Ssv
Ssv

Reputation: 1059

primefaces upgrade-- Data table not working

Recently I upgraded my project from primefaces 3.3.1 to 3.4.1 . Except Lazy Data Model all the remaining project is working fine. Do I have to make any additional changes?

my xhtml code:

 <h:panelGroup id="clsTablePanel">
            <p:dataTable var="cls" value="#{classesBean.classModel}"
                sortBy="#{cls.classId}" sortOrder="descending"
                selectionMode="single" selection="#{classesBean.selectedClass}"
                paginator="true" rows="5" paginatorAlwaysVisible="false"
                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                lazy="true" widgetVar="clsTable" style="width:auto;margin:10px;">
                <p:ajax event="rowSelect" listener="#{classesBean.classRowSelect}"
                    update=":mainTab:clsDetailPanel" />
                <f:facet name="header">
                    <h:outputText value="#{titles.classList}" />
                </f:facet>

                <p:column headerText="Class Id" sortBy="#{cls.classId}"
                    style="width:10%;">
                #{cls.classId}
            </p:column>
                <p:column headerText="Class" sortBy="#{cls.className}"
                    style="width:10%;">
                #{cls.className}
            </p:column>
                <p:column headerText="Coordinator" style="width:20%;">
                #{cls.mtmdemployees.firstName}
            </p:column>
                <p:column headerText="Location" style="width:20%;">
                #{cls.mtmdlocation.locShortName}
            </p:column>

            </p:dataTable>
        </h:panelGroup>
    </div>
    <div>
        <p:outputPanel id="clsDetailPanel">

            <h:form>
                <p:messages id="clsmsgs" style="width:98%;margin:5px auto;" />
                <p:panelGrid columns="4" style="width:98%;margin:5px auto;">
                    <f:facet name="header">
                        <h:outputText value="#{titles.classinfo}"></h:outputText>
                    </f:facet>

                    <h:outputText value="ClassId"></h:outputText>
                    <p:inputText value="#{classesBean.selectedClass.classId}"
                        disabled="true" />

                    <h:outputText value="Class Name"></h:outputText>
                    <p:inputText value="#{classesBean.selectedClass.className}"
                        required="true" requiredMessage="Enter Class Name" />

                    <h:outputText value="Coordinator"></h:outputText>
                    <p:selectOneMenu value="#{classesBean.selectedEmployeeId}"
                        style="height:20px;">
                        <f:selectItems value="#{classesBean.employeesList}" var="emp"
                            itemLabel="#{emp.firstName}" itemValue="#{emp.employeeId}" />
                    </p:selectOneMenu>


                    <h:outputText value="Location"></h:outputText>
                    <p:selectOneMenu value="#{classesBean.selectedLocationId}">
                        <f:selectItems value="#{classesBean.locationList}" var="loc"
                            itemLabel="#{loc.locShortName}" itemValue="#{loc.locationId}" />
                    </p:selectOneMenu>

                    <f:facet name="footer">
                        <p:commandButton widgetVar="updateBt" value="Update"
                            action="#{classesBean.classesUpdate}" ajax="true" process="@form"
                            update="clsmsgs :mainTab:clsTablePanel"
                            disabled="#{classesBean.updateDisable}"
                            style="margin-left:5px;margin-right:5px;" />
                        <p:commandButton widgetVar="createBt" value="Create"
                            action="#{classesBean.classesCreate}" ajax="true" process="@form"
                            update="clsmsgs :mainTab:clsTablePanel"
                            disabled="#{classesBean.createDisable}"
                            style="margin-left:5px;margin-right:5px;" />
                        <p:commandButton widgetVar="clearBt" value="Clear"
                            action="#{classesBean.classesClear}" ajax="true" process="@none"
                            update="@form" oncomplete="clsTable.unselectAllRows()"
                            style="margin-left:5px;margin-right:5px;" />
                    </f:facet>

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

my Lazy Data Model code:

@Named
@WindowScoped
public class ClassLazyDataModel extends LazyDataModel<Mtmdclass> implements
        Serializable {

    static final long serialVersionUID = 12l;
    private static final Log log = LogFactory.getLog(ClassLazyDataModel.class);

    @Inject
    private HibernateUtil hibernateUtil;

    @Inject
    MtmdclassHome clsHome;

    private List<Mtmdclass> clsList = new ArrayList<Mtmdclass>();

    public ClassLazyDataModel() {
    }

    @PostConstruct
    public void init() {
        setDataModelSize();
    }

    public void setDataModelSize() {
        try {
            hibernateUtil.beginTransaction();               
            Long count = clsHome.getClassCount();
            this.setRowCount(count.intValue());
            hibernateUtil.commitTransaction();
            log.debug("Row Count:" + count);
        } catch (Exception ex) {
            if (hibernateUtil.isTransactionActive())
                hibernateUtil.rollbackTransaction();
            log.error("Exception getting employee row count" + ex);
            FacesContext.getCurrentInstance().addMessage(
                    null,
                    new FacesMessage(FacesMessage.SEVERITY_ERROR,
                            "Error getting employee row count",
                            "Error getting employee row count"));
        }
    }

    @SuppressWarnings("unchecked")
    @Override
    public Mtmdclass getRowData(String rowKey) {
        List<Mtmdclass> clsrows = (List<Mtmdclass>) getWrappedData();
        for (Mtmdclass cls : clsrows) {
            if (rowKey.equals((cls.getClassId()).toString()))
                return cls;
        }
        return null;
    }

    @Override
    public Object getRowKey(Mtmdclass cls) {
        log.debug("in getRowKey:classId" + cls.getClassId());
        return cls.getClassId();
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<Mtmdclass> load(int first, int pageSize, String sortField,
            SortOrder sortOrder, Map<String, String> filters) {
        log.debug("First:" + first + " PageSige:" + pageSize + " SortField:"
                + sortField + " SortOrder:" + sortOrder);
        try {
            // MtmdclassHome clsHome = new MtmdclassHome();
            hibernateUtil.beginTransaction();
            clsList = clsHome.lazyLoad(first, pageSize, sortField, sortOrder);
            for (Mtmdclass cls : clsList) {
                Hibernate.initialize(cls.getMtmdlocation());
                Hibernate.initialize(cls.getMtmdemployees());
            }
            hibernateUtil.commitTransaction();
            log.debug("in load: class Row Count: " + clsList.size());
        } catch (Exception ex) {
            if (hibernateUtil.isTransactionActive())
                hibernateUtil.rollbackTransaction();
            log.error("Exception fetching Employee List" + ex);
            FacesContext.getCurrentInstance()
                    .addMessage(
                            null,
                            new FacesMessage(FacesMessage.SEVERITY_ERROR,
                                    "Error Getting Students",
                                    "Error Getting Students"));
        }
        return clsList;
    }
}

my bean

@Inject
    ClassLazyDataModel classLDM;
private LazyDataModel<Mtmdclass> classModel;

public void loadClassesModel() {
        classModel = classLDM;
    }

            public void classRowSelect() {
                    oldEmpId = selectedClass.getMtmdemployees().getEmployeeId();

                    if (selectedClass.getMtmdemployees() != null) {
                        setSelectedEmployeeId(selectedClass.getMtmdemployees()
                                .getEmployeeId());
                    }
                    if (selectedClass.getMtmdlocation() != null) {
                        setSelectedLocationId(selectedClass.getMtmdlocation()
                                .getLocationId());
                    }
                    updateDisable = Boolean.FALSE;
                    createDisable = Boolean.TRUE;
                }

        public Mtmdclass getSelectedClass() {
                return selectedClass;
            }

            public void setSelectedClass(Mtmdclass selectedClass) {
                this.selectedClass = selectedClass;
            }
    public LazyDataModel<Mtmdclass> getClassModel() {
            return classModel;
        }

        public void setClassModel(LazyDataModel<Mtmdclass> classModel) {
            this.classModel = classModel;
        }

Upvotes: 0

Views: 700

Answers (1)

Murali D
Murali D

Reputation: 448

This is likely related to partial ajax behavior changes in 3.4. Below is the from the 3.4 migration guide

partialSubmit is now false by default. It can be globally configured using primefaces.SUBMIT context parameter and components can override the global setting with provided partialSubmit attribute

Try setting the primefaces.SUBMIT to true in web.xml and see if this is solved.

Upvotes: 1

Related Questions