3

Hi I have been beating my head all day with this issue and I am not sure what to do about it and I am hoping someone in this forum can help me.

When I render a standalone page with a dataTable element, all Ajax functionality works: Sorting, Navigation, etc.

But when I include the same page with the dataTable element inside another page via the "ui:include" tag, the table renders but all Ajax functionality is lost.

Here is the code for my "p:dataTable" page:

    <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:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
        <p:dataTable id="dataTable"
                     var="alarm" 
                     value="#{alarmsBean.alarms}"
                     paginator="true" rows="10"
                     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {NextPageLink} {LastPageLink}"
                     paginatorPosition="bottom">
            <f:facet name="header">
                Alarms
            </f:facet>
            <p:column id="deviceHeader" sortBy="#{alarm.device}">
                <f:facet name="header">
                    <h:outputText value="Device" />
                </f:facet>
                <h:outputText value="#{alarm.device}" />
            </p:column>
            <p:column sortBy="#{alarm.alarm}">
                <f:facet name="header">
                    <h:outputText value="Alarm" />
                </f:facet>
                <h:outputText value="#{alarm.alarm}" />
            </p:column>            
            <p:column sortBy="#{alarm.managedObject}">
                <f:facet name="header">
                    <h:outputText value="Managed Object" />
                </f:facet>
                <h:outputText value="#{alarm.managedObject}" />
            </p:column>            
            <p:column sortBy="#{alarm.alarmTime}">
                <f:facet name="header">
                    <h:outputText value="Alarm Time" />
                </f:facet>
                <h:outputText value="#{alarm.alarmTime}" />
            </p:column>            
            <p:column sortBy="#{alarm.severity}">
                <f:facet name="header">
                    <h:outputText value="Severity" />
                </f:facet>
                <h:outputText value="#{alarm.severity}" />
            </p:column>            
            <p:column sortBy="#{alarm.message}">
                <f:facet name="header">
                    <h:outputText value="Message" />
                </f:facet>
                <h:outputText value="#{alarm.message}" />
            </p:column>
        </p:dataTable>
    </ui:composition>

And here is the section of the other page that includes that page:

    <h:form id="mainF">
      <pe:layoutPane id="center" position="center">
          <h:panelGroup id="centerContent">
              <ui:include src="#{navigationBean.pageName}.xhtml" />
          </h:panelGroup>
      </pe:layoutPane>
    </h:form>

What am I doing wrong or is this a bug in PrimeFaces 3.3?

jrobertsz66
  • 953
  • 1
  • 12
  • 29
  • Ajax functionality requires a valid form. Apparently the form is lost or broken. What if you move `` to inside that `` tag? – BalusC Jun 18 '12 at 20:29
  • I have tried that and it doesn't work. I moved the form as follows: – jrobertsz66 Jun 18 '12 at 21:40
  • Oh wait, I now see that you're using EL in ``. I've posted the answer. – BalusC Jun 18 '12 at 21:42
  • I also tried moving the tag right above ui:include and that didn't work. I also tried moving the tag right above the dataTable element in the included page. Nothing works related to AJAX so long as the dataTable element is included inside ui:include. – jrobertsz66 Jun 18 '12 at 21:42
  • Should I expect better results from RichFaces than in PrimeFaces related to my issue? It seems I am spending countless hours on functionality that should be there and should be easy to use. – jrobertsz66 Jun 18 '12 at 21:43
  • And the help in their forum is lacking. – jrobertsz66 Jun 18 '12 at 21:43

1 Answers1

2
<ui:include src="#{navigationBean.pageName}.xhtml" />

You need to make sure that #{navigationBean.pageName} returns exactly the same value during processing the (ajax) form submit as it was when the initial page was displayed. If this is not the case, then JSF won't be able to find the input and command components involved in the (ajax) form submit.

So if that value depends on a request based parameter/variable, then you need to make sure that this request parameter/variable is preserved across form submits and available during bean's (post)construction. You can achieve that by passing it as <f:param> in the command buttons and setting it as @ManagedProperty. Note that placing the bean in the view scope won't work as the <ui:include src> as being a view build time tag gets its own brand new instance. You would need to turn off the partial state saving or to upgrade to JSF 2.2.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hmmmm...when my dataTable is already loaded in the page and I click on the navigation or sort buttons, navigationBean.pageName does not change. It is the same value for the duration of the data table display. So, I don't think that is it, unless I am not understanding your explanation. – jrobertsz66 Jun 18 '12 at 21:47
  • Hmmm...I think you are on to something there actually. I added a System.out.prinln to my NavibationBean to output pageName. When I initially load the alarms.xhtml page, the output is this: INFO: /pages/alarms, however, when I click on the navigation or sorting, I can see the navigation bean pringting this: /pages/alarms. – jrobertsz66 Jun 18 '12 at 21:57
  • The question is why is it being called again? It is defined with SessionScoped and ManagedBean annotations so I don't think that it should be outputting anything after the first time - meaning the output statement I just added is in the constructor, however, the constructor is being called over and over every time I click on sort button - this means a new NavigationBean with the default value is being created over and over after I load the page? – jrobertsz66 Jun 18 '12 at 22:01
  • Apparently `@SessionScoped` is imported from `javax.enterprise.context` (CDI) instead of from `javax.faces.bean` (JSF). It's called again during building the view. The session scope should indeed also work fine, although that would only result in unintuitive behaviour and bad user experience when the same page is opened in multiple browser windows/tabs in the same session. You'd rather want to use request or view scope instead for such a property. See also http://stackoverflow.com/questions/7031885/how-to-choose-the-right-bean-scope – BalusC Jun 18 '12 at 22:21
  • Man...you are good...:) Thanks for your help - I am still trying to digest it all. OK, I am going to go over everything you posted, including the other links, and see if I can get it to work. – jrobertsz66 Jun 18 '12 at 22:33
  • Hi BalusC, Can I run this by you? I think what you are saying is that instead of calling navigationBean.doNav('pages/pagename') I need to pass that as a parameter right? And then after that inject the parameter value via @ManagedProperty, but I am having trouble with that last part, where do I inject it? My page is already using #{navigationBean.pageName} and it is all xhtml, there is no other bean that changes this - the rest of the code is Prime Faces code so when I click the sort it is doing a refresh and creating a new NavigationBean instance due to `@SessionScoped` is loading it again. – jrobertsz66 Jun 18 '12 at 22:45
  • Man...I have to get used to this text box...I can't type very well in it...:) – jrobertsz66 Jun 18 '12 at 22:52
  • Well, I changed the value for the pageName (hard-coded for now) and the AJAX now works on dataTable - now I am struggling with changing it the correct way ...:) – jrobertsz66 Jun 18 '12 at 23:39
  • OK, I just went with saving the pageName in the session. That solved my problem. Thanks. – jrobertsz66 Jun 20 '12 at 12:55