素数升级 -- 数据表不工作



最近我将我的项目从 primefaces 3.3.1 升级到 3.4.1 。除了惰性数据模型外,其余所有项目都工作正常。我是否必须进行任何其他更改?

我的 XHTML 代码:

 <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>

我的惰性数据模型代码:

@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;
    }
}

我的豆子

@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;
        }

这可能与 3.4 中的部分 ajax 行为更改有关。以下是 3.4 迁移指南

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

尝试设置定数。在 web 中提交到 true.xml看看这是否得到解决。

相关内容

  • 没有找到相关文章

最新更新