multiple ValueChangeListeners in a DataTable

Hi all,

I have 3 valueChangeListeners in a datatable on the JSP.

the first textbox will populate the entire row based on the textfield value.

The second and third valuechangelisteners update the costs of all the rows.

here is the jsp:

<h:dataTable border="0" cellpadding="2" cellspacing="2"

columnClasses="columnClass1" headerClass="headerClass"

footerClass="footerClass" rowClasses="rowClass1"

styleClass="dataTable" id="pms" width="200"

value="#{pmBO.model}"

binding="#{pmBO.modelTable}" var="item" rows="10">

<h:column>

<h:inputText styleClass="inputText" id="empNo"value="#{item.empNo}" size="10" valueChangeListener="#{pmBO.processValueChange}" immediate="true" onblur="submit();">

</h:inputText>

</h:column>

<h:column>

<h:inputText styleClass="inputText" id="dAmount value="#{item.dAmount}" valueChangeListener="#{pmBO.processAmountValueChange}" onblur="submit();" size="10" >

</h:inputText>

</h:column>

<h:column>

<h:inputText styleClass="inputText" id="pAmount" value="#{item.pAmount}" size="10" valueChangeListener="#{pmBO.processAmountValueChange}" onblur="submit();">

</h:inputText>

</h:column>

<h:column>

<h:selectOneMenu styleClass="selectOneMenu" id="PInd" value="#{item.pInd}">

<f:selectItems value="#{pmBO.pInds}"/>

</h:selectOneMenu>

</h:column>

<h:column id="column1">

<h:inputText styleClass="inputText" id="fAmt"value="#{item.fAmount}"size="10">

</h:inputText>

</h:column>

</h:dataTable>

After i populate the first row, i select pInd and fAmount...fields

and now, if i enter the empNo in the second row and populate it, the values i entered in pInd and fAmount for thefirst row are lost.

Are these not supposed to be in the modelTable that is bound to the Backing beant? Am i missing something here?

and here is the code in the valueChangeListener and the binded HtmlDataTable:

publicvoid processAmountValueChange(ValueChangeEvent ve){

double value = 0.0;

value = ((Double)ve.getNewValue()).doubleValue();

valueChangeSource = ((UIInput)ve.getSource()).getId();

setRowIndex(getModelTable().getRowIndex());

valueChange =true;

if (valueChangeSource.equalsIgnoreCase("dAmount"))

setDAmount(value);

elseif(valueChangeSource.equalsIgnoreCase("pAmount")){

setPAmount(value);

}

modify();//this is where the manipulation of the arraylist goes.

valueChange =false;

valueChangeSource ="";

}

/**

* @param modelTable The modelTable to set.

*/

publicvoid setModelTable(HtmlDataTable modelTable){

this.modelTable = modelTable;

pList =new ArrayList();

try{

for (int i=0; i < modelTable.getRows(); i++){

modelTable.setRowIndex(i);

Item item = (Item)modelTable.getRowData();

pList.add(i, item);

System.out.println("^^^^^^^^^^ in the for loop $$$$$$$$ = "+i+";"+item.getPType()+";"+item.getFAmount());

}

setPList(pList);

}catch(Exception e){

e.printStackTrace();

}

}

When i see the console for the changed values, the Modeltable doesn't show the values selected for the first row.

i know that value change listener doesn't update all the request values. But i want the values selected in the first row too.

The backing bean is in session scope.

is there a way to get around this?

Thank you

[5894 byte] By [Seshu_Varanasia] at [2007-11-26 17:09:29]
# 1
any ideas pls? i don't understand why the datatable is not getting updated for a valueChange even if it is binded to the backing bean.
Seshu_Varanasia at 2007-7-8 23:37:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

ok. i guess i figured out the problem.

in my valueChangeListener i am constructing the arrayList again.

I thought the values from the JSP would get set in the corresponding row Item even if it is a valueChange.

Now, i am just retrieving that row and modifying it, and adding it to the arrayList at the "Row Index" and setting the DataModel. Please see the code below:

public void processValueChange(ValueChangeEvent ve) {

String value = "";

value = (String)ve.getNewValue();

setRowIndex(getModelTable().getRowIndex());

Item item = (tem)modelTable.getRowData();

if(!isEmptyString(value)){

item = getItemDetails(value);

System.out.println("<<<<<<< county = "+item.getCounty());

pList.add(getRowIndex(), item);

}

model = new ListDataModel(pList);

model.setWrappedData(pList);

setModel(model);

}

public void setModelTable(HtmlDataTable modelTable) {

this.modelTable = modelTable;

pList = new ArrayList();

try{

for (int i=0; i < modelTable.getRows(); i++){

modelTable.setRowIndex(i);

Item item = (Item)modelTable.getRowData();

pList.add(i, item);

System.out.println("in the for loop = "+i+";"+item.getCounty());

}

}catch(Exception e){

e.printStackTrace();

}

}

After i do this, only some of the columns are getting showed on the JSP. one of them is dropdown for "county".

I fail to understand why only few items are getting updated on the screen.

someone please explain me what is it that i am doing wrong here.

Seshu_Varanasia at 2007-7-8 23:37:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Someone pls help me with this.
Seshu_Varanasia at 2007-7-8 23:37:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Figured it out. Sorry for the late reply.I needed to use a new arraylist (atleast, i should not use the arraylist that was used to create the initial datatable) everytime there was a change. HTH
Seshu_Varanasia at 2007-7-8 23:37:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...