Hi Simon
THANKS YOU VERY MUCH
I always forget that this is HTML and everything must be in the html -
its my mistake - thats why I was wondered about calls to getAsString
You are right about converter
about getAsString
If value in item property has type Number or so - just return object.toString();
Again thanks!
2008/11/7 Simon Kitching <[EMAIL PROTECTED]>:
> An html select element looks like this:
> <select name="cars">
> <option value="volvo">Volvo</option>
> <option value="saab">Saab</option>
> <option value="fiat">Fiat</option>
> <option value="audi">Audi</option>
> </select>
>
> You have:
> <h:selectOneMenu value="#{...}">
> <f:selectItems value="#{anotherDataBean.selectItems}"/>
> where the getSelectItems() method returns a list of SelectItem objects
> whose string is the text you want to display, and the value is a
> ComplexProp object, right?
>
> So the renderer for the f:selectItems writes out one <option> tag for
> each item in the list. The body text for the <option> tag is taken from
> the SelectItem.label property. The SelectItem.value is a ComplexProp
> object, and so the converter.getAsString method is called to generate
> the string to write out as the "value" attribute. Obviously this occurs
> once for each item in the list.
>
> When the form is posted back, the browser will include in the posted
> form data the *string value* of whatever option was selected by the
> user. JSF calls the converter once, to map this string back to a
> ComplexProp object, then (in update-model phase) stores the resulting
> object using the "value" EL-expression of the h:selectOneMenu component.
>
> So on render, getAsString is called N times, and on postback getAsObject
> is called once.
>
> Regards, Simon
>
> Anton Gavazuk schrieb:
>> Hi dushyant,
>>
>> thanks for response -
>>
>> which value I should return in getAsString method? - actual Key
>> element or Value element? - because the selectOneItem is populated by
>> SelectItem's elements.
>>
>> and why in debug I see that getAsString method is being called for N
>> times (over all elements in binded array)?
>>
>> 2008/11/7 dushyant agarwal <[EMAIL PROTECTED]>:
>>
>>> In case of selection, the getAsObject would convert the selected value as
>>> specified and send it to BB. In getAsString() method you again have to
>>> specify some code to change the BB value into one of the values in the
>>> selectItem list, bound to the selectOneMenu component.
>>>
>>>
>>>
>>> --- On Fri, 7/11/08, Anton Gavazuk <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>> From: Anton Gavazuk <[EMAIL PROTECTED]>
>>>> Subject: Re: confused about selectOneItem and converter and data binding
>>>> To: "MyFaces Discussion" <[email protected]>
>>>> Date: Friday, 7 November, 2008, 3:41 PM
>>>> Guys,
>>>> does anyone have any idea?
>>>>
>>>> 2008/11/6 Anton Gavazuk <[EMAIL PROTECTED]>:
>>>>
>>>>> Hi all,
>>>>>
>>>>> have a problem
>>>>>
>>>>> I have the JSF Bean dataBean with property complexprop
>>>>>
>>>> - the type of
>>>>
>>>>> field is ComplexType
>>>>> I want to set an certain property to the bean via
>>>>>
>>>> selectItems, which
>>>>
>>>>> is being collected from the
>>>>>
>>>> anotherDataBean.selectItems - it returns
>>>>
>>>>> array of SelectItems.
>>>>>
>>>>> so it looks like
>>>>>
>>>>> <!--page-->
>>>>> <h:selectOneMenu id="in_property"
>>>>>
>>>> value="#{dataBean.complexprop}">
>>>>
>>>>> <f:selectItems
>>>>>
>>>> value="#{anotherDataBean.selectItems}"/>
>>>>
>>>>> <f:converter
>>>>>
>>>> converterId="geoConverter"/>
>>>>
>>>>> </h:selectOneMenu>
>>>>>
>>>>> Of course it wouldnt not work because JSF would try
>>>>>
>>>> convert the String
>>>>
>>>>> value from UI to internal dataBean.complexprop type
>>>>>
>>>> and vice versa so
>>>>
>>>>> I added the converter
>>>>> But I cannot understand how to work properly with it -
>>>>>
>>>> during the call
>>>>
>>>>> the method is being called for count =
>>>>>
>>>> selectItems.size()
>>>>
>>>>> Converter.getAsString(FacesContext facesContext,
>>>>>
>>>> UIComponent
>>>>
>>>>> uiComponent, Object o)
>>>>>
>>>>> What could be wrong?
>>>>>
>>>>> How to link together all such things?
>>>>>
>>>>>
>>> Add more friends to your messenger and enjoy! Go to
>>> http://messenger.yahoo.com/invite/
>>>
>>>
>>
>>
>
>
> --
> -- Emails in "mixed" posting style will be ignored
> -- (http://en.wikipedia.org/wiki/Posting_style)
>
>