开发者

h:commandLink action doesn't fire in every click using JSF 2

开发者 https://www.devze.com 2023-03-19 05:25 出处:网络
I have a masterLasyout.xhtml: <h:form id=\"abc\"> <h1> <ui:insert id=\"abc1\" name=\"title\"></ui:insert>

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>
开发者_Python百科</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.


Problem is fixed. In web.xml I defined:

 <context-param>
     <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
     <param-value>false</param-value>
 </context-param>

I wonder whether there is a possibility to add dynamically (programatically or using xml files) in JSF 2 workflow page controls that has to be added dyanmically. In the case of the question above, one of the controls was not defined in the control tree that is created during the first request of the page. So, in another note: is there an option to add controls dynamically to the controls tree without modifying web.xml, for optimization?

0

精彩评论

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