I have a masterLasyout.xhtml:
<h:form id="abc">
<h1>
<ui:insert id="abc1" name="title"></ui:insert>
</h1>
<p>
<ui:insert id="abc2" name="body"></ui:insert>
</p>
</h:form>
I have 2 snippets files (they are inside ui:composition
):
<p:inputText id="it1" value="#{exampleBean.name}" immediate="true" ></p:inputText>
<h:commandLink id="cl1" immediate="true" value="Text1" action="#{exampleBean.ModifyLink2}" actionListener="exampleBean.Modify">
<p:ajax update=":abc:main"></p:ajax>
</h:commandLink>
second file:
<p:inputText id="it2" value="#{exampleBean.name}" immediate="true"></p:inputText>
<h:commandLink id="cl2" immediate="true" value="Text2" action="#{exampleBean.ModifyLink}" actionListener="exampleBean.Modify" >
<f:param value="/snippets/snippet1.xhtml" id="link"></f:param>
<p:ajax update=":abc:main"></p:ajax>
</h:commandLink>
I have the managed bean:
Now, I wish to switch between the snippets, and between fire an action in the following managed bean:
@ManagedBean (name="exampleBean")
@RequestScoped
public class ExampleBean {
/** Creates a new instance of ExampleBean */
public ExampleBean() {
m_User = new User();
SnippetFileName = "/snippets/snippet2.xhtml";
}
public void Modify(ActionEvent a){
System.out.println("Modify");
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
String t = externalContext.getRequestParameterMap().get("link");
System.out.println("SnippetFileName in ModifyLink is " + t);
}
public String ModifyLink()
{
System.out.println("ModifyLink");
SnippetFileName = "/snippets/snippet1.xhtml";
return "page";
}
public String ModifyLink2()
{
System.out.println("ModifyLink2");
SnippetFileName = "/snippets/snippet2.xhtml";
return "page";
}
private String SnippetFileName;
public String getSnippetFileName()
{
return SnippetFileName;
}
public void setSnippetFileName(String i_filename)
{
SnippetFileName = i_filename;
}
private User m_User;
public String getName(){
System.out.println("getName");
if (m_User==null)
{
return null;
}
return m_User.getName();
}
public void setName(String i_Name){
System.out.println("setName");
String name = i_Name.trim();
if (m_User!=null)
{
m_User.setName(name);
}
}
}
What that is happening is that in clicks number 1,3,5,7... the ModifyLink
method fires, and in clicks number 2,4,6,8... `ModifyLink2' doesn't. I can't seem to understand why this behavoiur happens.
I read few articles, including commandButton/commandLink/ajax action/listener method not invoked or input value not updated that states 7 issues that none of them fits in the spoken case and http://vierwaende.org/articles/posts/jsf-2-evaluation-test.html which brings about a very good overview on JSF 2 lifecycles.
I have also tried to remove Ajax, and it still does the same.
Thanks in advance.