6 Replies Latest reply on Feb 25, 2016 10:45 AM by Rudi Lausa

    ExtendedDataTable selection null in ui:include page

    Mario Andala Newbie

      Greetings Everyone.

      Im facing a problem with extendeddatatable and I will try to explain, I'm sorry if my english is not so good, maybe Im doing something wrong because Im pretty new in Richfaces and I spent some hours searching how to fix my problem but didnt found a solution.

       

      Im using Richfaces 4.3.7 (I tried with 4.5.0 but still have the problem) and Mojara 2.2.0 with Hibernate (MySql Db) and Tomcat 8.0

       

      I have a Homepage (.xhtml) with on the left commands and on right a ui:include inside a a4j outputpanel with src pointing to a backing bean proprierties, follow the portion of code of the ui:include.

        <a4j:outputPanel ajaxRendered="true" id="targetArea" layout="block">
             <ui:include src="#{homeBean.centralPage}" />
        </a4j:outputPanel>
      
      

       

      This is the page included:

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:a4j="http://richfaces.org/a4j"
        xmlns:rich="http://richfaces.org/rich">
      
      
        <html>
             <rich:extendedDataTable value="#{ordiniBean.documenti}"
                                     var="docum"
                                     id="table_docs"
                                     rows="60"
                                     selection="#{ordiniBean.selection}"
                                     selectionMode="single"
                                     style="height:#{sessionParameters.tableHeight1}px;width:692px">
                  <a4j:ajax event="selectionchange" listener="#{ordiniBean.selectionListener}" />
                  <rich:column width="90px">
                       <f:facet name="header">
                            <h:outputText value="Data" />
                       </f:facet>
                       <h:outputText value="#{docum.docData}">
                            <f:convertDateTime type="date" pattern="dd/MM/yyyy" />
                       </h:outputText>
                  </rich:column>
             </rich:extendedDataTable>
      
        </html>
      </ui:composition>
      
      

       

      The extendeddatatable has a selection and a a4j:ajax event="selectionchange" that point at a listener in the backingbean:

      private Collection<Object> selection;
      public Collection<Object> getSelection() {
        return selection;
      }
      
      
      public void setSelection(Collection<Object> selection) {
        this.selection = selection;
      }
      
      
      public void selectionListener(AjaxBehaviorEvent event) {
        AbstractExtendedDataTable dataTable = (AbstractExtendedDataTable)event.getComponent();
        Object originalKey = dataTable.getRowKey();
        selectionItems.clear();
        for (Object selectionKey : selection) {
        dataTable.setRowKey(selectionKey);
        if (dataTable.isRowAvailable()) {
        selectionItems.add((DocPartite) dataTable.getRowData());
        }
        }
        dataTable.setRowKey(originalKey);
      }
      
      

       

       

      The problem I have is that when the event its fired my variable "selection" its always null.

      I think the problem its because the page its loaded in a ui:include because if I launch the page like a "stand-alone" page I have no problem with that and the selection has inside the righe row.

      The page has some other little problem when loaded using the ui:include.

       

      Thank you very much.

      Best Regards, Mario.

        • 1. Re: ExtendedDataTable selection null in ui:include page
          Michal Petrov Master

          Hi,

           

          what's the scope of the homeBean? It should be ApplicationScoped (maybe SessionScoped works also). You also have <html> tag that doesn't belong there.

          Please include only relevant parts of the code, we don't need to see the entire page - http://sscce.org/

          1 of 1 people found this helpful
          • 2. Re: ExtendedDataTable selection null in ui:include page
            Mario Andala Newbie

            Sorry, I cleaned the code removing the not relevants parts.

            The scope of HomeBean is Session, tried with Application but didnt changed.

             

            I added the html Tag in included page because the application start with the src of include empty and with a panel menu item its changed to the correct page but doing like this the included page was not skinned.

            • 3. Re: ExtendedDataTable selection null in ui:include page
              Mario Andala Newbie

              Looks like if I enclose the ExtendedDataTable in a <h:form> it starts to work but not perfect because first click dont make any selection (and dont fire the event) and everytime I click another row (than fire the event) the datagrid view is refreshed moving it at the beginning.

              • 4. Re: ExtendedDataTable selection null in ui:include page
                Michal Petrov Master

                Mario Andala wrote:

                 

                Looks like if I enclose the ExtendedDataTable in a <h:form> it starts to work but not perfect because first click dont make any selection (and dont fire the event) and everytime I click another row (than fire the event) the datagrid view is refreshed moving it at the beginning.

                Well, <h:form> is necessary for any components that send requests to server. But if you get it to work without the include a form must have already been there. For the a4j:ajax add execute="@this".

                The <html> should be on the main page, the page you're including is not a full page, just a piece of code.

                1 of 1 people found this helpful
                • 5. Re: Re: ExtendedDataTable selection null in ui:include page
                  Mario Andala Newbie

                  Thank you very much for the help Michal but that not worked too.

                  Searching and searching I found this post of a similar problem : Re: Richfaces 4 ui:include not load Javascript and CSS files

                  Inside there is a link that redirect to this that helped me : RichFaces 4 and Today's Mobile Web Frameworks (Part 1)

                  Looks like in JSF 2 it is not possible to use parents of forms as render targets in <f:ajax/> or jsf.ajax.request : https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-1024

                   

                   

                  There was only a little problem more that I had:

                   

                  my first page with ui:composition was a blank page without nothing inside:

                  <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                    xmlns:h="http://java.sun.com/jsf/html"
                    xmlns:f="http://java.sun.com/jsf/core"
                    xmlns:ui="http://java.sun.com/jsf/facelets"
                    xmlns:a4j="http://richfaces.org/a4j"
                    xmlns:rich="http://richfaces.org/rich">
                  
                  
                  
                  </ui:composition>
                  
                  

                   

                  When I click on my panelMenuItem changing the src of the include of my page with the ExtendedDataTable it load the page but it dont skin the dataTable.

                  Adding a <h:head> and <h:body> inside the ui:composition of the page with the datatable fix it but was not correct then I tried to find a workaround.

                  Looks like loading page in that ui:include didnt load extendeddatatable component fully then I did a little trick loading in a hidden outputpanel in my first blank page some components that I will use later in other pages and forcing it to load.

                  Then my blank.xhtml page become like this:

                  <ui:composition xmlns
                  ="http://www.w3.org/1999/xhtml"
                    xmlns:h="http://java.sun.com/jsf/html"
                    xmlns:f="http://java.sun.com/jsf/core"
                    xmlns:ui="http://java.sun.com/jsf/facelets"
                    xmlns:a4j="http://richfaces.org/a4j"
                    xmlns:rich="http://richfaces.org/rich">
                  
                  
                    <a4j:outputPanel rendered="false"> 
                       <rich:popupPanel/> 
                       <rich:calendar/> 
                       <rich:collapsiblePanel/> 
                       <rich:extendedDataTable>
                       </rich:extendedDataTable>
                    </a4j:outputPanel>     
                  </ui:composition>
                  
                  

                   

                  Thanks again for your reply and your effort to help me Michal.

                  Best Regards.

                  • 6. Re: ExtendedDataTable selection null in ui:include page
                    Rudi Lausa Newbie

                    Hi,

                     

                    I have the same problem.

                    My solution was to take out the <h:form> tag from the include page.

                    You can't nest forms!!!

                    Put form an the main page, and try to take it out from the included page.

                     

                    Regards!