开发者

JSF Action is not called

Once again I have a problem which I can't find the solution to.

A managed bean

@Named(value="changeInfoBean")
@RequestScoped
public class ChangeInfoBean {

    private String email;
    private String firstName;
    private String lastName;

    /** Creates a new instance of ChangeInfoBean */
    public ChangeInfoBean() {
            FacesContext context = FacesContext.getCurrentInstance();
            // Gets the user which is currently logged in
            LoginBean bean = (LoginBean) context.getExternalContext().getSessionMap().get("loginBean");
            BasicUser user = bean.getUser();
            this.email = user.getEmail();
            this.firstName = user.getFirstName();
            this.lastName = user.getLastName();

    }

    public String changeName() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            Transaction tx = session.beginTransaction();
            BasicUser updateUser = (BasicUser) session.load(BasicUser.class, this.email);
            updateUser.setFirstName(firstName);
            updateUser.setLastName(lastName);
            tx.commit();
        开发者_StackOverflow中文版}
        catch(Exception e) {
            e.printStackTrace();
        }
        finally {
            session.close();
            return "succes";
        }
    }

The return "succes" is just to return something. Part of a page that uses the bean

<h:panelGroup rendered="#{param.change == 'name'}">
            <h:form id="changeNameForm">
                <h:messages/>
                <h:panelGrid id="panel1" columns="2">
                    First Name:
                    <h:inputText id="firstName" value="#{changeInfoBean.firstName}"/>
                    Last Name:
                    <h:inputText id="lastName" value="#{changeInfoBean.lastName}"/>
                    <f:facet name="footer">
                        <h:panelGroup style="display:block; text-align:center">
                            <h:commandButton value="Submit Name" action="#{changeInfoBean.changeName}"/>
                        </h:panelGroup>
                    </f:facet>
                </h:panelGrid>
            </h:form>
        </h:panelGroup>

I have checked that all it runs trough every lifecycle phase, tried to make the bean session scoped and tried to set immediate="true". I have tried to delete the inputText fields and only have the commandButton left. In every case the method changeName() is not called. What can be done?


Apparently the #{param.change} didn't equal to "name" during the form submit request which caused the h:panelGroup not to render which in turn caused the button's action not to be invoked.

Add the following to your form:

<input type="hidden" name="change" value="#{param.change}" />

This will retain the #{param.change} for the subsequent request. Placing the bean in session scope would only have worked when it was been a #{sessionBean.change}.

See also:

  • When an UICommand component won't be invoked
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜