简体   繁体   English

使用PrimeFaces使用独立的输入框保存数据表

[英]Saving datatable with a independent inputbox using PrimeFaces

I want to save my data table value with the inputtext value enter by the user. 我想将数据表值与用户输入的inputtext值一起保存。 my problem is my save method is not working and i am not able to find any idea to save it. 我的问题是我的保存方法不起作用,我无法找到任何保存它的想法。

my xhtml is: 我的xhtml是:

<h:message for="message"/>  
        <h:panelGrid columns="2" cellspacing="4" columnClasses="control-label">

            <h:outputText
                    value="#{msg['elicense.examinationform.personal.proposeofexam']}" />
                <p:selectOneMenu id="propExam" value="#{issueAdmitCardBean.examination}" 
                    converter="omnifaces.SelectItemsConverter" editable="false"
                    required="true" label="Examination Applied For" styleClass="dropdownWidth">
                    <f:selectItem itemLabel="---Select One---" itemValue="" />
                    <f:selectItems value="#{issueAdmitCardBean.testExamNames}" var="test" itemLabel="#{test.name}" itemValue="#{test}" />

                </p:selectOneMenu>

                <h:outputText value="Select Degree Category :" />
                <p:selectOneMenu id="degreeList"
                    value="#{issueAdmitCardBean.degree}" editable="false"
                    converter="omnifaces.SelectItemsConverter" required="true"
                    label="Please Select degree" styleClass="dropdownWidth">
                    <f:selectItem itemValue="" itemLabel="---Select One---" />
                    <f:selectItems value="#{issueAdmitCardBean.degreeNames}"
                        var="degree" itemLabel="#{degree.name}" itemValue="#{degree}" />
                </p:selectOneMenu>


                <h:outputText value="Center of Examination :"/>
                <p:selectOneMenu id="centerId" value="#{issueAdmitCardBean.center}" editable="false" 
                converter="omnifaces.SelectItemsConverter" required="true" label="Please select Center"
                styleClass="dropdownWidth">
                <f:selectItem itemValue="" itemLabel="---Select One---"/>
                <f:selectItems value="#{issueAdmitCardBean.centerNames}" var="center" 
                itemLabel="#{center.name}" itemValue="#{center}"/>
                <p:ajax   listener="#{issueAdmitCardBean.readVenuefromCenter(issueAdmitCardBean.center.id)}" update="venueNames"  />
                </p:selectOneMenu>


                <h:outputText value="Total No. of Candidates Under this Category :"/>
                <!-- <h:outputText value="#{issueAdmitCardBean.getTotalNoofCandidates()}"/>  -->



                 </h:panelGrid> 


                <p:dataTable id="venueNames" var="test" value="#{issueAdmitCardBean.venueNames}" 
                paginator="false" rows="10">

                    <p:column headerText="Id">
                        <h:outputText value="#{test.id}" />
                    </p:column>

                    <p:column headerText="Name Of Venue">
                        <h:outputText value="#{test.name}" />
                    </p:column>

                    <p:column headerText="Maximum Capacity ">
                        <h:outputText value="#{test.capacity}" />
                    </p:column>

                     <p:column headerText="Allot No. of Candidates ">
                        <h:inputText value="issueAdmitCardBean.allotedCandidates" style="width:50px;"/>
                    </p:column>

                    <p:column headerText="Exam Date">
                       <p:calendar value="issueAdmitCardBean.examDate" pattern="dd-MM-yyyy" navigator="true" style="width:10px;"/>
                     </p:column>

               </p:dataTable>


            <p:commandButton  icon="Save" value="Submit" action="#{issueAdmitCardBean.issueRollNoForExamination()}"/>
            </p:panel>

    </div>

</h:form>

and my managed bean save method is: 而我的托管bean保存方法是:

public void issueRollNoForExamination() {


        for(Venue venue :venueNames) 
        {
            System.out.println("name of vanue"+venue.getName());
        }
        }

but my save method will never execute. 但我的save方法将永远不会执行。 please help me to save my datatable with the update value. 请帮助我用更新值保存数据表。

You need to make a few changes in order to be able to update the venues in your backing bean. 您需要进行一些更改,以便能够更新后备bean中的场所

  1. Add a styleClass and rowIndexVar variable to your p:dataTable component styleClassrowIndexVar变量添加到p:dataTable组件

     <p:dataTable id="venueNames" var="test" value="#{issueAdmitCardBean.venueNames}" styleClass="dataTable" rowIndexVar="index" paginator="false" rows="10"> 
  2. change your input text to 将输入文本更改为

     <h:inputText value="#{issueAdmitCardBean.venueNames[index].allotedCandidates}" style="width:50px;"/> 
  3. Add an update to your save button 向您的保存按钮添加更新

     <p:commandButton icon="Save" value="Submit" update="@(.dataTable)" action="# {issueAdmitCardBean.issueRollNoForExamination()}"/> 

This will fix your immediate problem of not being able to update the values of allotedCandiadates. 这将解决您当前无法更新allotedCandiadates值的问题。 I didn't understand well the part in your question when you say "my save method will never execute". 当您说“我的保存方法将永远不会执行”时,我对您的问题部分不太了解。 But what I see in your code, the method should be triggered just fine, so if the issue is that you're not hitting the method in your backing bean, than the root cause is something else, that is not obvious from the snippet you've posted. 但是我在您的代码中看到的是,该方法应该被很好地触发,因此,如果问题是您没有在后备Bean中击中该方法,则根本原因是其他原因,这在您的代码段中并不明显已经发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM