Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

combo boks  RSS feed

 
Naeem Malik
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
del1.jsp

<h:selectOneMenu value="#{del1.selectedOption}" onchange="submit();"
valueChangeListener="#{del1.selectedOptionChanged}">
<f:selectItem itemLabel="Vet ikke" itemValue="Vet ikke"/>
<f:selectItem itemLabel="Mann" itemValue="Mann"/>
<f:selectItem itemLabel="Kvinne" itemValue="Kvinne"/>
</h:selectOneMenu>

Personnr.java

private String selectedOption;

public String getSelectedOption()
{
return selectedOption;
}

public void setSelectedOption(String selectedOption)
{
this.selectedOption = selectedOption;
}

public void selectedOptionChanged(ValueChangeEvent event)
{
selectedOption = (String)event.getNewValue();
if(selectedOption.equals("Vet ikke"))
activateOtherInput = true;
else
activateOtherInput = false;
FacesContext context = FacesContext.getCurrentInstance();

context.renderResponse();
}

faces-config.xml
<faces-config>
<managed-bean>
<managed-bean-name>del1</managed-bean-name>
<managed-bean-class>Personnr</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>


where is the problem? i want to access value that i have selected in combo box?
 
Kavita Tipnis
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The values are not updated until the Update Model Values Phase and value change events are fired in process validations phase, you can get 'selected option' to point to correct value in Invoke application phase(command button/link)
 
Mario Campos
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!
I have the same problem, so i'll appreciate if you could tell us the solution you find.
In my case the selectOneMenu it's linked to another so i need to get the value and process the info before submit the form.

The setters methods of my bean are not called neither my valueChangeListener method. Is there any way to force to call them?

Any help and comments will be appreciate.

Thanks and sorry for my lame english.
 
Mario Campos
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there!
I have the same problem, so i'll appreciate if you could tell us the solution you find.
In my case the selectOneMenu it's linked to another so i need to get the value and process the info before submit the form.

The setters methods of my bean are not called neither my valueChangeListener method. Is there any way to force to call them?

Any help and comments will be appreciate.

Thanks and sorry for my lame english.
 
Kavita Tipnis
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case you have to use the binding attribute and then use the SetValue to set the value of the second drop down based on a ValueChangeEvent on the first drop down.
This link will be very helpful
http://balusc.blogspot.com/2007/10/populate-child-menus.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!