You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Wiebke Henrici <wh...@cebenetwork.com> on 2007/03/14 15:40:07 UTC

Problem with t:selectItems

Hi,

I want to use t:selectItems within a t:selectManyCheckbox. My problem is
that I always get a validation error saying that the value is not valid.

My JSP:
<t:selectManyCheckbox id="sensor_access"
value="#{sensorBacker.selectedItems}" layout="pageDirection"
layoutWidth="3">
<t:selectItems value="#{sensorBacker.groups}" var="Group"
itemLabel="#{Group.name}" itemValue="#{Group.id}" />
</t:selectManyCheckbox>

The definition of sensorBacker.selectedItems and sensorBacker.groups:
private Collection<GroupBean> groups;
private ArrayList<GroupBean> selectedItems = new ArrayList<GroupBean>();

When I load my JSP, I fill groups with: 
groups = remoteReader.readAllGroups();
This works alright, there is one checkbox per group.

I am not really sure what to use as itemValue in the t:selectItems. I
tried with "Group", this didn't work either and gave the same error.
I tried with Group.name, this gave no validation error but a
ClassCastException in my backing when I tried to do a loop like that:

for (GroupBean group: selectedItems){
(some debugging output here)
}

Can anyone tell me what kind of value has to be there for itemValue? Or
what else am I doing wrong?

Wiebke

Re: Problem with t:selectItems

Posted by Gerald Müllan <bi...@gmail.com>.
Hi,

sure, you only have to initialize the selectedItems Array with the
corresponding Goups/Ids which have to be checked.

cheers,

Gerald

On 3/15/07, Wiebke Henrici <wh...@cebenetwork.com> wrote:
> Hi,
>
> thank you very much for this answer. It works now :-)
> Now I have one more question: When I display the checkboxes, I would like to have the groups, my object is associated with, checked. Right now, I read simply all groups from the database for the checkboxes, but it would be nice if the user could see which groups already belong to the object. Is there any possibility to do this?
>
> Wiebke
>
> > -----Ursprüngliche Nachricht-----
> > Von: Gerald Müllan [mailto:bierbrauen@gmail.com]
> > Gesendet: Mittwoch, 14. März 2007 16:55
> > An: MyFaces Discussion
> > Betreff: Re: Problem with t:selectItems
> >
> > Hi,
> >
> > this component is a nice counterpart to returning back a list of
> > SelectItems in your model bean code.
> >
> > So, what you actually need is a label and a value for each entry in
> > the list, which in turn is exactly the same as filling a list of
> > SelectItems.
> >
> > You are right with your first try when writing
> > itemValue="#{Group.id}". The itemValue must be a unique identifier for
> > mapping the value to a group object after the response in order to
> > know which entry (or entries) has (have) been choosen.
> >
> > So, the expected type given in the value field (selectedItems in your
> > case) has to be the same as the itemValue type. E.g. Group.id is a
> > Long, so selectedItems has to be of type Long[]. In case of a
> > SelectOne component it would be simply a Long.
> >
> > Just generate setters and getters for the value field, and this should
> > do the trick.
> >
> > Hope this helps,
> >
> > cheers - Gerald
> >
> > On 3/14/07, Wiebke Henrici <wh...@cebenetwork.com> wrote:
> > > Hi,
> > >
> > > I want to use t:selectItems within a t:selectManyCheckbox. My problem is
> > > that I always get a validation error saying that the value is not valid.
> > >
> > > My JSP:
> > > <t:selectManyCheckbox id="sensor_access"
> > > value="#{sensorBacker.selectedItems}" layout="pageDirection"
> > > layoutWidth="3">
> > > <t:selectItems value="#{sensorBacker.groups}" var="Group"
> > > itemLabel="#{Group.name}" itemValue="#{Group.id}" />
> > > </t:selectManyCheckbox>
> > >
> > > The definition of sensorBacker.selectedItems and sensorBacker.groups:
> > > private Collection<GroupBean> groups;
> > > private ArrayList<GroupBean> selectedItems = new ArrayList<GroupBean>();
> > >
> > > When I load my JSP, I fill groups with:
> > > groups = remoteReader.readAllGroups();
> > > This works alright, there is one checkbox per group.
> > >
> > > I am not really sure what to use as itemValue in the t:selectItems. I
> > > tried with "Group", this didn't work either and gave the same error.
> > > I tried with Group.name, this gave no validation error but a
> > > ClassCastException in my backing when I tried to do a loop like that:
> > >
> > > for (GroupBean group: selectedItems){
> > > (some debugging output here)
> > > }
> > >
> > > Can anyone tell me what kind of value has to be there for itemValue? Or
> > > what else am I doing wrong?
> > >
> > > Wiebke
> > >
> >
> >
> > --
> > http://www.irian.at
> >
> > Your JSF powerhouse -
> > JSF Consulting, Development and
> > Courses in English and German
> >
> > Professional Support for Apache MyFaces
>


-- 
http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

AW: Problem with t:selectItems

Posted by Wiebke Henrici <wh...@cebenetwork.com>.
Hi,

thank you very much for this answer. It works now :-) 
Now I have one more question: When I display the checkboxes, I would like to have the groups, my object is associated with, checked. Right now, I read simply all groups from the database for the checkboxes, but it would be nice if the user could see which groups already belong to the object. Is there any possibility to do this?

Wiebke

> -----Ursprüngliche Nachricht-----
> Von: Gerald Müllan [mailto:bierbrauen@gmail.com]
> Gesendet: Mittwoch, 14. März 2007 16:55
> An: MyFaces Discussion
> Betreff: Re: Problem with t:selectItems
> 
> Hi,
> 
> this component is a nice counterpart to returning back a list of
> SelectItems in your model bean code.
> 
> So, what you actually need is a label and a value for each entry in
> the list, which in turn is exactly the same as filling a list of
> SelectItems.
> 
> You are right with your first try when writing
> itemValue="#{Group.id}". The itemValue must be a unique identifier for
> mapping the value to a group object after the response in order to
> know which entry (or entries) has (have) been choosen.
> 
> So, the expected type given in the value field (selectedItems in your
> case) has to be the same as the itemValue type. E.g. Group.id is a
> Long, so selectedItems has to be of type Long[]. In case of a
> SelectOne component it would be simply a Long.
> 
> Just generate setters and getters for the value field, and this should
> do the trick.
> 
> Hope this helps,
> 
> cheers - Gerald
> 
> On 3/14/07, Wiebke Henrici <wh...@cebenetwork.com> wrote:
> > Hi,
> >
> > I want to use t:selectItems within a t:selectManyCheckbox. My problem is
> > that I always get a validation error saying that the value is not valid.
> >
> > My JSP:
> > <t:selectManyCheckbox id="sensor_access"
> > value="#{sensorBacker.selectedItems}" layout="pageDirection"
> > layoutWidth="3">
> > <t:selectItems value="#{sensorBacker.groups}" var="Group"
> > itemLabel="#{Group.name}" itemValue="#{Group.id}" />
> > </t:selectManyCheckbox>
> >
> > The definition of sensorBacker.selectedItems and sensorBacker.groups:
> > private Collection<GroupBean> groups;
> > private ArrayList<GroupBean> selectedItems = new ArrayList<GroupBean>();
> >
> > When I load my JSP, I fill groups with:
> > groups = remoteReader.readAllGroups();
> > This works alright, there is one checkbox per group.
> >
> > I am not really sure what to use as itemValue in the t:selectItems. I
> > tried with "Group", this didn't work either and gave the same error.
> > I tried with Group.name, this gave no validation error but a
> > ClassCastException in my backing when I tried to do a loop like that:
> >
> > for (GroupBean group: selectedItems){
> > (some debugging output here)
> > }
> >
> > Can anyone tell me what kind of value has to be there for itemValue? Or
> > what else am I doing wrong?
> >
> > Wiebke
> >
> 
> 
> --
> http://www.irian.at
> 
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
> 
> Professional Support for Apache MyFaces

Re: Problem with t:selectItems

Posted by Gerald Müllan <bi...@gmail.com>.
Hi,

this component is a nice counterpart to returning back a list of
SelectItems in your model bean code.

So, what you actually need is a label and a value for each entry in
the list, which in turn is exactly the same as filling a list of
SelectItems.

You are right with your first try when writing
itemValue="#{Group.id}". The itemValue must be a unique identifier for
mapping the value to a group object after the response in order to
know which entry (or entries) has (have) been choosen.

So, the expected type given in the value field (selectedItems in your
case) has to be the same as the itemValue type. E.g. Group.id is a
Long, so selectedItems has to be of type Long[]. In case of a
SelectOne component it would be simply a Long.

Just generate setters and getters for the value field, and this should
do the trick.

Hope this helps,

cheers - Gerald

On 3/14/07, Wiebke Henrici <wh...@cebenetwork.com> wrote:
> Hi,
>
> I want to use t:selectItems within a t:selectManyCheckbox. My problem is
> that I always get a validation error saying that the value is not valid.
>
> My JSP:
> <t:selectManyCheckbox id="sensor_access"
> value="#{sensorBacker.selectedItems}" layout="pageDirection"
> layoutWidth="3">
> <t:selectItems value="#{sensorBacker.groups}" var="Group"
> itemLabel="#{Group.name}" itemValue="#{Group.id}" />
> </t:selectManyCheckbox>
>
> The definition of sensorBacker.selectedItems and sensorBacker.groups:
> private Collection<GroupBean> groups;
> private ArrayList<GroupBean> selectedItems = new ArrayList<GroupBean>();
>
> When I load my JSP, I fill groups with:
> groups = remoteReader.readAllGroups();
> This works alright, there is one checkbox per group.
>
> I am not really sure what to use as itemValue in the t:selectItems. I
> tried with "Group", this didn't work either and gave the same error.
> I tried with Group.name, this gave no validation error but a
> ClassCastException in my backing when I tried to do a loop like that:
>
> for (GroupBean group: selectedItems){
> (some debugging output here)
> }
>
> Can anyone tell me what kind of value has to be there for itemValue? Or
> what else am I doing wrong?
>
> Wiebke
>


-- 
http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: Problem with t:selectItems

Posted by Mike Kienenberger <mk...@gmail.com>.
Typically, I'd use "Group" as the itemValue.  However, you probably
need to have a Group converter registered by Class (or specified
explicitly in your page code).

Contrary to what Gerald stated, I don't think there's any requirement
that itemValue must be unique.

On 3/14/07, Wiebke Henrici <wh...@cebenetwork.com> wrote:
> Hi,
>
> I want to use t:selectItems within a t:selectManyCheckbox. My problem is
> that I always get a validation error saying that the value is not valid.
>
> My JSP:
> <t:selectManyCheckbox id="sensor_access"
> value="#{sensorBacker.selectedItems}" layout="pageDirection"
> layoutWidth="3">
> <t:selectItems value="#{sensorBacker.groups}" var="Group"
> itemLabel="#{Group.name}" itemValue="#{Group.id}" />
> </t:selectManyCheckbox>
>
> The definition of sensorBacker.selectedItems and sensorBacker.groups:
> private Collection<GroupBean> groups;
> private ArrayList<GroupBean> selectedItems = new ArrayList<GroupBean>();
>
> When I load my JSP, I fill groups with:
> groups = remoteReader.readAllGroups();
> This works alright, there is one checkbox per group.
>
> I am not really sure what to use as itemValue in the t:selectItems. I
> tried with "Group", this didn't work either and gave the same error.
> I tried with Group.name, this gave no validation error but a
> ClassCastException in my backing when I tried to do a loop like that:
>
> for (GroupBean group: selectedItems){
> (some debugging output here)
> }
>
> Can anyone tell me what kind of value has to be there for itemValue? Or
> what else am I doing wrong?
>
> Wiebke
>