卡在 ManagedBeanPreProcessingException 中:处理托管 bean 时出现意外错误

发布于 2024-10-17 11:34:26 字数 13407 浏览 1 评论 0原文

有人可以帮助我们吗?

我们正在尝试在 JSF 应用程序中添加注册用户功能。我们希望用户注册后立即登录。用户点击“我是新客户端”命令链接后,我们遇到了这个异常,并且我们不知道如何处理它:

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

这是 LoginBean 和 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;
    }
}

这是来自 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>

和注册器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>

我们的自定义 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);
        }
    }
}

以及 faces-config.xml 中的验证部分:

<validator>
    <validator-id>registerUsernameValidator</validator-id>
    <validator-class>validation.RegisterUsernameValidator</validator-class>
</validator>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-10-24 11:34:26

com.sun.faces.mgbean.ManagedBeanPreProcessingException:处理托管 bean registerBean 时出现意外错误

这意味着在构造后直接处理 RegisterBean 上的 bean 属性由于开发人员错误(错误的配置、无法访问的属性)而惨败、无效的属性类型等)。问题的根本原因应该作为异常堆栈跟踪中的根本原因部分可见。由于您没有共享整个堆栈跟踪,因此很难判断到底是什么失败了。

无论如何,只需阅读堆栈跟踪即可。答案就在那里。


更新:根据完整的堆栈跟踪:

由以下原因引起:com.sun.faces.mgbean.ManagedBeanPreProcessingException:处理托管属性loginBean时出现意外错误
引起原因:java.lang.NullPointerException

无法在 registerBean 中设置 loginBean 的托管属性。验证 RegisterBean 类中是否有 setter 并且它具有正确的签名。

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

与具体问题无关,这个 NullPointerException 实际上应该是 PropertyNotWritableException。您使用什么 JSF impl/版本?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文