You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Arpan Debroy <ar...@gmail.com> on 2008/05/07 18:10:22 UTC

problem

I have a JPA query like that

Query query = em.createQuery("*SELECT c.name, c.id FROM Group c ORDER BY
c.name*");
        List resultList = query.getResultList();

In Action class I have *resultList *and *GroupId *declared with getter and
setters

private List resultList ;
private long GroupId;

In JSP I have written like that :

*<s:select name="GroupId" list="resultList"  listKey="id" listValue="name"
value="%{GroupId}" />*

But nothing is displaying in my drop down box when I put listkey and
listvalue.

I will be great full if somebody tell me how to make it work.

Thanks
Arpan

Re: problem

Posted by Arpan Debroy <ar...@gmail.com>.
Without listKey and listValue, it just display the whole list.
But while displaying doesn't get selected according to the "value"
attribute.

My result list directly comes from the JPA query list(please refer the first
mail).

On Wed, May 7, 2008 at 9:51 PM, Rushikesh Thakkar <
thakkar.rushikesh@gmail.com> wrote:

> On Wed, May 7, 2008 at 6:10 PM, Arpan Debroy <ar...@gmail.com>
> wrote:
>
> >
> > But nothing is displaying in my drop down box when I put listkey and
> > listvalue.
> >
> > If it's working without using listKey and listValue, then make sure you
> have defined getters and setters for "id" and "name" attributes of
> *Result*
> (I'm assuming it as the name of list is resultList) object.
>



-- 
Thanks & Regards
Arpan Debroy

AOL Online India Private Ltd
RMZ EcoSpace Campus 1A
Outer Ring Road, Bellandur,
Bangalore - 560037
India
Mobile No :+9886006306
on-board :+91 (80) 4035 4528
E-mail : arpan.debroy@corp.aol.com

Re: problem

Posted by Rushikesh Thakkar <th...@gmail.com>.
On Wed, May 7, 2008 at 6:10 PM, Arpan Debroy <ar...@gmail.com> wrote:

>
> But nothing is displaying in my drop down box when I put listkey and
> listvalue.
>
> If it's working without using listKey and listValue, then make sure you
have defined getters and setters for "id" and "name" attributes of *Result*
(I'm assuming it as the name of list is resultList) object.

Re: problem

Posted by Arpan Debroy <ar...@gmail.com>.
Is there anybody can tell me where it's wrong in my code..
Anybody knows how to show the result list, coming from database operation,
in the drop down box of JSP directly.
Any example will be better.

On Fri, May 9, 2008 at 6:02 PM, Arpan Debroy <ar...@gmail.com> wrote:

> Hi Laurie,
>
> My JPA query is like that
>
> Query query = em.createQuery("*SELECT c.name, c.id FROM Group c ORDER BY
> c.name*");
>         List<Group> resultList = query.getResultList();
>
> My "resultList" have all the values.It has the list of rows of
> id(numerical) and name(string). "Group" entity has "id" of long type
> and "name" of String type.
>
> In Action class I have *resultList *and *groupId *declared with getter and
> setters
>
> *private List<Group> resultList ;
> private long groupId;*
>
> In JSP I have written like that :
>
> 1) If I write like this :-
> *<s:select name="groupId" list="resultList"  listKey="id"
> value="%{groupId}" />
>
> *"resultlist" is being displayed in drop down box. But the value not
> getting selected according to the "groupId" value.
> *And if I submit this, it throws error that invalid field value for the
> field "groupId".*
>
> 2) If I write like this :-
> *<s:select name="groupId" list="resultList"  listKey="id" listValue="name"value="%{groupId}" />
>
> Nothing is being displayed!!...*
>
> Do I need to write setters and getters for "id" and "name" fields in
> Action class.
> I did that too.But nothing effects.
>
> How you would like to do that?
>
>
>
> On Thu, May 8, 2008 at 9:24 PM, Laurie Harper <la...@holoweb.net> wrote:
>
> > Arpan Debroy wrote:
> >
> > > I have a JPA query like that
> > >
> > > Query query = em.createQuery("*SELECT c.name, c.id FROM Group c ORDER
> > > BY
> > > c.name*");
> > >        List resultList = query.getResultList();
> > >
> >
> > Have you verified that the query is returning a non-empty list -- i.e.
> > resultList really contains data to display? What does the result object  JPA
> > produces for an ad-hoc query like that look like? I don't recall off the top
> > of my head, but I suspect it's something like List<Map<String, Object>> or
> > possibly List<Map<String, String>>?
> >
> >  In Action class I have *resultList *and *GroupId *declared with getter
> > > and
> > > setters
> > >
> > > private List resultList ;
> > > private long GroupId;
> > >
> > > In JSP I have written like that :
> > >
> > > *<s:select name="GroupId" list="resultList"  listKey="id"
> > > listValue="name"
> > > value="%{GroupId}" />*
> > >
> >
> > That should be 'groupId' not 'GroupId'; case is important, and the
> > convention is specified by the JavaBeans spec.
> >
> >  But nothing is displaying in my drop down box when I put listkey and
> > > listvalue.
> > >
> >
> > According to your previous reply on this thread, the options are
> > rendered correctly but none is selected. Is that right? That would be
> > explained by the mis-spelled 'GroupId'. If that doesn't fix it, make sure
> > the type of the groupId property matches the type of the 'id' property in
> > the JPA result object.
> >
> > L.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> --
> Thanks & Regards
> Arpan Debroy
>
> AOL Online India Private Ltd
> RMZ EcoSpace Campus 1A
> Outer Ring Road, Bellandur,
> Bangalore - 560037
> India
> Mobile No :+9886006306
> on-board :+91 (80) 4035 4528
> E-mail : arpan.debroy@corp.aol.com
>



-- 
Thanks & Regards
Arpan Debroy

AOL Online India Private Ltd
RMZ EcoSpace Campus 1A
Outer Ring Road, Bellandur,
Bangalore - 560037
India
Mobile No :+9886006306
on-board :+91 (80) 4035 4528
E-mail : arpan.debroy@corp.aol.com

Re: problem

Posted by Arpan Debroy <ar...@gmail.com>.
Hi Laurie,

My JPA query is like that

Query query = em.createQuery("*SELECT c.name, c.id FROM Group c ORDER BY
c.name*");
        List<Group> resultList = query.getResultList();

My "resultList" have all the values.It has the list of rows of id(numerical)
and name(string). "Group" entity has "id" of long type
and "name" of String type.

In Action class I have *resultList *and *groupId *declared with getter and
setters

*private List<Group> resultList ;
private long groupId;*

In JSP I have written like that :

1) If I write like this :-
*<s:select name="groupId" list="resultList"  listKey="id" value="%{groupId}"
/>

*"resultlist" is being displayed in drop down box. But the value not getting
selected according to the "groupId" value.
*And if I submit this, it throws error that invalid field value for the
field "groupId".*

2) If I write like this :-
*<s:select name="groupId" list="resultList"  listKey="id"
listValue="name"value="%{groupId}" />

Nothing is being displayed!!...*

Do I need to write setters and getters for "id" and "name" fields in Action
class.
I did that too.But nothing effects.

How you would like to do that?


On Thu, May 8, 2008 at 9:24 PM, Laurie Harper <la...@holoweb.net> wrote:

> Arpan Debroy wrote:
>
>> I have a JPA query like that
>>
>> Query query = em.createQuery("*SELECT c.name, c.id FROM Group c ORDER BY
>> c.name*");
>>        List resultList = query.getResultList();
>>
>
> Have you verified that the query is returning a non-empty list -- i.e.
> resultList really contains data to display? What does the result object  JPA
> produces for an ad-hoc query like that look like? I don't recall off the top
> of my head, but I suspect it's something like List<Map<String, Object>> or
> possibly List<Map<String, String>>?
>
>  In Action class I have *resultList *and *GroupId *declared with getter and
>> setters
>>
>> private List resultList ;
>> private long GroupId;
>>
>> In JSP I have written like that :
>>
>> *<s:select name="GroupId" list="resultList"  listKey="id" listValue="name"
>> value="%{GroupId}" />*
>>
>
> That should be 'groupId' not 'GroupId'; case is important, and the
> convention is specified by the JavaBeans spec.
>
>  But nothing is displaying in my drop down box when I put listkey and
>> listvalue.
>>
>
> According to your previous reply on this thread, the options are rendered
> correctly but none is selected. Is that right? That would be explained by
> the mis-spelled 'GroupId'. If that doesn't fix it, make sure the type of the
> groupId property matches the type of the 'id' property in the JPA result
> object.
>
> L.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Thanks & Regards
Arpan Debroy

AOL Online India Private Ltd
RMZ EcoSpace Campus 1A
Outer Ring Road, Bellandur,
Bangalore - 560037
India
Mobile No :+9886006306
on-board :+91 (80) 4035 4528
E-mail : arpan.debroy@corp.aol.com

Re: problem

Posted by Laurie Harper <la...@holoweb.net>.
Arpan Debroy wrote:
> I have a JPA query like that
> 
> Query query = em.createQuery("*SELECT c.name, c.id FROM Group c ORDER BY
> c.name*");
>         List resultList = query.getResultList();

Have you verified that the query is returning a non-empty list -- i.e. 
resultList really contains data to display? What does the result object 
  JPA produces for an ad-hoc query like that look like? I don't recall 
off the top of my head, but I suspect it's something like 
List<Map<String, Object>> or possibly List<Map<String, String>>?

> In Action class I have *resultList *and *GroupId *declared with getter and
> setters
> 
> private List resultList ;
> private long GroupId;
> 
> In JSP I have written like that :
> 
> *<s:select name="GroupId" list="resultList"  listKey="id" listValue="name"
> value="%{GroupId}" />*

That should be 'groupId' not 'GroupId'; case is important, and the 
convention is specified by the JavaBeans spec.

> But nothing is displaying in my drop down box when I put listkey and
> listvalue.

According to your previous reply on this thread, the options are 
rendered correctly but none is selected. Is that right? That would be 
explained by the mis-spelled 'GroupId'. If that doesn't fix it, make 
sure the type of the groupId property matches the type of the 'id' 
property in the JPA result object.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org