Search code examples
javajavascriptjakarta-eejsf-2datatable

problem in fetching values,JSF-data table


I'm using JSF 2.0 and trying to display a list of data using a datatable. After my data is fetched I have button in each row, on this button it has to take some of the fields as input parameters and then save it.

<h:dataTable id="dt1" value="#{vendorApp.editQtnList}" var="qList" >
 <h:column>
  <f:facet name="header">
   <h:outputText style=""value="RFQ Number" />
  </f:facet>     
<h:column>
<f:facet name="header"> 
 <h:outputText value="Vendor Number"/>
</f:facet> 
<h:outputText value="#{qList.vendorNumber}"></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
 <h:outputText value="RFQ Date"/>
</f:facet>
<h:outputText value="#{qList.rfqDate}"></h:outputText> 
</h:column>
<h:column> 
<f:facet name="header">
 <h:outputText value=""/>
</f:facet>
<h:inputText id="adComment" value="#{qList.adminComment}"></h:inputText>
</h:column>
<h:column> 
<f:facet name="header">
 <h:outputText value=""/>
</f:facet>
<h:form>
 <h:commandButton id="rejectBtn" value="Reject" action="#{vendorApp.rejectEditQuotation}">
 <f:param name="vendorNum" value="#{qList.vendorNumber}" />
 <f:param name="rfqNum" value="#{qList.rfqNumber}" />
 <f:param name="adComment" value="#{qList.adminComment}" /> 
</h:commandButton></h:form> </h:column> </h:dataTable>

In my above code, editQtnList is the getter method for list which gives a list fetched from database.Now user can click on reject by proving a comment in the text box provided, I have tried this as shown but the value of the comment is not feteched..Need suggestions on this....


Solution

  • All input fields of interest must be placed inside the same form as the submit button.

    Rewrite your view as follows:

    <h:form>
        <h:dataTable value="#{vendorApp.quotations}" var="quotation">
            ...
            <h:column> 
                <h:inputText value="#{quotation.adminComment}" />
            </h:column>
            <h:column> 
                <h:commandButton value="Reject" action="#{vendorApp.rejectEditQuotation(quotation)}" />
            </h:column>
        </h:dataTable>
    </h:form>
    

    with

    public void rejectEditQuotation(Quotation quotation) {
        // ...
    }