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

[1016 byte] By [Seshu_Varanasia] at [2007-11-26 15:30:10]
# 1
any ideas pls?
Seshu_Varanasia at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
try using t:datatable with attribute preserveDataModel set to false. I am not sure if that would help but you can give it a try.
RJohara at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
i'm using IBM RI for the JSF tags. i don't think it has the preserveDataModel attribute.what does it do anyway?
Seshu_Varanasia at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
check http://wiki.apache.org/myfaces/Working_With_DataTable_And_PreserveDataModel for more info
RJohara at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Thanx Johar. Would have been helpful if IBM RI had the same too.
Seshu_Varanasia at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Any more ideas? i think i am missing something. I have the datatable bound to my backing bean and the bean is in session scope.Yet, the values in the price fields are not reflecting in the datatable.
Seshu_Varanasia at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
can you pls. share the code snippet showing ur datatable & the namespace uri for ibm jsf?
RJohara at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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

Seshu_Varanasia at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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());

RJohara at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
yes i did johar.the problem is...if i use this valuechange method then all the other values in the first row are not being retrieved.
Seshu_Varanasia at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11
Is it a request or session scoped bean? I've tested such a construction here and it just works with a session scoped bean.
BalusCa at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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?

Seshu_Varanasia at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
Hello BalusC,Can you send me the code you used?Thank you.
Seshu_Varanasia at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 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?

BalusCa at 2007-7-8 21:46:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15
You probably already resolved this, but in case you didn't, the element id'd as nbr has an incorrect submit command. The code above reads onblur=submit. I believe it should be this.form.submit() or document.forms[0].submit(), but submit itself is not a function...\W
wbossonsa at 2007-7-21 16:27:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...