File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
jackie parker
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
jackie parker
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, i figured out how to do it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic