0 Replies Latest reply on Feb 25, 2013 3:36 AM by Philip H

    dynamic includes with a4j- the second click problem

    Philip H Newbie

      Hi community!

       

      I've been reading posts about this issue for a while now and have not come to a final conclusion which im requesting for, cause it is a serious issue in our project.
      To sum it up clearly: There is one index.xhtml and its purpose is to handle navigation- with the help of dynamic includes and a current value, maintained by the bean. I've enclosed my example with just two navigation items, for demonstrating purposes, the testing had been done with lemmaSearch.xhtml:

       

      <?xml version='1.0' encoding='UTF-8' ?>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <html xmlns="http://www.w3.org/1999/xhtml"

            xmlns:h="http://java.sun.com/jsf/html"

            xmlns:ui="http://java.sun.com/jsf/facelets"

            xmlns:rich="http://richfaces.org/rich"

            xmlns:f="http://java.sun.com/jsf/core"

            xmlns:a4j="http://richfaces.org/a4j">

          <h:head>

              <link rel="stylesheet" media="all" type="text/css" href="style.css"/>

          </h:head>

          <h:body>

             

              <div id="page" layout="block">

                  <h:panelGroup id="header" layout="block">

                      <ui:insert name="header" >

                          <ui:include src="header.xhtml" />

                      </ui:insert>

                  </h:panelGroup>

       

                  <div id="content">

                      <h:form>

                      <h:panelGroup id="leftcol" layout="block" ajaxRendered="true" mode="ajax">

                         

                              <rich:panelMenu collapseEvent="none">

                                  <rich:panelMenuItem label="Home" expanded="true" action="#{IndexBackingBean.updateCurrent}">

                                      <f:param  name="current" value="home.xhtml"/>

                                  </rich:panelMenuItem>

                                 

                                  <rich:panelMenuGroup label="Suche" expanded="true">

                                      <rich:panelMenuItem label="Lemma Suche" action="#{IndexBackingBean.updateCurrent}">

                                          <f:param name="current" value="../web_searchMasks/lemmaSearch.xhtml"/>

                                      </rich:panelMenuItem>

                                  </rich:panelMenuGroup>

                                 

       

                              </rich:panelMenu>

                         

                      </h:panelGroup>

       

                     

                      <a4j:outputPanel id="rightcol" ajaxRendered="true" >

                              <ui:include src="#{IndexBackingBean.current}"/>

                          </a4j:outputPanel>

                      </h:form>

                  </div>

              </div>

             

          </h:body>

       

      </html>

       

      The IndexBackingBean looks like the following:

       

      package backing.index;

      import java.awt.Toolkit;

      import java.io.Serializable;

      import javax.faces.bean.ManagedBean;

      import javax.faces.bean.SessionScoped;

      import javax.faces.context.FacesContext;

      import javax.faces.event.ActionEvent;

      import org.richfaces.component.UIPanelMenuItem;

       

      @ManagedBean(name = "IndexBackingBean")

      @SessionScoped

      public class IndexBackingBean implements Serializable

      {

       

          private String current = "home.xhtml";

          private boolean singleMode;

          private transient Toolkit tk = Toolkit.getDefaultToolkit();

          private double screenHeight = tk.getScreenSize().getHeight();

          private double screenWidth = tk.getScreenSize().getWidth();

       

          public boolean isSingleMode()

          {

              return singleMode;

          }

       

          public void setSingleMode(boolean singleMode)

          {

              this.singleMode = singleMode;

          }

       

          public String getCurrent()

          {

              return this.current;

          }

       

          public void setCurrent(String current)

          {

              this.current = current;

          }

       

          public String updateCurrent()

          {

              FacesContext context = FacesContext.getCurrentInstance();

              setCurrent(context.getExternalContext().getRequestParameterMap().get("current"));

              return null;

          }

       

          public void updateCurrent(ActionEvent event)

          {

              String tmp = ((UIPanelMenuItem) event.getComponent()).getLabel().toString();

              if (tmp.equals("Home"))

              {

                  setCurrent("home.xhtml");

              }

          }

       

          public boolean validate(String str)

          {

              return current.equals(str);

          }

       

          public int getScreenHeight()

          {

              return (int) screenHeight;

          }

       

          public int getScreenWidth()

          {

              return (int) screenWidth;

          }

      }

       

      and the lemmaSearch.xhtml

       

      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                      xmlns:h="http://java.sun.com/jsf/html"
                      xmlns:rich="http://richfaces.org/rich"
                      xmlns:a4j="http://richfaces.org/a4j"
                      xmlns:f="http://java.sun.com/jsf/core"
                      xmlns:ui="http://java.sun.com/jsf/facelets"
                      xmlns:c="http://java.sun.com/jsp/jstl/core"
                      >
          <h:form id="aform">
          <rich:panel>

       

                  I want to find out something about the input blabla
                  <h:inputText value="#{LemmaSearch.input}"></h:inputText>
                  <a4j:commandButton value="go" action="#{LemmaSearch.findLemma()}" render="lemmapanel">
                  </a4j:commandButton>
             
              <br/>

       

              <rich:panel id="lemmapanel" style="border:none">
                 
                      <h:outputText style="color:red" value="Result: #{LemmaSearch.lemma}"></h:outputText>
                 
              </rich:panel>
             
          </rich:panel>
              </h:form>
      </ui:composition>

       

      My RF version is 4.2.2 and Mojarra 2.3.17

      The backing bean of lemmaSearch is just a simple databasequery and not necessary for demonstration, it does work perfectly fine and on the first click if runned seperately.
      Navigating through lemmaSearch and Home works at the first time, without any problems.

       

      THE issue here, that had been discussed in this forum multiple times, is that the go button reacts only at the second click of a session. Everything else works great. These demonstrations hold just a version of many diferent tries I did on form nesting. I read about it, but couldnt find out the correct way how to do it. Does index.xhtml need to cover everything under one form, or does it have to have seperate forms for the panelmenu and the outputpanel. What form structure does lemmaSearch.xhtml need? Is this problem still an unresolved bug in JSF and there is a common workaround ? I included it statically once, and it worked on the first click, but i need to have dynamic includes, to handle navigation. I hope someone can give a clear instruction on how to do this simply, because i've read about people resolivng the issue, although i didn't find a helpful explanation or was unable to adjust my program correctly.

       

      Thank you in advance, Philip