views:

191

answers:

1

I've got this h:dataTable and form:

<h:form>
<h:dataTable value='#{bean.allData.dataItems}' var='item'>
   <h:column>
     <h:outputText value='#{item.id}' />
   </h:column>

   <h:column>
     <h:inputText value='#{item.name}' />
   </h:column>
</h:dataTable>

<h:commandButton value="Save" action="#{bean.saveEntries}"/>
</h:form>

So the table shows the id and a textbox with the name in. That works. When a user clicks the button, I'd like it to save any changes to the name field.

DataBean has:

private Vector<ItemBean> dataItems;

// constructor here

public void setDataItems(Vector v) {
   dataItems = v;
}

public Vector getDataItems() {
   return dataItems;
}

and ItemBean has...

private String id;
private String name;

// setter for both
// getter for both

Bean has a variable 'allData' of type 'DataBean'.

Bean also has a method saveEntries() which is currently blank (as I'm not sure how it works). How do I reference the inputs to set these values?

+1  A: 

JSF has already done it during UPDATE MODEL VALUES phase. Print/debug the local variables and you'll see. All you need to do in the save method is just persisting the data in some datastore.

Also see the following articles for more background information and examples:

  1. Using datatables.
  2. Debug JSF lifecycle.
BalusC