selectOneMenu dropdown list Validation Error

I've been trying to get a selectOneMenu working properly for a while now. I've added a "blank" value at the top, but it seems to be causing me a lot of problems.

If I click the "Cancel" button on my page, which navigates away from the current page, I get this error: "Validation Error: Value is not valid" if I've selected "None" from the dropdown list.

Here's my code for my selectOneMenu :

<h:selectOneMenu binding="#{task.dropDownCategoryNew}" id="dropDownCategoryNew" style="position: absolute; left: 576px; top: 480px" value="#{SessionBeanTask.intSelectedValue}">

<f:selectItem itemLabel="None" itemValue="0"/>

<f:selectItems binding="#{task.dropdown1SelectItems}" id="dropdown1SelectItems" value="#{task.task_categoryDataProvider.options['task_category.id,task_category.name']}"/>

</h:selectOneMenu>

Does anyone have any idea why this might not be working?

Thanks so much

[1187 byte] By [True_Neutrala] at [2007-11-27 6:38:41]
# 1

Add immediate="true" to the cancel button. Then the values of the UIInput components will not be submitted to the backing bean (that is what the cancel button is meant for, isn't it?).

This error by the way means that the object type of "0" (String) does not fit in the object type of the value behind h:selectOneMenu (maybe you're using int or Integer?).

BalusCa at 2007-7-12 18:07:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Wow that totally worked. Thank you, I wouldn't have thought to do that so you've saved me a lot of time and hassle.

As for the object type of the selectOneMenu , I have been inserting int values into it. But how would I specify that it's an int? selectOneMenu seems to require quotation marks around the value. I wouldn't worry about this question though because it seems to work now.

Thank you

True_Neutrala at 2007-7-12 18:07:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Actually it looks like I posted too soon. The cancel button is working properly; I am now able to navigate away from the page, but I also have a "Save" button and that's causing some problems.

I can't set the "Submit" button's immediate value to true because then I'm unable to get any values from the selectOneMenu. I'm able to get any of the values except for the first one.

What do I need to do to pull values from the selectOneMenu for the submit button without getting the error "Validation Error: Value is not valid"?

True_Neutrala at 2007-7-12 18:07:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

I'll repeat myself:

> This error by the way means that the object type of "0" (String) does not fit in

> the object type of the value behind h:selectOneMenu (maybe you're using int

> or Integer?).

So you've at least 2 options: use String values only or use Integer values only.

I recommend to add the 1st item right in the backing bean while populating the selectItems.

BalusCa at 2007-7-12 18:07:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Alright I got it.

You were perfectly right, I was storing the first item as a string with the value "0". What confused me was that in the HTML source code they all were represented as:<option value="0" selected="selected">None</option>

<option value="1">Sales</option>

All I had to do was bind the selectItem to an int value like this:

<f:selectItem itemLabel="None" itemValue="#{task.intNoneValue}"/>

Thank you BalusC

True_Neutrala at 2007-7-12 18:07:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Yw.
BalusCa at 2007-7-12 18:07:28 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...