Select one Validator problem when using converter on JSF 1.2

I implement a converter to put on select one boxes witch will translate ids to complex bean types.

This convertes works fine with JSF 1.1 Myfaces implementation.

Now i am using JSF 1.2 and i am facing the folowing problem.

The converter successfully converts the Id to my bean but it returns a "Validation Error: Value is not valid"

The component has no validator associated with it.

This happen on line 136 of the UISelectOne class

// Ensure that the value matches one of the available options

boolean found = matchValue(value, new SelectItemsIterator(this));

Inside this method the component tries to compare the converted value (complex Object) with the values of the SelectItem (without passing thru the converter). The consequence is that the converted value does not math with any result on the SelectItem sub components. And raises the validator error.

newValue = getFacesContext().getApplication().

getExpressionFactory().coerceToType(item.getValue(), type);

Is this behavior correct? In my opinion faces should compare the submited value with the selectOne items value. Or doesnt compare it at all.

I really think this is a bug.

Any idea or opinions?

[1244 byte] By [lucasma] at [2007-11-27 9:08:12]
# 1

If you think about this a little bit, you will realize that your converter is unnecessary.

You created the converter because in the past, when you had to do drop down menus on web pages, you would use the id as the value of the option tags. Then on the server side you would load the bean from the database based on the id. I think you are stuck in this way of thinking a little bit.

In JSF, you give the selectOneXxx components a list of values (beans) and labels in the form of select items. The component is responsible for setting the values of the option tags in a way so that it can figure out which bean was selected on the server side. Then all you need to do is ask it which one was selected.

RaymondDeCampoa at 2007-7-12 21:45:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I undestand the model and I realy want to do that.

I d like to speed up my process and post the result of the select direct to my bean like

<h:selectOneMenu value="#{mycontroler.mybean.complexTypeAssociation}" />

I d like the component to do the search for me.

This problem can be reproduced to any type of non standard converter witch cannot be coerced with getFacesContext().getApplication().

getExpressionFactory().coerceToType(item.getValue(), type);

I my opinion this model invalidates any elaborate try to create converters

Any idea about the behavior of the component? Should I post it as a bug

lucasma at 2007-7-12 21:45:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> I undestand the model and I realy want to do that.

>

> I d like to speed up my process and post the result

> of the select direct to my bean like

>

> <h:selectOneMenu

> value="#{mycontroler.mybean.complexTypeAssociation}"

> />

>

> I d like the component to do the search for me.

>

I don't understand why this necessitates the use of a converter. If the values of your select items are the same type as mycontroler.mybean.complexTypeAssociation, what's the issue?

> This problem can be reproduced to any type of non

> standard converter witch cannot be coerced with

> getFacesContext().getApplication().

> getExpressionFactory().coerceToType(item.getValue(),

> type);

>

> I my opinion this model invalidates any elaborate try

> to create converters

>

> Any idea about the behavior of the component? Should

> I post it as a bug

It wouldn't hurt.

RaymondDeCampoa at 2007-7-12 21:45:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hey, yesterday I've had the same kind of problem.

Instead of selectOneMenu I was using selectManyCheckbox component but I was getting the same error Validation error: Value is not valid.

On the server side I have some managed bean (session scope). That bean contains a function getItems which returns an array of SelectItem elements. SelectItems are constructed with SelectItem si = new SelectItem(myObj) where myObj parameter is of type MyCustomObject.

In a JSF page I have a h:selectManyCheckbox. Value attribute of this component is set to: value="#{myBean.selectedItems}".

selectedItems is again of type MyCustomObject and because I wanted to provide multuple selection this value (selectItems) should be a list of these items. So in myBean I've had a line like this one:

private List<MyCustomObject> selectedItems;

And all I was getting when some items were selected on page and the page submitted was a list of Strings. Why? I really don't know.

Accidently I tried to replace

private List<MyCustomObject> selectedItems;

with

private MyCustomObject [] selectItems;

and everything started working as expected. I was getting selected objects in selectedItems array and all items were of type MyCustomObject.

So, to make a long story short, review your managed bean and its property which receives the value of selected item.

sekulaa at 2007-7-12 21:45:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi lucasm,

A few days ago I had the same error.

This seems to be an error in JSF1.2, i created an issue you can find it on the following page.

https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=600

Note: that I also included a way around, but you need to change the JSF api and JSF impl. I did that so if you want both jars you can send me an email.

Have a nice day,

Pieter Pareit

PieterPareita at 2007-7-12 21:45:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...