Problem in h:selectoneMenuin a datatable

We are developing a page with a datatable. One column in thedatatable is h:selectOneMenu. We need to call the a new page according to the selected item in the i.e the value change in the h:selectOneMenu. There is no action to be done to call the page. HOw can this be done. Further in the code we need the reference of the row which the value change is called. I usehtmlDataTable.getRowData().

The problem comes here. We useimmediate ="true" andonclick="sumit()" so that the valuechangeListener is fired once the value is changed. But all the rows are called and all the rowdata are fetched in this case. Is there anything wrong in using onclick="submit();" in the h:selectOneMenu or is there any other way of coming around the problem.

I am attaching the code for ur reference.

ValueChangeListener

public void menuValueChange(ValueChangeEvent event) {

System.out.println("entered the value change function " + event);

System.out.println("the if method entered " + event.getPhaseId());

String s = (String)event.getNewValue();

newDO1 = (ClassNewDO)myDataTable.getRowData();

System.out.println("the row data is got and its values is " + newDO1);

System.out.println("the row data is got and its values is " +

newDO1.getId());

}

JSP file:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<%@ page contentType="text/html;charset=windows-1252"%>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<f:view>

<html>

<head>

<meta http-equiv="Content-Type"

content="text/html; charset=windows-1252"/>

<title>DataTableNew</title>

<script type="text/javascript">

</script>

</head>

<body><h:form id="form1">

<h:selectOneRadio id="radioButton"

valueChangeListener="#{sortBean.radioValueChange}"

immediate="true" onclick="submit();">

<f:selectItem itemValue="1" itemLabel="Radio1"/>

<f:selectItem itemValue="2" itemLabel="Radio2"/>

<f:selectItem itemValue="3" itemLabel="Radio3"/>

</h:selectOneRadio>

<h:dataTable value="#{sortBean.sortlist3}" id="Id_0" var="order"

binding="#{sortBean.myDataTable}" rendered="true"

>

<h:column rendered="#{sortBean.setColumn}">

<f:facet name="header">

<h:commandLink actionListener="#{sortBean.sortMyDataList}">

<f:attribute name="sortField" value="getId"/>

<h:outputText value="Identity"/>

</h:commandLink>

</f:facet>

<h:outputText value="#{order.id}" style="back"/>

</h:column>

<h:column>

<f:facet name="header">

<h:commandLink actionListener="#{sortBean.sortMyDataList}">

<f:attribute name="sortField" value="getName"/>

<h:outputText value="Name"/>

</h:commandLink>

</f:facet>

<h:outputText value="#{order.name}"

styleClass="#{order.color}"/>

</h:column>

<h:column>

<h:selectOneMenu valueChangeListener="#{sortBean.menuValueChange}"

value="#{sortBean.selectValue}"

immediate="true" onclick="submit();"

id="actionDropdown" binding="#{sortBean.selectRadioButton}" >

<f:selectItem itemValue="4" itemLabel="Radio1"/>

<f:selectItem itemValue="5" itemLabel="Radio2"/>

<f:selectItem itemValue="6" itemLabel="Radio3"/>

</h:selectOneMenu>

</h:column>

</h:dataTable>

<h:outputText value="Hai Sathya"/>

</h:form></body>

</html>

</f:view>

[3991 byte] By [suryan84a] at [2007-11-27 7:08:10]
# 1

Likely you misunderstood the working of valueChangeListener and you're expecting some client-side magic. The server side knows nothing about the changed value at the client side until you submits the value to the server side. So all values are submitted to the server, nothing wrong in here.

What you need to do is to compare event.getOldValue() with event.getNewValue(). If they differs then retrieve the rowData and do your thing with it.

BalusCa at 2007-7-12 18:59:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for the reply,

I tried your solution but the problem is that the event.getOldValue() is always returned null and so its not possible to compare the new and the changed value.

If I attempt giving the default value in the h:selectOneMenu the value is taken as new value on the row which i have not selected.However in the selected row the changed value is taken as new value and the old value is still null.

<h:selectOneMenu valueChangeListener="#{sortBean.menuValueChange}"

value="7"

immediate="true" onchange="submit();"

id="actionDropdown"

binding="#{sortBean.selectRadioButton}" >

<f:selectItem itemValue="4" itemLabel="Radio1"/>

<f:selectItem itemValue="5" itemLabel="Radio2"/>

<f:selectItem itemValue="6" itemLabel="Radio3"/>

</h:selectOneMenu>

suryan84a at 2007-7-12 18:59:38 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...