File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes SelectOneMenu value Not getting reset    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "SelectOneMenu value Not getting reset    " Watch "SelectOneMenu value Not getting reset    " New topic
Author

SelectOneMenu value Not getting reset

Sreekanth Kalakanti
Greenhorn

Joined: Sep 09, 2009
Posts: 12
I developed a JSF1.2 Application and my form looks like contains a Country SelectOneMenu and MobileField as below


<h:form>
<h:selectOneMenu value="#{mybean.selectedCountry}" required="true" >

<f:selectItem itemName="selectOne" itemValue=""/>
<f:selectItems value="#{mybean.countriesMap}"/>

</h:selectOneMenu>

<h:inputText binding="#{mybean.mobileNo}"></h:inputText>

<h:commandButton id="next" value="NEXT" action="#{regform.next}" />
</h:form>

And My Bean Scope is Session and this is mandatory for my Requirement.


My Actions:

1) Select a Country value like USA of CountrySelectOneMenu and Click Submit Button

2) Now again Select the 'selectOne' of CountrySelectOneMenu and Click Submit Then the
Previous Submitted Value "USA" is displayed as selected and a error message is Showing
'Country is Required' as this field property is reqired="true" .


So Previous Selected value is getting displayed even i select default option 'selectOne' and
displaying error Message.

I must get the default 'selectOne' Option with an error message but not the previous submitted value
to be set for SelectoneMenu .


Can you suggest a Solution for my Problem?


Thanks & Regards
K.Sreekanth
Brajendra Mathema
Ranch Hand

Joined: Jun 02, 2009
Posts: 39
hi

can you check your source code in jsf page and find out what is the corresponding value shown in the select one menu ..

is it empty or it has value USA


brajen

Sreekanth Kalakanti
Greenhorn

Joined: Sep 09, 2009
Posts: 12
brajen mathema wrote:hi

can you check your source code in jsf page and find out what is the corresponding value shown in the select one menu ..

is it empty or it has value USA


brajen


Hi brajen,

The Value for SelectOnemenu default option '--SelectOne--' is ""(empty String Only) and my code looks Like:

<h:selectOneMenu class="select_field" id="country" label="#{labels.countryCode}"
value="#{countryCountroller.selectedCountry}" required="true" >
<f:selectItem itemLabel="--SelectOne--" itemvalue="" />
<f:selectItems value="#{countryCountroller.countryItems}"/>
</h:selectOneMenu>


Brajendra Mathema
Ranch Hand

Joined: Jun 02, 2009
Posts: 39
hi

since your managed bean is in session whenever you select a value and submit that value remains in session hence selected

when you reselect the select country option with empty value since the value is emtpy error message is displayed but as the value=#{attribute} is already selected in previous submit and is in session , you got that value selected when the page is rendered


to avoid this you can clear the value value=#{attriubute} in managed bean action methos as this:

public String test(){

...............................

some process
.................................
selectedCountry = "";
return "pageNav";
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SelectOneMenu value Not getting reset