Stuck in ManagedBeanPreProcessingException: handling unexpected bean errors

Can someone help us with this?

We are trying to make a register user function in our JSF application. We want the user to log in immediately after registration. After the user came across me, I’m a new commandLink client, we have this exception and we don’t know how to handle it:

com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error processing managed bean registerBean at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:394) at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:260) at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175) at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72) at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:99) at com.sun.el.parser.AstValue.getValue(AstValue.java:158) at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219) at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178) at javax.faces.component.UIOutput.getValue(UIOutput.java:168) at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:338) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620) at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613) 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.StandardWrapper.service(StandardWrapper.java:1523) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:662) Caused by: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error processing managed property loginBean at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:117) at com.sun.faces.mgbean.BeanManager.preProcessBean(BeanManager.java:349) ... 50 more Caused by: java.lang.NullPointerException at com.sun.faces.mgbean.ManagedBeanBuilder.bakeBeanProperty(ManagedBeanBuilder.java:350) at com.sun.faces.mgbean.ManagedBeanBuilder.bake(ManagedBeanBuilder.java:107) ... 51 more 

Here is a list of LoginBean and RegisterBean:

 @ManagedBean @SessionScoped public class LoginBean { private String username, password; private User user; private UserManager um = UserManager.getInstance(); /** * */ public LoginBean() { super(); } /** * @return the username */ public String getUsername() { return username; } /** * @return the password */ public String getPassword() { return password; } public void setUser(User user) { this.user = user; username = user.getUsername(); password = user.getPassword(); } /** * @return the user */ public User getUser() { return user; } /** * @param username * the username to set */ public void setUsername(String username) { this.username = username; } /** * @param password * the password to set */ public void setPassword(String password) { this.password = password; } public String nextPage() { try { user = um.getUser(username, password); } catch (NoResultException e) { return "failure" + REDIRECT; } if (user instanceof Client) return "home_client" + REDIRECT; return "home_admin" + REDIRECT; } } @ManagedBean @RequestScoped public class RegisterBean { private String username, password, repassword, firstname, lastname, email, address, city, county, postcode, country, phone; @ManagedProperty(value = "#{loginBean}") private LoginBean loginBean; // private UserManager um = UserManager.getInstance(); public RegisterBean() { } /** * @return the username */ public String getUsername() { return username; } /** * @return the password */ public String getPassword() { return password; } /** * @return the repassword */ public String getRepassword() { return repassword; } /** * @return the firstname */ public String getFirstname() { return firstname; } /** * @return the lastname */ public String getLastname() { return lastname; } /** * @return the email */ public String getEmail() { return email; } /** * @return the address */ public String getAddress() { return address; } /** * @return the city */ public String getCity() { return city; } /** * @return the county */ public String getCounty() { return county; } /** * @return the postcode */ public String getPostcode() { return postcode; } /** * @return the country */ public String getCountry() { return country; } /** * @return the phone */ public String getPhone() { return phone; } /** * @return the user */ public LoginBean getLoginBean() { return loginBean; } /** * @param username * the username to set */ public void setUsername(String username) { this.username = username; } /** * @param password * the password to set */ public void setPassword(String password) { this.password = password; } /** * @param repassword * the repassword to set */ public void setRepassword(String repassword) { this.repassword = repassword; } /** * @param firstname * the firstname to set */ public void setFirstname(String firstname) { this.firstname = firstname; } /** * @param lastname * the lastname to set */ public void setLastname(String lastname) { this.lastname = lastname; } /** * @param email * the email to set */ public void setEmail(String email) { this.email = email; } /** * @param address * the address to set */ public void setAddress(String address) { this.address = address; } /** * @param city * the city to set */ public void setCity(String city) { this.city = city; } /** * @param county * the county to set */ public void setCounty(String county) { this.county = county; } /** * @param postcode * the postcode to set */ public void setPostcode(String postcode) { this.postcode = postcode; } /** * @param country * the country to set */ public void setCountry(String country) { this.country = country; } /** * @param phone * the phone to set */ public void setPhone(String phone) { this.phone = phone; } public String register() { this.loginBean.setUser(new Client(username, password, new ContactDetails(firstname, lastname, email, address, city, county, postcode, country, phone))); return "home_client" + REDIRECT; } } 

Here is the login form from login.xhtml:

 <h:form> Username: <h:inputText value="#{loginBean.username}" /> <br /> Password: <h:inputSecret value="#{loginBean.password}" /> <br /> <h:commandButton value="Login" action="#{loginBean.nextPage}" /> <h:commandLink value="I'm a new client" action="register"></h:commandLink> </h:form> 

And the register form from register.xhtml:

 <h:form> <h:outputText value="Inregistrare client nou"/> <br/> Username: <h:inputText value="#{registerBean.username}"> <f:validator validatorId="registerUsernameValidator"></f:validator> </h:inputText> <br/> Parola: <h:inputSecret value="#{registerBean.password}"></h:inputSecret> <br/> Re-Parola: <h:inputSecret value="#{registerBean.repassword}"></h:inputSecret> <br/> <br/> Prenume: <h:inputText value="#{registerBean.firstname}"></h:inputText> <br/> Nume: <h:inputText value="#{registerBean.lastname}"></h:inputText> <br/> E-mail: <h:inputText value="#{registerBean.email}"></h:inputText> <br/> Adresa: <h:inputText value="#{registerBean.address}"></h:inputText> <br/> Oras: <h:inputText value="#{registerBean.city}"></h:inputText> <br/> Judet: <h:inputText value="#{registerBean.county}"></h:inputText> <br/> Cod postal: <h:inputText value="#{registerBean.postcode}"></h:inputText> <br/> Tara: <h:inputText value="#{registerBean.country}"></h:inputText> <br/> Telefon: <h:inputText value="#{registerBean.phone}"></h:inputText> <br/> <br/> <h:commandButton value="Inregistreaza-ma" action="#{registerBean.register}"></h:commandButton> 

Our custom RegisterUsernameValidator:

 public class RegisterUsernameValidator implements Validator { UserManager um = UserManager.getInstance(); @Override public void validate(FacesContext context, UIComponent arg1, Object value) throws ValidatorException { String username = (String) value; if (!um.isUsernameAvailable(username)) { FacesMessage facesMessage = new FacesMessage("Username indisponibil"); FacesContext.getCurrentInstance().addMessage("Username indisponibil", facesMessage); } } } 

And the verification part from faces-config.xml:

 <validator> <validator-id>registerUsernameValidator</validator-id> <validator-class>validation.RegisterUsernameValidator</validator-class> </validator> 
+4
source share
1 answer

com.sun.faces.mgbean.ManagedBeanPreProcessingException: unforeseen error management bean registerBean

This means that the processing of bean properties on the RegisterBean immediately after its construction failed due to a developer error (incorrect configuration, unavailable properties, invalid property type, etc.). The root cause of the problem should be visible as the root cause in the exception stack. Since you didn’t split the whole stack, it’s hard to say what exactly is going on.

Anyway, just read stacktrace. The answer is there.


Update : according to the full stacktrace table:

Called: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error handling managed property loginBean
Reason: java.lang.NullPointerException

The managed property for loginBean cannot be set to RegisterBean . Check if there is a setter in the RegisterBean class and it has the correct signature.

 public void setLoginBean(LoginBean loginBean) { this.loginBean = loginBean; } 

Unrelated to a specific problem, this NullPointerException should really be a PropertyNotWritableException . What do you use / version of JSF?

+12
source

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


All Articles