Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stuck in ManagedBeanPreProcessingException : Unexpected error processing managed bean

Tags:

java

jsf

jsf-2

Can anyone help us with this?

We're trying to make the register user feature in our JSF application. We want the user log in right after he registers. After the user hits the I'm a new client commandLink, 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 are the LoginBean and the 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 validation part from faces-config.xml:

<validator>
    <validator-id>registerUsernameValidator</validator-id>
    <validator-class>validation.RegisterUsernameValidator</validator-class>
</validator>
like image 259
DaJackal Avatar asked Feb 12 '11 11:02

DaJackal


1 Answers

com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error processing managed bean registerBean

This means that processing the bean properties on RegisterBean directly after its construction has failed miserably due to a developer error (wrong configuration, inaccessible properties, invalid property type, etc). The root cause of the problem should be visible as root cause part in the stacktrace of the exception. Since you didn't share the entire stacktrace, it's hard to tell what exactly is failing.

Anyway, just read the stacktrace. The answer is in there.


Update: as per the full stacktrace:

Caused by: com.sun.faces.mgbean.ManagedBeanPreProcessingException: Unexpected error processing managed property loginBean
Caused by: java.lang.NullPointerException

The managed property for loginBean could not be set in registerBean. Verify if there is a setter in RegisterBean class and it has the right signature.

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

Unrelated to the concrete problem, this NullPointerException should really have been a PropertyNotWritableException. What JSF impl/version are you using?

like image 163
BalusC Avatar answered Nov 05 '22 04:11

BalusC