4 Replies Latest reply on Jul 5, 2013 12:21 PM by bleathem

    ajax request to change and display a second table on the same page

    jobame

      Hello,

       

      on a page a table is displayed with some results. In that table I would like to include a link. When the user clicks that link that table row would be passed onto a method in the backing bean which does some search and return to the same jsf page. Another tables would then be displayed on the same page below the first table with the results of the second search.

       

      Example

       

      Table 1

                result a search 1

                result b search 1

                result c search 1

       

      Now when clicking on the link "result a search 1" that table row would be passed onto a method in the backing bean which executes a search and another table 2 would display the results of that second search.

       

       

      Table 1

                result a search 1

                result b search 1

                result c search 1

       

      Table 2

           details for result a search 1

       

      I tried in the first table

       

      <h:form>
                <rich:dataTable value="#{detDeb.subscriptionList}" var="subs">
                          <rich:column>
                                    <f:facet name="header">#{msgs.detailsId}</f:facet>
                                    <a4j:commandLink value="#{subs.id}" action="#{detDeb.getMoreDetailsOnSubscription(subs)}" render="out" />
                          </rich:column>
                          <rich:column>
                <rich:dataTable ...>
      <h:form>
      

       

      and for the second table

       

       <a4j:outputPanel id="out">
                <rich:dataTable value="#{detDeb.account}" var="account">
                          <rich:column>
                                    <f:facet name="header">#{msgs.detailsId}</f:facet>
                                    <h:outputText value="#{account.id}" />
                          </rich:column>
                          ...
                </rich:dataTable>
      </a4j:outputPanel>
      

       

      However, the ajax commandLink does not even trigger the method.

       

      Any ideas?

        • 1. Re: ajax request to change and display a second table on the same page
          bleathem

          Any output on the browser error console, or in the server log?  Are you able to get that commandLink/action to work outside of the datatable?

          • 2. Re: ajax request to change and display a second table on the same page
            jobame

            There is no error and in the server log nothing is printed - although I have a print statement in the method I would like to call (getMoreDetailsOnSubscription).

             

            Without the table I can get the example to work, sure (see e.g. http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=commandLink&skin=blueSky):

             

            <h:form>
                      <h:panelGrid columns="3">
                                <h:inputText value="#{detDeb.testSubscription}" />
                                <a4j:commandLink value="Submit" action="#{detDeb.getMoreDetailsOnSubscription()}" render="out" execute="@form" />
                      </h:panelGrid>
            </h:form>
            
            
            <a4j:outputPanel id="out">
                      <rich:dataTable value="#{detDeb.account}" var="account" rendered="#{detDeb.account != null}">
                                <rich:column>
                                          <f:facet name="header">#{msgs.detailsId}</f:facet>
                                          <h:outputText value="#{account.id}" />
                                </rich:column>
                                ...
                      </rich:dataTable>
            </a4j:outputPanel>
            

             

            However, in the above example I have to use an inputText field to get the value into the bean. So two fields are displayed but only one field - the link - should be displayed and I couldn't find a possibility to pass a value into the bean only via a4j:commandLink. Is there? If not, is there another solution?

            • 3. Re: ajax request to change and display a second table on the same page
              jobame

              Aargh. My bean was in request scope and tables refer to a bean which is kept in memory (e.g. session scoped). However, another question comes up:

               

              With CDI always javax.inject.Named hast to be used so the bean is available via EL and the injected beans are put into the appropriate CDI scope which would be e.g. javax.enterprise.context.RequestScoped, javax.enterprise.context.SessionScoped, javax.enterprise.context.ApplicationScoped or javax.enterprise.context.ConversationScoped.

               

              Now I would like to used the bean in ViewScope which is not available for CDI. I first tried to use javax.faces.bean.ViewScoped with javax.inject.Named but that wouldn't work since the backing bean cannot be put into that scope (since it doesn't exist for CDI) and hence to value cannot be placed from the JSF page into the backing bean (which is an assumption...).

               

              Next, I used javax.faces.bean.ViewScoped with javax.faces.bean.ManagedBean. That seems to be working. However, the dependency injection in the backing bean still works. How come? The backing bean is in jsf view scope. But in which scope are the injected beans being put by CDI into the backing bean? And if CDI works with those two annotations why does it not work when using javax.faces.bean.ViewScoped with javax.inject.Named?

               

              Even though it is working is it wrong to use javax.faces.bean.ManagedBean and javax.faces.bean.ViewScoped together with CDI?

               

              Add-on: I am using AS7.

              • 4. Re: ajax request to change and display a second table on the same page
                bleathem

                You do not want to mix CDI scopes with JSF scopes.  The Apache DeltaSpike (http://deltaspike.apache.org/) has a CDI implementation of the View Scope, then you can use CDI all-around.