Exception - unable to set userLogin property for managed bean credentials

For authentication purposes, I am introducing bean-binding routine support into another bean session scope that will store the logged-in user. Or at least it should ... Next, a bit of code:

Request bean scope - managed property

@ManagedProperty(value="userLogin") 

Error Failed to set userLogin property for managed bean credentials

Stack trace

 com.sun.faces.mgbean.ManagedBeanCreationException: Unable to set property userLogin for managed bean credentials at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:615) at com.sun.faces.mgbean.ManagedBeanBuilder.buildBean(ManagedBeanBuilder.java:133) at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:104) at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244) at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116) at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72) at org.apache.el.parser.AstValue.getValue(AstValue.java:161) at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185) at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) at javax.faces.component.UIOutput.getValue(UIOutput.java:169) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185) at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:437) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) 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:594) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: javax.el.ELException: Cannot convert userLogin of type class java.lang.String to class model.businessLogic.UserLogin at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:420) at org.apache.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:47) at com.sun.faces.el.ELUtils.coerce(ELUtils.java:536) at com.sun.faces.mgbean.BeanBuilder$Expression.evaluate(BeanBuilder.java:592) at com.sun.faces.mgbean.ManagedBeanBuilder$BakedBeanProperty.set(ManagedBeanBuilder.java:606) ... 51 more 
+6
source share
1 answer

Read the root cause of the exception to understand the reason (and, essentially, this is also the solution):

Raised: javax.el.ELException: cannot convert userLogin of type java.lang.String to class model.businessLogic.UserLogin

So you referred to the String instance as a managed bean instead of the UserLogin instance.

And indeed, your managed property value is not valid:

 @ManagedProperty(value="userLogin") 

It refers to plain vanilla String . Instead, you need to reference a managed bean:

 @ManagedProperty(value="#{userLogin}") 

Or, in short, since the value attribute is the default attribute of the annotation:

 @ManagedProperty("#{userLogin}") 
+13
source

Source: https://habr.com/ru/post/945940/


All Articles