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>

