Unable to populate values obtained from ajax call using PrimeFaces

走远了吗. 提交于 2019-12-13 07:26:53

问题


Hi
I have made an ajax call using primefaces [p:ajax]. The call to the listener was successful and it returned the required values. To update these properties in xhtml, I have checked the DOM source, to find out the exact ID of the column, using which the column or property would be updated. But, in this case the fields are not getting the values.

The code I used in this case is

        <p:dataTable id="table1" var="recepit" rowIndexVar="rowIndex"   value="#{ReceiptDetailsBean.iterativeList}" scrollable="true"  height="120px" styleClass="leftTable">

            <p:column style="background-color: #EFF2F9">
                <f:facet name="header">
                    <h:outputText value="SL NO" />
            </f:facet>
                    <h:outputText value="#{rowIndex+1}" />

            </p:column>

            <p:column >
                <f:facet name="header">
                    <h:outputText value="Buss." />
                </f:facet>

                        <h:selectOneMenu id="selectOneCb" value="#{ReceiptDetailsBean.bussCode}" >
                            <f:selectItem itemLabel="V_BUSS_CODE" itemValue=""/>
                            <f:selectItems value="#{ReceiptDetailsBean.rdetails}" var="model" itemLabel="#{model.buss}" itemValue="#{model.buss}"/>
                             <p:ajax update="mainForm:table1:#{rowIndex}:receiptCode, mainForm:table1:#{rowIndex}:referenceType"  actionListener="#{ReceiptDetailsBean.obtainReceiptDatabasedOnBussCode}" event="change"/>  
                        </h:selectOneMenu>

            </p:column>

            <p:column id="receiptCodeCol">
                <f:facet name="header">
                    <h:outputText value="Receipt Code" />
                </f:facet>

                        <h:inputText value="#{ReceiptDetailsBean.receiptCode}" id="receiptCode" style="font-family: verdana;font-size: 10px;width:80px;height:15px" />


            </p:column>

            <p:column id="receiptTypeCol">
                <f:facet name="header">
                    <h:outputText value="Ref Type" />
                </f:facet>

                        <h:inputText value="#{ReceiptDetailsBean.receiptType}" id="referenceType" style="font-family: verdana;font-size: 10px;width:80px;height:15px"/>


            </p:column>


        </p:dataTable>

                    </div>


        </p:tab>

        <p:tab title="Print">

        </p:tab>



</p:tabView>
</h:form>

The id from the DOM view source was table1:0:receiptCodeHotKey:receiptCode

What would be the problem for the data to not get populated in the field.


回答1:


I think the source of the problem is your usage of h:form. You don't need to put it around each single input element. Put one h:form around the datatable and then check again the generated ids.

Then it should be something like (example for first row with rowindex 0):

formId:table1:0:receiptCode


来源:https://stackoverflow.com/questions/6016948/unable-to-populate-values-obtained-from-ajax-call-using-primefaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!