如何使用PrimeFaces在JSF上创建具有多个页面的表单

时间:2018-04-30 02:00:31

标签: jsf primefaces

您好我想问一些事情,我尝试使用带有primeface的java制作网站表单,我用2页制作此表单但是当我尝试输入数据时,第二页的数据有时无法在数据库中设置我尝试修改代码,第一页上的数据无法设置,但第二页上的数据可以在数据库上设置

这是我保存数据的代码

<ul class="buttons">
   <li><button class="add-winner">Add Winder</button></li>
   <li><button class="save">Save</button></li>
   <li><a href="https://www.w3schools.com">Cancel</a></li>
</ul>

第一页的这个xhtml

public String save(){
    String nextPage = "";

    PRPKUserNonIt PRPKUser = new PRPKUserNonIt();

    PRPKUser prpkUser = new PRPKUser();
    setListUserSelected(chooseBean.getListSelecteduser());

    try{
        prpkUserController.save(prpkUser);
        nextPage = "/prpk/master_prpk.xhtml?faces-redirect=true";
        RequestContext rq = RequestContext.getCurrentInstance();
        rq.execute("PF('successDialog').show();");
    }catch(Exception e){
        e.printStackTrace();
        FacesMessage messageFailed = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error","Save data failed");
        RequestContext.getCurrentInstance().showMessageInDialog(messageFailed);
        nextPage = "#";
    }


    Group group = new Group();
    setListGroupSelected(chooseTargetSDDialogBean.getGroupSelection());
    try{
        groupController.save(group);
        nextPage = "/prpk/master_prpk.xhtml?faces-redirect=true";
        RequestContext rq = RequestContext.getCurrentInstance();
        rq.execute("PF('successDialog').show();");
    }catch(Exception e){
        e.printStackTrace();
        FacesMessage messageFailed = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error","Save data failed");
        RequestContext.getCurrentInstance().showMessageInDialog(messageFailed);
        nextPage = "#";
    }

    PRPKNon PRPKNon = new PRPKNon();


    PRPKNon.setUser_non_itId(userLogin.getId());
    PRPKNon.setSenderId(userLogin.getId());
    PRPKNon.setPic_prpkId(userLogin.getId());
    PRPKNon.setCreatedBy(userLogin.getName());
    PRPKNon.setUpdatedBy(userLogin.getName());
    for (Map.Entry<String, Integer> e : prpkTypeIdMap.entrySet()) {
        if (prpkTypeTypeId.equals(e.getValue())) {
            prpkTypeType = e.getKey();
            continue;
        }
    }
    PRPKNon.setPrpkTypeId(prpkTypeTypeId); //diubah
    PRPKNon.setPrpkTypeName(prpkTypeType);
    PRPKNon.setPrpkDesc(prpkDesc);
    PRPKNon.setMemoNumber(memoNumber);


    for (Map.Entry<String, Integer> e : priorityIdMap.entrySet()) {
        if (priorityTypeId.equals(e.getValue())) {
            priorityType = e.getKey();
            continue;
        }
    }
    setPriorityLevelId(priorityTypeId);
    setPriorityName(priorityType);

    for (Map.Entry<String, Integer> e : departmentIdMap.entrySet()) {
        if (departmentTypeId.equals(e.getValue())) {
            departmentType = e.getKey();
            continue;
        }
    }

    for (Map.Entry<String, Integer> e : businessUnitIdMap.entrySet()) {
        if (businessUnitTypeId.equals(e.getValue())) {
            businessUnitType = e.getKey();
            continue;
        }
    }

    PRPKNon.setPriorityId(getPriorityLevelId());//diubah
    PRPKNon.setPriorityLevel(getPriorityName());
    PRPKNon.setBusinessUnitId(getBusinessId());
    PRPKNon.setBusinessUnitName(getBussinessName());
    PRPKNon.setPicDepartmentId(getDepartmentId());
    PRPKNon.setDepartmentName(getDepartmentNames());


    PRPKNon.setBusinessUnitId(getBusinessUnitId());


    PRPKNon.setPicDepartmentId(departmentTypeId);//diubah
    System.out.println("Pic : "+ prpk.getPicDepartmentId());
    PRPKNon.setDepartmentName(departmentType);

    PRPKNon.setBusinessUnitId(businessUnitTypeId);//diubah
    PRPKNon.setBusinessUnitName(businessUnitType);
    nextPage = "/prpk/next_prpk_new.xhtml?faces-redirect=true";
    PRPKNon.setPrpkRequest(prpkRequest);
    PRPKNon.setPrpkBackground(prpkBackground);
    PRPKNon.setPrpk_analysisBenefit(prpk_analysisBenefit);


    try{
        prpkNonController.save(PRPKNon);
        nextPage = "/prpk/next_prpk_new.xhtml?faces-redirect=true";
        RequestContext rq = RequestContext.getCurrentInstance();
        rq.execute("PF('successDialog').show();");
    }catch(Exception e){
        e.printStackTrace();
        FacesMessage messageFailed = new FacesMessage(FacesMessage.SEVERITY_ERROR,"Error","Save data failed");
        RequestContext.getCurrentInstance().showMessageInDialog(messageFailed);
        nextPage = "#";
    }


    return nextPage;
}

和第二页的这个xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
template="/user_templates/template.xhtml">
<ui:define name="metadata">
</ui:define>
<ui:define name="content">
    <h:form id="formId" style="margin-top:35;" prependId="false">
        <p:contextMenu>
            <p:menuitem value="© Indomaret" />
        </p:contextMenu>
        <p:breadCrumb>
            <p:menuitem value="Home" />
            <p:menuitem value="PRPK" />
            <p:menuitem value="List PRPK"/>
            <p:menuitem value="Add New PRPK"/>
            <p:menuitem value="#{pRPKUserNonItBean.header}" />
        </p:breadCrumb>

        <h:panelGrid id="TableInputId" columns="2" cellpadding="10" >
             <h:panelGrid id="inputGridId1" columns="3" cellpadding="10" >
                <p:outputLabel value="PRPK Type" for="prpktypeTxt" />
                <p:selectOneMenu id="prpktypeTxt" value="#{pRPKUserNonItBean.prpkTypeTypeId}"
                    >
                    <p:ajax listener="#{pRPKUserNonItBean.updateButton}" update="formId"/>
                    <f:selectItem itemLabel="None Selected" itemValue=""
                        noSelectionOption="true" />
                    <f:selectItems value="#{pRPKUserNonItBean.prpkTypeIdMap}" />
                </p:selectOneMenu>
                <p:message for="prpktypeTxt" display="icon" />

                <p:outputLabel value="PRPK Reference" for="prpkReferenceTxt" />
                <h:panelGrid columns="2" cellpadding="0" border="0">
                    <p:inputText id="prpkReferenceTxt" disabled="true"
                        readonly="true" style="width:200; height:25"
                        value="#{pRPKUserNonItBean.prpkReference}" />
                    <p:commandButton icon="ui-icon-search"
                        action="#{pRPKUserNonItBean.showPRPKReferenceDialog}" rendered="#{pRPKUserNonItBean.prpkReferenceRendered}" process="@this">
                        <p:ajax event="dialogReturn" update="prpkReferenceTxt" />
                    </p:commandButton>
                </h:panelGrid>
                <p:message for="prpkReferenceTxt" display="icon"></p:message>

                <p:outputLabel value="Description" for="descriptionTxt" />
                <p:inputTextarea id="descriptionTxt" required="true" style="width:300; height:50"
                    value="#{pRPKUserNonItBean.prpkDesc}" />
                <p:message for="descriptionTxt" display="icon"></p:message>

                <p:outputLabel value="Memo" for="memoTxt"
                    style="display:block; width:100px;" />
                <p:inputText id="memoTxt" required="true" style="width:225; height:25"
                    value="#{pRPKUserNonItBean.memoNumber}" />
                <p:message for="memoTxt" display="icon"></p:message>

                </h:panelGrid>


            <h:panelGrid id="inputGridId2" columns="3" cellpadding="10" >


                <p:outputLabel value="Priority Level" for="prioritylevelTxt" />
                <p:selectOneMenu id="prioritylevelTxt" value="#{pRPKUserNonItBean.priorityTypeId}"
                    >
                    <f:selectItem itemLabel="None Selected" itemValue=""
                        noSelectionOption="true" />
                    <f:selectItems value="#{pRPKUserNonItBean.priorityIdMap}" />
                </p:selectOneMenu>
                <p:message for="prioritylevelTxt" display="icon" />


                <p:outputLabel value="Department" for="departmentTxt" />
                <p:selectOneMenu id="departmentTxt" value="#{pRPKUserNonItBean.departmentTypeId}"
                    >
                    <f:selectItem itemLabel="None Selected" itemValue=""
                        noSelectionOption="true" />
                    <f:selectItems value="#{pRPKUserNonItBean.departmentIdMap}" />
                </p:selectOneMenu>
                <p:message for="departmentTxt" display="icon" />


                <p:outputLabel value="OPU" for="opuTxt" />
                <p:selectOneMenu id="opuTxt" value="#{pRPKUserNonItBean.businessUnitTypeId}"
                    >
                    <f:selectItem itemLabel="None Selected" itemValue=""
                        noSelectionOption="true" />
                    <f:selectItems value="#{pRPKUserNonItBean.businessUnitIdMap}" />
                </p:selectOneMenu>
                <p:message for="opuTxt" display="icon" />
                <p:row></p:row><p:row></p:row><p:row></p:row>
                <p:row></p:row><p:row></p:row><p:row></p:row>
                <p:row></p:row><p:row></p:row><p:row></p:row>
                <p:row></p:row><p:row></p:row><p:row></p:row>
                <p:row></p:row><p:row></p:row><p:row></p:row>

                </h:panelGrid>
    </h:panelGrid>

        <p:outputLabel value="Target SD *" style="border:0;margin-top:10;margin-left:25;"/>

            <h:panelGrid width="60%">
                <p:commandButton value="Select Target SD"
                    action="#{pRPKUserNonItBean.showTargetSDDialog()}" immediate="true" >
                    <p:ajax event="dialogReturn" update="targetTable"/>
                    </p:commandButton>
                <p:dataTable 
                    paginatorPosition="bottom" rows="3" paginator="true"
                    rowsPerPageTemplate="10,15,25,50,100" rowIndexVar="rowIndex"
                    currentPageReportTemplate="Showing {startRecord}-{endRecord} out of {totalRecords}"
                    paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                    style="font-size:12px;"
                    var="group" widgetVar="targetTables" value="#{chooseTargetSDDialogBean.listGroupTemp}" id="targetTable">
                    <p:column headerText="No" width="5%">
                        <h:outputText value="#{rowIndex+1}" />
                    </p:column>
                    <p:column headerText="Target SD" width="40%">
                        <h:outputText value="#{group.name}" />
                    </p:column>
                    <p:column headerText="Description" width="45%"> 
                        <h:outputText value="#{group.description}" />
                    </p:column>
                    <p:column headerText="Delete" width="10%">
                        <center>
                            <p:commandButton icon="ui-icon-trash" action="#{chooseTargetSDDialogBean.deleteChooseGroupTargetSD(group)}" update="targetTable" immediate="true"/>
                        </center>
                    </p:column>
                </p:dataTable>
            </h:panelGrid>

            <p:commandButton value="Cancel"
                style="position: relative; bottom: -15px;" icon="ui-icon-circle-close"
                process="@this" action="/prpk/master_prpk.xhtml?faces-redirect=true" />
            <p:commandButton value="Next"
                style="float:right; position: relative; bottom: -15px;" icon="ui-icon-arrow-1-e"
                action="#{PRPKUserNonItBean.save}"  process="@this">
                <!-- <p:confirm header="Confirmation"
                    message="Are you sure the data correct ?" icon="ui-icon-alert" />  -->

            </p:commandButton>

    </h:form>
</ui:define>

0 个答案:

没有答案