JSF 2.0 で @ManagedProperty を使用していますが、以下の問題が発生しています。
エンティティ クラス
@Entity(name="UserDetail")
@Table(name="in_user")
@SessionScoped
public class UserDetail implements Serializable{
private static final long serialVersionUID = 1L;
@Id
private Integer no;
private String userName;
private String password;
public Integer getNo() {
return no;
}
public void setNo(Integer no) {
this.no = no;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
コントローラ
@ManagedBean(name="authenticator")
@RequestScoped
public class Authenticator implements Serializable {
private static final long serialVersionUID = 1L;
@ManagedProperty(value = "#{userDetail}")
private UserDetail userDetail;
// Some Code......
}
.XHTML
<p:panel header="Application Login" toggleable="true" toggleOrientation="horizontal" style="width:400px">
<p:panelGrid columns="2" columnClasses="0">
<h:outputLabel value="User Name " />
<h:inputText value="#{authenticator.userDetail.userName}" />
<h:outputLabel value="Password " />
<h:inputSecret value="#{authenticator.userDetail.password}" />
<p:commandButton value="Login" action="#{authenticator.authenticate}"></p:commandButton>
<p:commandButton value="Log Out" action="#{authenticator.logOut}" />
</p:panelGrid>
</p:panel>
アプリケーションを実行すると、以下の問題に直面しています..
Mar 29, 2013 7:26:56 PM com.sun.faces.lifecycle.ProcessValidationsPhase execute
WARNING: /login.xhtml @21,66 value="#{authenticator.userDetail.userName}": Target Unreachable, 'userDetail' returned null
javax.el.PropertyNotFoundException: /login.xhtml @21,66 value="#{authenticator.userDetail.userName}": Target Unreachable, 'userDetail' returned null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030)
at javax.faces.component.UIInput.validate(UIInput.java:960)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233)
at javax.faces.component.UIInput.processValidators(UIInput.java:698)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at org.primefaces.component.panel.Panel.processValidators(Panel.java:297)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
どこに問題があるのかわからない。
私が交換する場合。
@ManagedProperty(value = "#{userDetail}")
private UserDetail userDetail;
と
private UserDetail userDetail = new UserDetail();
その後、正常に動作します。しかし、私は@ManagedPropertyを使いたいです。私を助けてください。