• Post Reply Bookmark Topic Watch Topic
  • New Topic

SelectOneMenu control not returning selected value

 
Avrajit Roy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem with the SelectOneMenu control. I want the the selected item to be be displayed via the valueChange Ajax event listen. But this is not happening.

However, when I change the value in the SelectOneMenu and then click on the Submit button, then selected value is getting displayed via the 'save' bean function

Cannot figure out why this is not working. Would appreciate any help on this.

Thanks.

The relevant xhtml code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<style type="text/css">
.ui-widget,.ui-widget .ui-widget {
font-size: 90% !important;
}
.ui-growl {
left:400px;
top:200px
}
.ui-stack {
bottom: 28px;
right: 500px;
}
.myStyle
{
font-size: 12px;
font-style: italic;
color:#009900;
}
</style>
<script type="text/javascript">
window.history.forward();
function noBack() {
window.history.forward();
}
</script>
</h:head>
<h:body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
<h:form>
<h:dataTable value="#{dynamicList.myData}" var="item">
<h:column>
<h:outputText value="#{item.oracleType}"></h:outputText>
</h:column>
<h:column>
<h:selectOneMenu value="#{item.coffeeFlavour}" rendered="#{item.showLov}">
<f:selectItems value="#{item.coffeeList}"></f:selectItems>
<f:ajax event="valueChange" listener="#{dynamicList.listen}"></f:ajax>
</h:selectOneMenu>
<h:inputText value="#{item.coffeeFlavour}" rendered="#{item.showText}"></h:inputText>
</h:column>
</h:dataTable>
<h:commandButton value="Submit" action="#{dynamicList.save}"></h:commandButton>
</h:form>

</h:body>
</html>

 
Tim Holloway
Bartender
Posts: 18413
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Avrajit!

You can use the "Code" button to preserve formatting on XML and indented plain text. It's not just for Java code!

My first thought was that perhaps it would like a nice cup of tea, instead, but that was unworthy. I cannot see specifically what's wrong, but there are a couple of things I did note that might be done better.

First, package names are recommended to be lower-case. That is, "mypack", not "MyPack". Some Java tools may become offended.

Secondly, you are being a bit casual in how you work with Lists and Maps. JSF can be especially problematic about this, since a List is, by definition, an ordered collection, but a Map is not, and there are times when JSF needs an ordered collection specifically.

Thirdly, although a lot of people do this, I do not recommend using a raw ordered collection (List, array, etc.) as the value model for an h:dataTable. JSF provides a set of wrapper classes that can be used to decorate the raw data with important and useful information. Among other things, that allows both your save() and listen() methods to know specifically which row you were working with when you submitted the form or partial form simply by using the DataModel's getRowData() or getRowIndex() method. You don't save any overhead (other than a minor amount of coding). If you pass a raw collection directly to the dataTable; the dataTable automatically constructs a DataModel and wraps the collection in it, but your application code cannot see it, and therefore cannot invoke getRowData/Index on it.
 
Avrajit Roy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tim for your observations or the irrelevant lecture which did not solve my problem, in the mean while I found the solution !!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!