why is dropdown menu being validated?

Does anyone have an idea why a select one menu would ever be validated? And how do you get around the validation? Or better yet - what would be failing? It's string key, string value. I don't get it. Please help.
[221 byte] By [Tammy_Ea] at [2007-11-15]
# 1

The h:selectOneMenu is not validated by default. I guess you're occurring conversion errors? This will usually occur if the object type of the select items does not fit in the selected value. For example, if you're supplying a List of Integers while the value expects a String, then you will get conversion errors. A workaround is to change the object types accordingly, or to create a custom converter -which is meaningless.

BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hi BalusC,

I think you are getting confused with my other post regarding conversion errors on radio button. (Which I'm still having trouble with, BTW. Can we still talk about that on the other post? That'd be great.)

The "Validation Error: Value Not Valid" error that occurs on a dropdown menu seems to be common. I duplicated the error using an example from a book I was reading, by submitting the form, and then hitting F5 to refresh. So it has to do with after a submit, coming back and trying to reload the page you were on.

It's not like the code is doing anything funky. You have a List menuList = new ArrayList(); and then set it with Strings. menuList..add(new SelectItem("0", "First Option", "")); etc.

This is very painful. I don't know what to do.

Tammy_Ea at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3

Which JSF version are you using then? I've tested it here with JSF 1.1_02 as well as 1.2_04 and I can't reproduce the problem.

JSF<h:form>

<h:selectOneMenu value="#{myBean.selectedItem}">

<f:selectItems value="#{myBean.selectItems}" />

</h:selectOneMenu>

<h:commandButton value="submit" action="#{myBean.action}" />

</h:form>

MyBeanprivate String selectedItem; // + getter + setter

private List selectItems;

public void action() {

System.out.println("Selected item: " + selectedItem);

}

public List getSelectItems() {

if (selectItems == null) {

selectItems = new ArrayList();

selectItems.add(new SelectItem("value1", "label1"));

selectItems.add(new SelectItem("value2", "label2"));

selectItems.add(new SelectItem("value3", "label3"));

}

return selectItems;

}

BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4
Here's how you reproduce the error:1. Click submit, and navigate to another page.2. On the second page, have a link to go back to the original page.3. Once the original page loads, you will have the error. Guaranteed.
Tammy_Ea at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 5
I created a 2nd page and placed outputLinks to each other and tried to reproduce. No problem. I've tested with the managed bean in the request as well as session scope.
BalusCa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 6
I am building an app using the code you provided. (Thanks!) I can't get the action() method to run... when I debug it selectedItem comes back null.
Tammy_Ea at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 7

Hi BalusC,

I have similar problem, you belive or not...

Anyways.. I just want to ask one question, What is the JSF version in IBM WebSphere Integration Developer 6.0.1? I guess it's JSF bug of older version.

- Will be thankful if you provide the information.

- If you want i can send you a small sample project and JSF jars which generates this error., so this error is also comming with Radio, Checkbox and Combobox.

- I have played with each possible combination of "immediate=true/false" on combo as well Command Button/ Command Link.

- I have written Custom validators as well Custom Converter to debug same.. Following is the debug log for same, which might give you some idea(sorry not posting code in hurry).

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO Pagecode Constructed....

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO onPagePost()

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO Combo value : null

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO onPagePost() Over

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO MyConverter(Object) Component : javax.faces.component.html.HtmlSelectOneMenu@318816e6

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO MyConverter(Object) getAsObject: 1

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO My validate() Called...

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO UIComponent: javax.faces.component.html.HtmlSelectOneMenu@318816e6

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO Object value : 1

[5/1/07 2:58:18:844 IST] 0000007d SystemOutO It's Combo !!!, I am not generating any Exception here...

[5/1/07 2:58:18:875 IST] 0000007d jsfE com.sun.faces.context.FacesContextImpl addMessage Adding Message[sourceId=form1:cmbItems,summary=Validation Error)[5/1/07 2:58:18:891 IST] 0000007d SystemOutO handleCmbItemsValueChange : -1

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO handleCmbItemsValueChange : 1

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO onPageLoadBegin()

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO Combo value : null

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO onPageLoadBegin... over

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO MyConverter(String) Component : javax.faces.component.html.HtmlSelectOneMenu@318816e6

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO MyConverter(String) getAsString: -1

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO MyConverter(String) Component : javax.faces.component.html.HtmlSelectOneMenu@318816e6

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO MyConverter(String) getAsString: 1

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO MyConverter(String) Component : javax.faces.component.html.HtmlSelectOneMenu@318816e6

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO MyConverter(String) getAsString: 2

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO onPageLoadEnd..

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO Validator count : 1

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO -> Validator[0] : pagecode.mit.InputValidator@4eef16e6

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO Converter : pagecode.mit.InputConverter@4b0c16e6

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO Combo value : null

[5/1/07 2:58:18:891 IST] 0000007d SystemOutO onPageLoadEnd.. Over

JanakMewadaa at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 8

JanakMewada,

I am running Websphere 6.0 as well. If you find the answer to your question, please post it here. I will do the same. I am still trying to track down this bug.

On another post, BalusC suggested that I upgrade to JSF 1.1.02. I did what he said, but WebSphere totally didn't like it.

Again, if you find the answer, please post here. If I find the answer, I will post here.

Thank you.

Tammy_Ea at 2007-7-12 > top of java,Enterprise & Remote Computing,Web Tier APIs...