0

In my login.xhtml file I have 1 form. This form also contains 2 <p:commandButton> which are mutual exclusively rendered.

The actions point to 2 different methods defined in my LoginController Java-class.

When the command button with the loginController.login action is clicked, the corresponding method in my LoginController is called as exptected.

But when the command button with the loginController.resetpassword action is clicked, the corresponding method in my LoginController is not called. The LoginController is just being reloaded and then nothing else (attempt #1).

First, I thought it's because I cannot have 2 command buttons in the same form, even though only 1 of them is rendered at any time, but if I swap the actions of the two action buttons, then the loginController.resetpassword is being called (attempt #2)! It does not matter if I swap the lines of code, so the lines of codes with the command buttons are read in another order (attempt #3).

For some readon, it seems as if I can only get the command button with id=loginButton to work?

I do not use navigation in my faces-config.xml. The form element is of type <h:form>

What am I doing wrong? Java 8, Primefaces 6.1

Attempt#1: default code

<p:commandButton id="resetpasswordButton" 
    value="#{msg['reset_password']}" 
    action="#{loginController.resetpassword}" 
    rendered="${not empty param.pw_reset}"
/>  <!-- #resetpasswordButton button does not work -->


<p:commandButton id="loginButton" 
    value="#{msg['login']}" 
    action="#{loginController.login}" 
    rendered="${empty param.pw_reset}" 
/>  <!-- #loginButton button works, calling login() -->

Attempt#2: actions switched

<p:commandButton id="resetpasswordButton" 
    value="#{msg['reset_password']}" 
    action="#{loginController.login}" 
    rendered="${not empty param.pw_reset}"
/>  <!-- #resetpasswordButton button does not work -->

<p:commandButton id="loginButton" 
    value="#{msg['login']}" 
    action="#{loginController.resetpassword}" 
    rendered="${empty param.pw_reset}" 
/>  <!-- #loginButton button works, calling resetpassword() -->

Attempt#3: order switched

<p:commandButton id="loginButton" 
    value="#{msg['login']}" 
    action="#{loginController.login}" 
    rendered="${empty param.pw_reset}" 
/>  <!-- #loginButton button works, calling login() -->

<p:commandButton id="resetpasswordButton" 
    value="#{msg['reset_password']}" 
    action="#{loginController.resetpassword}" 
    rendered="${not empty param.pw_reset}"
/>  <!-- #resetpasswordButton button does not work -->
Betlista
  • 10,327
  • 13
  • 69
  • 110
Janus Engstrøm
  • 103
  • 1
  • 12
  • 1
    Did yoy check if on submisaion, the 'param.reset` by chance became empty? The button reset button is then not working since it is on submission not rendered. Try switching the content of the rendered attributes and see if the result switches. And please always make a [mcve] – Kukeltje Dec 21 '18 at 22:02
  • 1
    Possible duplicate of [commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated](https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value) – Vsevolod Golovanov Dec 26 '18 at 16:03
  • I didn't get it. Based on what you render one or another button? I mean what is the logic, not the code (I can see that). – Betlista Dec 27 '18 at 08:02
  • @Betlista: the logic the code and in the page (`rendered="${not empty param.pw_reset}"` and `rendered="${empty param.pw_reset}" `) – Kukeltje Dec 27 '18 at 11:20
  • @VsevolodGolovanov is right.. That was what I was implying. #6 in the duplicate! – Kukeltje Dec 27 '18 at 11:21
  • I meant, he expects, that user comes to login page using `.../login.xhtml?pw_reset=true` or something? So the test case is to test the page with parameter and second test is without parameter? – Betlista Dec 27 '18 at 11:32

0 Answers0