tags:

views:

28

answers:

1

I am using a Datatable in JSF1.2 to populate the data received from Seam component/ using a List. The data is getting fetched when I use the list. But when, I want to make the Datatable editable so that the value I am changing on the JSF page can be sent back to the Seam Component/ Backing Bean the list is not passing value to the Seam component/Backing Bean.

I have tried but I am unable to pass the list to Seam component/Backing Bean again.

Below is the code.

JSF code:

<h:dataTable value="#{mainbean.findCustomerlist}" var="findCustomerList">
   <h:column>
    <f:facet name="header">
     <h:outputText value="Sr No" />
    </f:facet>
    <h:outputText value="#{findCustomerList.id}" />
   </h:column>
   <h:column>
    <f:facet name="header">
     <h:outputText value="Company Name" />
    </f:facet>
    <h:inputText value="#{findCustomerList.companyName}" />
   </h:column>

   <h:column>
    <f:facet name="header">
     <h:outputText value="Account Number" />
    </f:facet>
    <h:inputText value="#{findCustomerList.accountNumber}" />
   </h:column>
   <h:column>
    <f:facet name="header">
     <h:outputText value="Contact Number" />
    </f:facet>
    <h:inputText value="#{findCustomerList.contactNumber}" />
   </h:column>
   <h:column>
    <f:facet name="header">
     <h:outputText value="Contact Name" />
    </f:facet>
    <h:inputText value="#{findCustomerList.contactName}" />
            </h:column>
      <br></br>

  </h:dataTable>

<h:commandButton value="Update" type="submit" action="#{mainbean.modifyCustomer(findCustomerlist)}" />

Seam Component/Backing Bean Code:

private List<Customer> findCustomerlist=null;


public List<Customer> getFindCustomerlist() {
  return findCustomerlist;
 }

 public void setFindCustomerlist(List<Customer> findCustomerlist) {
  this.findCustomerlist = findCustomerlist;
}


public void searchCustomer(ActionEvent actionEvent)
    {
     findCustomerlist=session.findCustomer(customerName);
    }

/* The searchCustomer function works fine and it returns the list to the JSF. But when I use the modifyCustomer function to retrieve the value from JSF then it is not working.*/  

    public void modifyCustomer(List<Customer> findCustomerlist)
    {
         session.updateCustomer(findCustomerlist);
         System.out.println("Inside modifyCustomer");
         System.out.println(findCustomerlist.get(0).getCompanyName());
    } 
A: 

I am not sure what Seam is doing about this, but in normal JSF this is unnecessary. Normally, JSF has already updated the list property during update model values phase. You just has to access it as a local bean property. I.e.

<h:commandButton value="Update" type="submit" action="#{mainbean.modifyCustomer}" />

with

public void modifyCustomer()
{
     session.updateCustomer(findCustomerlist);
     System.out.println("Inside modifyCustomer");
     System.out.println(findCustomerlist.get(0).getCompanyName());
} 

should already be enough.

You only need to ensure that the same list is preserved by the backing bean. The code which you've shown as far will fail when the bean is request scoped. If you're on JSF 2.0 you could put the bean in view scope. On JSF 1.x you need to either put bean in session scope (not recommended) or to preload the list in bean's constructor or @PostConstruct based on customerName.

BalusC