简体   繁体   English

JSF隐藏异常?

[英]JSF hiding exceptions?

I have a managed bean for a JSF page which is doing JPA calls in the constructor to populate fields in the bean. 我有一个JSF页面的托管bean,它在构造函数中执行JPA调用以填充bean中的字段。 I'm having a bit of trouble with another call to persist an entity (to populate data for testing). 我在另一个持久化实体的调用(填充数据以进行测试)时遇到了一些麻烦。 I'm expecting it to throw some sort of exception since it's not working, but I'm not getting anything. 我期待它会抛出某种异常,因为它不起作用,但我没有得到任何东西。 Just of the heck of it I tried the following: 仅仅是因为它,我尝试了以下内容:

Query newQuery = em.createQuery("Bad Syntax");
List newList = newQuery.getResultList();

I'd expect an IllegalArgumentException here since the query string is completely invalid, but the page still loads and I don't see any exceptions anywhere. 我希望这里有一个IllegalArgumentException ,因为查询字符串完全无效,但页面仍然加载,我在任何地方都看不到任何异常。

Am I right in expecting this exception? 我是否正确期待这个例外? If so, why am I not seeing it? 如果是这样,为什么我没有看到它?

It doesn't suppress exceptions by default. 默认情况下,它不会禁止异常。 As a quick test I tried the following: 作为快速测试,我尝试了以下方法:

package com.example;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class Bean {

    public Bean() {
        throw new IllegalArgumentException("No!");
    }

}

with

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>test</title>
    </h:head>
    <h:body>
        #{bean}
    </h:body>
</html>

and I got a nice default error page with the following trace in the webbrowser: 我有一个很好的默认错误页面,在webbrowser中有以下跟踪:

javax.el.ELException: /test.xhtml: Cant instantiate class: com.example.Bean.
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:83)
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:75)
    at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:176)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Thread.java:619)
Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: com.example.Bean.
    at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:193)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:405)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:267)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
    at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:217)
    at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:141)
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:78)
    ... 25 more
Caused by: java.lang.IllegalArgumentException: No!
    at com.example.Bean.<init>(Bean.java:9)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188)
    ... 36 more
1-jun-2010 13:51:06 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet Faces Servlet threw exception
java.lang.IllegalArgumentException: No!
    at com.example.Bean.<init>(Bean.java:9)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:355)
    at java.lang.Class.newInstance(Class.java:308)
    at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:405)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:267)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
    at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
    at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:217)
    at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:141)
    at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:78)
    at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:75)
    at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:176)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
    at java.lang.Thread.run(Thread.java:619)

So your problem probably lies somewhere else. 所以你的问题可能就在其他地方。 Have you run a debugger? 你运行调试器了吗?

Well, it appears there was some sort of issue with NetBeans not redeploying everything properly. 好吧,似乎存在某种问题,NetBeans没有正确地重新部署所有内容。 I had been running clean builds while I was originally troubleshooting, but after letting things sit for a couple of days and going back to it, I'm now seeing what I'd expect to see. 在我最初进行故障排除时,我一直在运行干净的构建,但是在让事情停留了几天并回到它之后,我现在看到了我期望看到的东西。

Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: Exception Description: Syntax error parsing the query [Bad Syntax], line 1, column 0: unexpected token [Bad]. 引发者:java.lang.IllegalArgumentException:在EntityManager中创建查询时发生异常:异常描述:解析查询的语法错误[错误语法],第1行,第0列:意外令牌[错误]。

I'm not sure what lesson I've really learned from this, but it's definitely removed some of my trust NetBeans. 我不确定我从中学到了什么教训,但它确实删除了我对NetBeans的一些信任。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM