You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Damar Thapa <th...@gmail.com> on 2006/10/31 13:32:40 UTC

General JSF question -- Class object!

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

Re: General JSF question -- Class object!

Posted by Damar Thapa <th...@gmail.com>.
Thanks, indeed.

Damar

On 10/31/06, David Delbecq <de...@oma.be> wrote:
> 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 <de...@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
> >> >
> >>
> >>
> >
> >
>
>


-- 
With regards,

Damar Thapa

Re: General JSF question -- Class object!

Posted by David Delbecq <de...@oma.be>.
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 <de...@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
>> >
>>
>>
>
>


Re: General JSF question -- Class object!

Posted by Damar Thapa <th...@gmail.com>.
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 <de...@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
> >
>
>


-- 
With regards,

Damar Thapa

Re: General JSF question -- Class object!

Posted by David Delbecq <de...@oma.be>.
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
>


Re: General JSF question -- Class object!

Posted by Rene Guenther <in...@innflow.com>.
It would maybe help to initialize firstChoice:
Course firstChoice = new Course()

JSF tries to set the value title of firstChoice by 
calling:

firstChoice.setTitle(title)

Of course this is not possible if firstChoice == null. 
Under these circumstances you get the error which you 
described. If firstChoice != null you can save the state 
of firstChoice with the saveState tag <t:saveState 
value="#{applicant.firstChoice}" />

Regards
René

On Tue, 31 Oct 2006 22:42:23 +0800
  "Damar Thapa" <th...@gmail.com> wrote:
> Hi Rene,
> 
> Possibly, it is null. I am still getting ""firstChoice": 
>Error during
> model data update." error.  I can add two more attribues 
>of type
> String to hold firstChoice and secondChoice in Applicant 
>class, but as
> a matter of interest and learning, how it works in JSF?
> 
> Thanks,
> 
> Damar
> 
> 
> 
> 
> 
> 
> n 10/31/06, Rene Guenther <in...@innflow.com> 
>wrote:
>> Is firstChoice != null?
>>
>> Regards
>> Rene
>>
>> On Tue, 31 Oct 2006 20:32:40 +0800
>>  "Damar Thapa" <th...@gmail.com> wrote:
>> > 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
>>
>>
> 
> 
> -- 
> With regards,
> 
> Damar Thapa


Re: General JSF question -- Class object!

Posted by Damar Thapa <th...@gmail.com>.
Hi Rene,

Possibly, it is null. I am still getting ""firstChoice": Error during
model data update." error.  I can add two more attribues of type
String to hold firstChoice and secondChoice in Applicant class, but as
a matter of interest and learning, how it works in JSF?

Thanks,

Damar






n 10/31/06, Rene Guenther <in...@innflow.com> wrote:
> Is firstChoice != null?
>
> Regards
> Rene
>
> On Tue, 31 Oct 2006 20:32:40 +0800
>  "Damar Thapa" <th...@gmail.com> wrote:
> > 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
>
>


-- 
With regards,

Damar Thapa

Re: General JSF question -- Class object!

Posted by Rene Guenther <in...@innflow.com>.
Is firstChoice != null?

Regards
Rene

On Tue, 31 Oct 2006 20:32:40 +0800
  "Damar Thapa" <th...@gmail.com> wrote:
> 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