JSF Valuechange in DataTable
I have a datatable with 10 rows.
The first column in each row has a valuechange event. For e.g it's like, we enter the accountnumber and the valuechangeevent retrieves
the account information.
Now, i also have another column to display the cost. If user enters some amount, it should add up all the amounts in all the rows and
display it on a different column.
But the problem is, the user can enter a second account number at any point of time. then it will again be a valuechange event. now, since
it is a value change event, the information in the first row is not updated in the DataModel. As such, i am losing the previously entered
amount for the first row.
Is there a way to implement this functionality without losing the previous information?
Also, when we use "javascript:this.form.submit();" in the JSP, where does the submit go? In other words, is there a default action method
that we can specify to go to?
Thank you,
Seshu
# 8
<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<h:dataTable id="ps" width="200" value="#{pbo.model}" binding="#{pbo.modelTable}"
var="item">
<h:column>
<h:inputText id="nbr" value="#{item.nbr}" size="10"valueChangeListener="#{pbo.processValueChange}" immediate="true" onblur="submit>
</h:inputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText styleClass="outputText" value="Amt" id="text16">
</h:outputText>
</f:facet>
<h:inputText styleClass="inputText" id="amt"value="#{item.duesAmount}" size="10" valueChangeListener="#{pbo.processAmountValueChange}" immediate="true" onblur="submit();" >
</h:inputText>
<f:attribute value="10" name="width" />
</h:column>
</h:dataTable>
Message was edited by:
Seshu_Varanasi
# 9
in your processAmountValueChange(ValueChangeEvent evnt), are you setting evnt.getNewValue() to the corresponding duesAmount .
here is an example of what should be there in processAmountValueChange(ValueChangeEvent evnt):
Item changedItem = (Item) itemsModel.getRowData();
changedItem.setDuesAmount(evnt.getNewValue().toString());
# 12
Hi BalusC
Yes, it is a session scoped bean.
In the backing bean, i use
pList = (ArrayList)model.getWrappedData();
where "model" is the DataTable in the JSP. After i get the arraylist, i just iterate through it, to retrieve all the values. But somehow, the values in these rows are not reflected.
Does it have something to do with the "binding" attribute i used in the JSP?
# 14
I've tested the JSF code snippet you gave. All values gets updated in the datamodel, unless where I enter the value.
It just works in a session scoped bean. When putting it in the request scope, I had to do some rework.
But first off, I am not sure if I understand the problem correctly.
You're talking about losing information of the "first row" everytime. This sounds obvious, aren't you just meaning the "first column"?
And you're talking about adding up all amounts and showing it in another column. But I don't see this column in the code.
Can you show the complete and reproduceable JSF + backing bean code snippets?