This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSF and the fly likes Input text in each row of JSF datatable not getting updated while submitting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Input text in each row of JSF datatable not getting updated while submitting" Watch "Input text in each row of JSF datatable not getting updated while submitting" New topic
Author

Input text in each row of JSF datatable not getting updated while submitting

jackie parker
Greenhorn

Joined: Mar 31, 2011
Posts: 3
Hi,

I am new to JSF, and am in need of some advice on how to achieve the below requirement. I have a datatable, with input text(which displays a value from the DB) and a checkbox in each row. On checking the checkbox, the input text is enabled for editing, and on typing the new value and hitting the submit button outside the data table, the edited value is not being retained. Kindly let me know how this can be done(i need to be able to select multiple rows and then submit all at the same time). Here is the snippet of the jsf.


<h:dataTable bgcolor="White" id="pList" binding="#{MngdBean.pDataTable}"
var="pBean" value="#{MngdBean.pBeanList}"
width="100%"
border="0"
cellpadding="3"
cellspacing="0" >
<h:column>
<f:facet name="footer">
<hutputLabel value="Min"
style="text-align:left; font-size:smaller;visibility:hidden;"/>
</f:facet>
<h:inputText value="#{pBean.Min}" immediate="true"
size="4"
id="minInputText" converter="javax.faces.Integer"
disabled="true"
style="vertical-align:top;font-size:smaller;"
/>
</h:column>
<h:column>
<f:facet name="footer">
<hutputLabel value="Max"
style="text-align:left; font-size:smaller;visibility:hidden;"/>
</f:facet>
<h:inputText size="4" id="maxInputText" immediate="true"
style="vertical-align:top;"
disabled="true" converter="javax.faces.Integer"
value="#{pBean.Max}"
/>
</h:column>
<h:column>
<f:facet name="footer">
<hutputLabel value="check1"
style="text-align:left; font-size:smaller;visibility:hidden;"/>
</f:facet>
<h:selectBooleanCheckbox id="check1"
style="align:center;"
onclick="addOnclickToDatatableRows(this)"
value="#{pBean.check1Selected}"/>
</h:column>
</h:dataTable>
</h:panelGroup>
<h:panelGroup id="panelGroup12">
<h:commandButton value="Submit"
id="save"
action="#{MngdBean.getSelectedEditedItems}" />
........

My backing bean has the following properties with getters/setters:

private List pBean;
private HtmlDataTable pDataTable;

When my action method in the backing bean gets called I see that the state of the dataTable reflects the state when it was created, not the state when the user clicked the commandButton (after they have edited some of the editable text fields).

What's the best way to get this state back into the backing bean so I can update my model?

I have already tried using immediate attribute. Can anyone give me inputs on how i can use the actionListeners (cmd button )/value change listeners(check box) to handle this? Do we need to implement processAction method for such a requirement.

Thanks in advance
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15632
    
  15

Welcome to the JavaRanch, Jackie! You can use the "code" button in the editor to wrap Java code and XML with tags that will make your samples more readable.

Binding is something that's overused in JSF. You typically only need to do binding if you're doing advanced manipulation of the UI controls themselves. For a simple dataTable display, it's pretty much a waste of time.

When you submit a form using a submit button external to the table, the entire set of input controls in the table is submitted back to the server. If all of the control values are valid, the table datamodel is updated and the action processor method is fired. The action method can then do what it needs to do, secure in the knowledge that the model has been updated and that all of the data in the model is valid.

You cannot use checkbox controls to restrict what data comes back. HTML doesn't work that way. All of the data will come back. The best you can do is make your table model front your persistent data model and only update the actual persistent data for rows which have their checkbox properties checked "true".


Customer surveys are for companies who didn't pay proper attention to begin with.
jackie parker
Greenhorn

Joined: Mar 31, 2011
Posts: 3
Thanks Tim i got that to work, i had a disable attribute which was reseting the value to the old one inspite of updating, and sorry for pasting the code in the text area. I had a follow up question on what you said about getting all the data at once, is it possible to at least show the selected value outside the datatable in a different output text based on the selection of the check box? If so could you give me a small snippet which would do that.

Thanks in advance
jackie parker
Greenhorn

Joined: Mar 31, 2011
Posts: 3
Thanks guys, i figured out how to do it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Input text in each row of JSF datatable not getting updated while submitting
 
Similar Threads
Component ID frm1_window viewid has already been found in the view
inserting several rows in DB using h:datatable
Unable to call Action Methof
My binding with datatable give me null ate the backing bean, do i miss some thing
How can I refresh(reset) inputText in a dataTable?