Lazy View not working when included to a xhtml file from other xhtml file

169 Views Asked by At

The Lazy View is working fine in ListIM.xhtml. On adding tag in ListIM.xhtml and including it in test.xhtml The Data Table appears but the lazy operations cannot be performed.

test.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://xmlns.jcp.org/jsf/html"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
    <ui:include src="ListIM.xhtml">
    </ui:include>
</h:body>
</html>

ListIM.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://xmlns.jcp.org/jsf/html"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
 xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Facelet Title</title>
</h:head>
<h:body>
    <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">


   <h:form id="form">
      <p:dataTable var="iM" value="#{LazyView.lazyModel}" paginator="true" rows="10"
             paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
             rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{LazyView.selectedIm}" id="iMTable" lazy="true">
    <p:ajax event="rowSelect" listener="#{LazyView.onRowSelect}" update=":form:iMDetail" oncomplete="PF('iMDialog').show()" />

    <p:column headerText=" Id" sortBy="#{iM.id}" filterBy="#{iM.id}">
        <h:outputText value="#{iM.id}" />
    </p:column>
    <p:column headerText=" Name" sortBy="#{iM.name}" filterBy="#{iM.name}">
              <h:outputText value="#{iM.name}" />
    </p:column>
          <p:column headerText="Is  Active?" sortBy="#{iM.isActive}" filterBy="#{iM.isActive}">
              <h:outputText value="#{iM.isActive}" />
    </p:column>
</p:dataTable>

        <p:dialog header="IM Detail" widgetVar="iMDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
    <p:outputPanel id="iMDetail" style="text-align:center;">
        <p:panelGrid  columns="2" rendered="#{not empty LazyView.selectedIm}" columnClasses="label,value">


            <h:outputText value=" Id:" />
            <h:outputText value="#{LazyView.selectedIm.id}" />

            <h:outputText value=" Name" />
            <h:outputText value="#{LazyView.selectedIm.name}" />

            <h:outputText value="Is Active?:" />
            <h:outputText value="#{LazyView.selectedIm.isActive}" />

        </p:panelGrid>
    </p:outputPanel>
</p:dialog>
  </h:form>

  </ui:composition>


    </h:body>

LazyView.java

package com.service;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;
import org.primefaces.showcase.domain.Im;

@ManagedBean(name="LazyView")
@ViewScoped
public class LazyView implements Serializable {

private LazyDataModel<Im> lazyModel;

private Im selectedIm;

@ManagedProperty("#{imService}")
private ImService service;

@PostConstruct
public void init() {
    lazyModel = new LazyImDataModel(service.createIms());
}

public LazyDataModel<Im> getLazyModel() {
    return lazyModel;
}

public Im getSelectedIm() {
    return selectedIm;
}

public void setSelectedIm(Im selectedIm) {
    this.selectedIm = selectedIm;
}

public void setService(ImService service) {
    this.service = service;
}

public void onRowSelect(SelectEvent event) {

}
}

Thanks in Advance

0

There are 0 best solutions below