繁体   English   中英

JSF ManagedBean初始化失败

[英]JSF ManagedBean initialisation fails

我是JSF的新手,从昨天开始我就面临着严重的问题。 通过以下方法调用以下方法“ initialiseLists”

<f:event listener="#{Bean.initialiseLists}" type="postAddToView" />

在我看来

public void initialiseLists() {
  this.setAuthorisationsToDelete(new ArrayList<>());

  this.setRoles(new RoleManager().readAll());
  this.setReportIntervals(new ReportIntervalManager().readAll());

  AddUserCustomerBundle bundle = new AddUserCustomerBundle(new CustomerManager().readActive());

  System.out.println("");

  this.setAddKundeAuth(bundle);
}

如果我在Eclipse的Tomcat7上使用此代码部署Bean,一切正常。 但是您可能会问:“为什么他把System.out.println(“”)放在那里?

真正奇怪的是,如果我注释了sysout,则会收到一条错误消息。

/WEB-INF/common/createOrEdit.xhtml @14,72 listener="#{Bean.initialiseLists}": Target Unreachable, identifier 'Bean' resolved to null

取消注释sysout并重新启动tomcat之后,它再次可以正常工作。 谁能告诉我,从哪里可以得到有关错误原因的更多信息? 在我看来,我的Bean无法初始化。 Java Stacktrace不会产生任何有趣的结果...

Feb 27, 2015 10:05:11 AM com.sun.faces.context.ExceptionHandlerImpl log
1100: JSF1073: javax.el.PropertyNotFoundException erfasst während Verarbeitung von RENDER_RESPONSE 6 : UIComponent-ClientId=, Message=/WEB-INF/common/createOrEdit.xhtml @14,72 listener="#{Bean.initialiseLists}": Target Unreachable, identifier 'Bean' resolved to null
Feb 27, 2015 10:05:11 AM com.sun.faces.context.ExceptionHandlerImpl log
1100: /WEB-INF/common/createOrEdit.xhtml @14,72 listener="#{Bean.initialiseLists}": Target Unreachable, identifier 'Bean' resolved to null
javax.el.PropertyNotFoundException: /WEB-INF/common/createOrEdit.xhtml @14,72 listener="#{Bean.initialiseLists}": Target Unreachable, identifier 'Bean' resolved to null
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(Unknown Source)    
    at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(Unknown Source)
    at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(Unknown Source)
    at javax.faces.event.SystemEvent.processListener(Unknown Source)
    at javax.faces.event.ComponentSystemEvent.processListener(Unknown Source)
    at com.sun.faces.application.ApplicationImpl.processListeners(Unknown Source)
    at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(Unknown Source)
    at com.sun.faces.application.ApplicationImpl.publishEvent(Unknown Source)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.buildView(Unknown Source)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(Unknown Source)
    at com.sun.faces.lifecycle.Phase.doPhase(Unknown Source)
    at com.sun.faces.lifecycle.LifecycleImpl.render(Unknown Source)
    at javax.faces.webapp.FacesServlet.service(Unknown Source)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at de.frupek.fluidman.web.filters.LoginFilter.doFilter(LoginFilter.java:43)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745) 

Edit1:如果我正在向我的bean添加另一个属性,例如,现在出现错误

private int test;

可能是环境问题(tomcat7,eclipse,ubuntu等)吗?

Edit2:在我的Bean中使用java.util.function.Function似乎是一个问题。 如果我评论所有出现的情况,则一切正常,如果我添加类似的内容

Function<User, List<Customer>> f = User::getCustomers;

上面的异常被抛出。 JSF使用中是否有Java 8限制?

我假设您的类称为Bean并且您尚未为其提供别名,这将迫使JSF向别名bean注册它。

<f:event> ,使用bean更改Bean

<f:event listener="#{bean.initialiseLists}" type="postAddToView" />

另外,您可以这样命名您的bean Bean

@ManagedBean(name = "Bean")
public class Bean { ... }

并将当前表达式保留在<f:event>的listener属性中。

几个小时后,我能够“解决”我的问题,但“解决方案”有效,但不是很令人满意:我不得不将引用的方法initializeLists和另一个使用类成员包的方法复制到源文件的末尾。 现在,我的bean已正确初始化(带有我所有的t:param东西),并且运行良好。

我不知道是哪个组件导致了这种特殊行为,我希望我不再面对它。 我的猜测是,任何“ JSF”类在“扫描”我的bean时都会失败,但这可能是完全错误的...

暂无
暂无

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

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