I'm trying to get a firm grasp on ajax
but I'm afraid I'm at a lost. The code below renders the Wait
button after clicking on the Join
button. Join
button's actionListener
also gets called the first time. Then, after clicking on Wait
, the Join
button gets rendered but Wait
button's actionListener
is not called. Finally, when you click on Join
nothing happens. This is a slight variation (I'm hoping) of this question (in case any of you saw something similar)
commandButton inactive after ajax rendering
If this is a duplicate question I'm sorry. If BalusC answered this already from the question I posted, I'm frankly not understanding the cause. I'm at the point where nothing makes sense anymore. I'm sure it's silly but can someone please explain what is happening ?
<h:form>
<p:commandButton id="Join" actionListener = "#{connexion.joinWaitingList}"
update="@form" rendered="#{connexion.renderJoinButton}"
value="Join"/>
<p:commandButton id="leave" actionListener = "#{connexion.leaveWaitingList}"
update="@form" rendered="#{connexion.renderWaitButton}"
value="Wait"/>
</h:form>
The java code
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class Connexion implements java.io.Serializable {
private boolean renderJoinButton;
private boolean renderWaitButton;
public Connexion() {
renderJoinButton = true;
renderWaitButton = false;
}
public boolean isRenderJoinButton() {
return renderJoinButton;
}
public void setRenderJoinButton(boolean renderJoinButton) {
this.renderJoinButton = renderJoinButton;
}
public boolean isRenderWaitButton() {
return renderWaitButton;
}
public void setRenderWaitButton(boolean renderWaitButton) {
this.renderWaitButton = renderWaitButton;
}
public void joinWaitingList() {
System.out.println("Waiting list joined");
renderJoinButton = false;
renderWaitButton = true;
}
public void leaveWaitingList() {
System.out.println("Waiting list abandoned");
renderJoinButton = true;
renderWaitButton = false;
}
}
UPDATE
I am using JSF 2.2 with PrimeFaces 3.5
UPDATE #2
This seems to work with JSF 2.1 and 2.0.10. It doesn't work with JSF 2.2. I have posted this issue on Primefaces forum. I'll update this post once I get a reply from them.
UPDATE #3
Thanks to jhond, I was made aware of a bug. Also, one of the primefaces community members got back to me and said "only latest snapshot is kind of compatible".