JSF action not called

Again I have a problem with which I cannot find a solution.

Driven 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();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
        finally {
            session.close();
            return "succes";
        }
    }

Returning "succes" is just returning something. Part of the page using 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 checked that all this is done at every stage of the life cycle, tried to make the bean session busy, and tried to set immediate = "true". I tried to remove the inputText fields and left only the CommandButton command. In any case, the changeName () method is not called. What can be done?

+3
source share
1 answer

Apparently, #{param.change}it was not equal "name"during the request for submitting the form, because of which h:panelGroupit was not displayed, which in turn did not cause the button to act.

:

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

#{param.change} . bean , #{sessionBean.change}.

. :

+6

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


All Articles