无法将类型为java.lang.String的#{ad.userid}转换为类javax.faces.component.UIComponent

时间:2010-07-14 12:57:54

标签: jsp jsf

我正在获取主页,但是当访问具有h:inputText的JSP页面时,我收到以下错误:

root cause
javax.servlet.ServletException: javax.servlet.jsp.JspException: org.apache.jasper.el.JspELException: /login.jsp(21,0) '#{ad.userid}' Cannot convert #{ad.userid} of type class java.lang.String to class javax.faces.component.UIComponent
 org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
 org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
 org.apache.jsp.login_jsp._jspService(login_jsp.java:83)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:542)
 com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:359)
 com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:150)
 com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:96)
 com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
 com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:135)
 javax.faces.webapp.FacesServlet.service(FacesServlet.java:309)

root cause

org.apache.jasper.el.JspELException: /login.jsp(21,0) '#{ad.userid}' Cannot convert #{ad.userid} of type class java.lang.String to class javax.faces.component.UIComponent
 org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:107)
 com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1878)
 com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:443)
 javax.faces.webapp.UIComponentELTag.createComponent(UIComponentELTag.java:218)
 javax.faces.webapp.UIComponentClassicTagBase.createChild(UIComponentClassicTagBase.java:483)
 javax.faces.webapp.UIComponentClassicTagBase.findComponent(UIComponentClassicTagBase.java:667)
 javax.faces.webapp.UIComponentClassicTagBase.doStartTag(UIComponentClassicTagBase.java:1139)
 com.sun.faces.taglib.html_basic.InputTextTag.doStartTag(InputTextTag.java:424)
 org.apache.jsp.login_jsp._jspx_meth_h_005finputText_005f0(login_jsp.java:253)
 org.apache.jsp.login_jsp._jspx_meth_h_005fform_005f0(login_jsp.java:168)
 org.apache.jsp.login_jsp._jspx_meth_f_005fview_005f0(login_jsp.java:113)
 org.apache.jsp.login_jsp._jspService(login_jsp.java:76)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:542)
 com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:359)
 com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:150)
 com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:96)
 com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
 com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:135)
 javax.faces.webapp.FacesServlet.service(FacesServlet.java:309)

1 个答案:

答案 0 :(得分:4)

login.jsp的第21行,替换

<h:inputText binding="#{ad.userid}" />

通过

<h:inputText value="#{ad.userid}" />

要了解binding属性的原因和内容,head here