myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Delbecq <de...@oma.be>
Subject Re: General JSF question -- Class object!
Date Tue, 31 Oct 2006 13:29:56 GMT
This all depends on what you want to do

Do you want to 'set the title of firstChoice'? then you map to
#{applicant.firstChoice.title}

do you want to 'set the firstChoice'? then you map to
#{applicant.firstChoice}

The SelectItem[] is use to select amongst a list of possible values. You
don't have to care how they are wired at html level, You just provide a
list of SelectItem[] object which have a visual label  (type String), a
description (type String, never used) and a Value (type Object). So you
can put in value whatever you want, JSF will take care that when an item
is selected for selectbox, the backing bean will be update with
something like setFirstChoice(selectedItem.getValue()).

Btw, sorry, this is not h:selectOne but h:selectOneMenu :D

Damar Thapa a écrit :
> Hi David,
>
> Thanks for your prompt reply.
>
> I am trying similar to your first suggestion.  In your case, I
> suppose, firstChoice has to be type String, but I made firstChoice as
> type Course, where Course  has several properties and one of them is
> title.  So I am trying to do similary to:
>
> <h:selectOne id="firstChoice" value ="#{applicant.firstChoice.title}">
>    <f:selectItems value="#{school.availableCourses}"/>
> </h:selectOne>
>
> Basically, trying to bind value to #{applicant.firstChoice.title}
> instead.  Is it possible?
>
> Thanks,
>
> Damar
>
>
>
> On 10/31/06, David Delbecq <delbd@oma.be> wrote:
>> Hi,
>>
>> Am a little confused by your explaination. I bet you are transforming a
>> textfield String (the course title) somehow in a Course object later.
>>
>> I have 2 suggestions:
>>
>> The first it to replace you textfield with a combo box, like this
>>
>> <h:selectOne id="firstChoice" value ="#{applicant.firstChoice}">
>>
>>    <f:selectItems value="#{school.availableCourses}"/>
>>
>> </h:selectOne>
>>
>> with your school bean having something like this
>>
>> public SelectItems[] getAvailableCourses(){
>>
>>     ...
>>
>> }
>>
>>
>> The second way to go is to use a converter
>>
>> <h:inputText id="firstChoice" value ="#{applicant.firstChoice}">
>>
>>    <f:converter converterId="my.custom.Converter"/>
>>
>> </h:inputText>
>>
>> with the converter define in you faces-config.xml:
>>
>> <converter>
>>
>>  <converter-id>my.custom.Converter</converter-id>
>>
>>  <converter-class>path.to.my.custom.CourseConverter</converter-class>
>>
>> </converter>
>>
>> your converter being an implementation of
>>
>> javax.faces.convert.Converter
>>
>>
>> pointer: http://www-128.ibm.com/developerworks/java/library/j-jsf3/
>>
>> Damar Thapa a écrit :
>> > Hi,
>> >
>> > I have following classes:
>> >
>> > Class Course(
>> >     String title,
>> >     String startDate.
>> >     …..
>> >     ….
>> >
>> > }
>> >
>> > and
>> >
>> > Class Apply{
>> >
>> > String studnetName;
>> > Course firstChoice;
>> > .....
>> > …….
>> > …..
>> > }
>> >
>> > In the apply form (page), I havae a field to accept course title from
>> > the applicant  ie <h:inputText id="firstChoice"
>> > value="#{applicant.firstChoice.title}"/>. Since title is unique, I can
>> > retrieve Course object for firstChoice properties later before saving
>> > Apply object. But, I am getting ""firstChoice": Error during model
>> > data update." error on "#{applicant.firstChoice.title} . Can somebody
>> > on the list point me what am I missing?
>> >
>> > Any pointers would be highly appreciated.
>> >
>> > Thanks,
>> >
>> > Damar
>> >
>>
>>
>
>


Mime
View raw message