0

我正在使用 PrimeFaces、JPA、Hibernate 和 JSF 2.0 开发一个 Web 应用程序。

我有这个JSF页面,“保存”和“取消”p:commandButton都没有动作!你能帮忙吗?

in中的操作 ( action="#{lotController.initLot}")重定向到此页面:p:commandButtonaction="#{lotController.initLot}"

<h:body style="width:600px; ">
<ui:composition template="/common/master-layout.xhtml">
    <ui:define name="title">#{message['app.page.main.title']}</ui:define>
    <ui:debug
        rendered="#{initParam['javax.faces.PROJECT_STAGE'] eq 'Development'}"
        hotkey="x" />
    <ui:define name="content">

        <p:fieldset legend="Création d'un nouveau lot"
            style="margin-top: 20px;">

            <h:form id="addLotForm">

                <p:fieldset legend="Lots techniques" toggleable="true"
                    toggleSpeed="500"
                    style="margin-left: 10px; margin-top: 30px; background-color:RGB(225,240,233)">

                    <h:panelGrid columns="2" cellpadding="10">
                        <h:outputText value="Libellé" style="font-weight:bold" />
                        <p:inputText value="#{lotController.lotToSave.libelle}" />
                    </h:panelGrid>

                </p:fieldset>

                <!-- Descriptifs -->
                <p:fieldset legend="Descriptifs" toggleable="true"
                    toggleSpeed="500"
                    style="margin-left: 10px; margin-top: 30px; background-color:RGB(225,240,233)">

                    <h:panelGrid columns="2" cellpadding="10">
                        <h:outputText value="Libellé" style="font-weight:bold" />
                        <p:selectOneMenu value="#{lotController.selectedDescriptif}"
                            effect="fade" converter="#{descriptifConverter}">
                            <f:selectItems value="#{lotController.listDescriptifs}" var="descriptif"
                                itemLabel="#{descriptif.libelle}" itemValue="#{descriptif}" />
                        </p:selectOneMenu>

                    </h:panelGrid>

                </p:fieldset>

                <p:commandButton value="Save" id="saveLot"
                    styleClass="ui-priority-primary"
                    action="#{lotController.createLot}"
                    style="margin-left:10px;margin-top:10px;margin-bottom:10px;height:125%;width:70px">
                </p:commandButton>

                <p:commandButton value="Cancel" id="cancelLot"
                    styleClass="ui-priority-primary"
                    action="#{lotController.cancelLot}"
                    style="margin-left:10px;margin-top:10px;margin-bottom:10px;height:125%;width:70px" />
            </h:form>
        </p:fieldset>
    </ui:define>

</ui:composition>

index.xhtml:

        <h:form id="listLotsForm">
            <p:panel>
                <ui:include src="lotDataTable.xhtml" />
            </p:panel>

        </h:form>

lotDataTable.xhtml:

                <p:commandButton value="Ajouter un lot" id="addLot"
                    styleClass="ui-priority-primary"
                    action="#{lotController.initLot}"
                    style="margin-left:10px;margin-bottom:10px;height:125%;width:140px" />

            <p:dataTable id="dataTableLot" var="lot" resizableColumns="true"
                liveResize="true" paginator="true"
                value="#{lotController.listLots}" rows="10" scrollable="false"
                style="width: 100%" selection="#{lotController.selectedLot}"
                rowKey="#{lot.idLot}"
                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                rowsPerPageTemplate="5,10,15" editable="true">


                <p:ajax event="rowEdit" listener="#{lotController.onEdit}"
                    update=":listLotsForm:messages" />
                <p:ajax event="rowEditCancel" listener="#{lotController.onCancel}"
                    update=":listLotsForm:messages" />
                    update=":listLotsForm:messages" /> -->

                <p:column headerText="N° lot" style="width: 100px">
                    <h:outputText value="#{lot.idLot}" />
                </p:column>

                <p:column headerText="Libellé" style="width: 100px">
                    <p:cellEditor>
                        <f:facet name="output">
                            <h:outputText value="#{lot.libelle}" />
                        </f:facet>
                        <f:facet name="input">
                            <p:inputText value="#{lot.libelle}" style="width:100%" />
                        </f:facet>
                    </p:cellEditor>
                </p:column>

                <p:column style="width:6%">
                    <p:rowEditor />
                </p:column>

                <p:column style="width:6%">
                    <p:commandButton action="#{lotController.deleteLot(lot)}"
                        icon="ui-icon-trash" title="Supprimer" />
                </p:column>


            </p:dataTable>

控制器:

public String createLot(){
    LotDto lot = prepareDtoBeforeSave();
    LotDto lotCreated = lotService.create(lot);
    clearLot();
    init();
    return "/views/administration/parametres/lot/listeLots?faces-redirect=true";
}

protected LotDto prepareDtoBeforeSave() {
    LotDto lot = new LotDto();
    lot.setIdDescriptif(selectedDescriptif);
    lot.setLibelle(lotToSave.getLibelle());
    return lot;
}
4

1 回答 1

1

谢谢你们。

我解决了这个问题,我忘了为我的转换器生成 hashCode() 和 equals() 方法。

于 2013-11-13T09:11:56.280 回答