You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by ma...@yahoo.com on 2007/04/06 23:01:19 UTC

Accesssing a bean from a jsp without struts tags

I have a bean that is set in an action class. I can access it using 
struts tag, but what do I do if I need to access it from somewhere else ?

for example, if I need to access it from a list iterator.

Thanks.



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


Re: Accesssing a bean from a jsp without struts tags

Posted by Dave Newton <ne...@yahoo.com>.
--- mansour77@yahoo.com wrote:
> Can you give an example please. I am newbie  and it
> sounds like greek to me. my original question was
how
> to retrieve an object using useBean from struts?

Your original question was how to access a bean from
something like an iterator; the quick answer is you
don't do anything differently (JSP 2.0, if < 2.0 then
use <c:out.../> in the loop body), so if you had a
list of beans "myBeans" each with a property "foo":

<c:forEach items="${myBeans}" var="b">
  ${b.foo}
</c:forEach>

Note that some people don't like to fix idioms in
their JSP and would prefer to use <s:iterator.../>
etc. Personally, I don't mind using ${...} if JSP 2.0+
since it makes more sense to me than typing out
<s:property.../> all over, but that might just be me.
I just really hate typing when it's pointless. (...and
I like pointers when they're typeless. Sorry.)

Your *second* question was dealing with the following
error:

> <dg:dataGrid items="${accountBean.invoices}" 
>              var="inv" 
>              name="datagrid1">
> [...]
> According to TLD or attribute directive in tag file,

> attribute items does not accept any expressions

I have no idea what that tag library is or what its
TLD looks like etc. but my impression is that the
error isn't telling you you're exposing your beans
improperly (like on a playground), but that according
to its TLD you're providing it (the tag) something it
is not expecting.

Are you using a JSP 2.0 container?

d.



 
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time 
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news

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


Re: Accesssing a bean from a jsp without struts tags

Posted by ma...@yahoo.com.
Dave Newton wrote:
> --- joey <re...@gmail.com> wrote:
>   
>> struts set action object in valuestack,so you can't
>> refere to it in your tag.
>>     
>
> Values exposed to OGNL from an Action are also
> available through JSP EL due to the
> StrutsRequestWrapper. getAttribute calls are elegated
> to the OGNL stack if the atribute isn't found in the
> request.
>
> d.
>
>   

Can you give an example please. I am newbie  and it sounds like greek to me.
my original question was how to retrieve an object using useBean from 
struts?
Thank you.

>
>  
> ____________________________________________________________________________________
> TV dinner still cooling? 
> Check out "Tonight's Picks" on Yahoo! TV.
> http://tv.yahoo.com/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>   


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


Re: Accesssing a bean from a jsp without struts tags

Posted by Dave Newton <ne...@yahoo.com>.
--- joey <re...@gmail.com> wrote:
> struts set action object in valuestack,so you can't
> refere to it in your tag.

Values exposed to OGNL from an Action are also
available through JSP EL due to the
StrutsRequestWrapper. getAttribute calls are elegated
to the OGNL stack if the atribute isn't found in the
request.

d.



 
____________________________________________________________________________________
TV dinner still cooling? 
Check out "Tonight's Picks" on Yahoo! TV.
http://tv.yahoo.com/

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


Re: Accesssing a bean from a jsp without struts tags

Posted by joey <re...@gmail.com>.
struts set action object in valuestack,so you can't refere to it in your
tag.
I just manually set it in request scope.
btw.Maybe someone know better method.:)

On 4/7/07, mansour77@yahoo.com <ma...@yahoo.com> wrote:
>
> joey wrote:
> > add request.setAttribute("invoices",accountBean.getInvoices()) in your
> > action execute method.
> > On 4/7/07, mansour77@yahoo.com <ma...@yahoo.com> wrote:
> >
>
> I thought that was set automatically by struts through the getters !
>
>
> >> OK, let me include more details, may be someone will understand what I
> >> am talking about.
> >> I have a list that belongs to  a Bean that's wet in an action class.
> >>
> >> public AccountBean getAccountBean() {
> >>     return accountBean;
> >> }
> >>
> >> AccountBean has an ArrayList<Invoices>  calles invoices.
> >>
> >> now im my jsp, I need to display this in a datagrid, I am doing this,
> >> but it's not working:
> >>
> >>
> >>
> >> <dg:dataGrid items="${accountBean.invoices}" var="inv"
> >> name="datagrid1" >
> >> <columns>
> >> <column>
> >> <header value="Name" />
> >> <item value="${inv.statementDate}" />
> >> </column>
> >> </dg:dataGrid>
> >>
> >>
> >> that's the error  I am getting:
> >>
> >> According to TLD or attribute directive in tag file, attribute items
> >> does
> >> not accept any expressions
> >>         org.apache.struts2.dispatcher.Dispatcher.serviceAction(
> >> Dispatcher.java:518)
> >>         org.apache.struts2.dispatcher.FilterDispatcher.doFilter(
> >> FilterDispatcher.java:421)
> >>
> >>
> >> Any Idea ??
> >>
> >>
> >>
> >>
> >> mansour77@yahoo.com wrote:
> >> > I have a bean that is set in an action class. I can access it using
> >> > struts tag, but what do I do if I need to access it from somewhere
> >> else
> >> ?
> >> >
> >> > for example, if I need to access it from a list iterator.
> >> >
> >> > Thanks.
> >> >
> >> >
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> > For additional commands, e-mail: user-help@struts.apache.org
> >> >
> >> >
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Accesssing a bean from a jsp without struts tags

Posted by joey <re...@gmail.com>.
just implement interface "ServletRequestAware" and
ensure you has config "servlet-config" interceptor in
your action mapper.

regards
joey




On 4/7/07, mansour77@yahoo.com <ma...@yahoo.com> wrote:
>
> mansour77@yahoo.com wrote:
> > joey wrote:
> >> add request.setAttribute("invoices",accountBean.getInvoices()) in your
> >> action execute method.
>
> How do I do this is struts 2. I couldn't find any way to get my hand on
> the Request object.
>
> >> On 4/7/07, mansour77@yahoo.com <ma...@yahoo.com> wrote:
> >>
> >
> > I thought that was set automatically by struts through the getters !
> >
> >
> >>> OK, let me include more details, may be someone will understand what I
> >>> am talking about.
> >>> I have a list that belongs to  a Bean that's wet in an action class.
> >>>
> >>> public AccountBean getAccountBean() {
> >>>     return accountBean;
> >>> }
> >>>
> >>> AccountBean has an ArrayList<Invoices>  calles invoices.
> >>>
> >>> now im my jsp, I need to display this in a datagrid, I am doing this,
> >>> but it's not working:
> >>>
> >>>
> >>>
> >>> <dg:dataGrid items="${accountBean.invoices}" var="inv"
> >>> name="datagrid1" >
> >>> <columns>
> >>> <column>
> >>> <header value="Name" />
> >>> <item value="${inv.statementDate}" />
> >>> </column>
> >>> </dg:dataGrid>
> >>>
> >>>
> >>> that's the error  I am getting:
> >>>
> >>> According to TLD or attribute directive in tag file, attribute items
> >>> does
> >>> not accept any expressions
> >>>         org.apache.struts2.dispatcher.Dispatcher.serviceAction(
> >>> Dispatcher.java:518)
> >>>         org.apache.struts2.dispatcher.FilterDispatcher.doFilter(
> >>> FilterDispatcher.java:421)
> >>>
> >>>
> >>> Any Idea ??
> >>>
> >>>
> >>>
> >>>
> >>> mansour77@yahoo.com wrote:
> >>> > I have a bean that is set in an action class. I can access it using
> >>> > struts tag, but what do I do if I need to access it from somewhere
> >>> else
> >>> ?
> >>> >
> >>> > for example, if I need to access it from a list iterator.
> >>> >
> >>> > Thanks.
> >>> >
> >>> >
> >>> >
> >>> >
> ---------------------------------------------------------------------
> >>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>> > For additional commands, e-mail: user-help@struts.apache.org
> >>> >
> >>> >
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>> For additional commands, e-mail: user-help@struts.apache.org
> >>>
> >>>
> >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Accesssing a bean from a jsp without struts tags

Posted by ma...@yahoo.com.
mansour77@yahoo.com wrote:
> joey wrote:
>> add request.setAttribute("invoices",accountBean.getInvoices()) in your
>> action execute method.

How do I do this is struts 2. I couldn't find any way to get my hand on 
the Request object.

>> On 4/7/07, mansour77@yahoo.com <ma...@yahoo.com> wrote:
>>
>
> I thought that was set automatically by struts through the getters !
>
>
>>> OK, let me include more details, may be someone will understand what I
>>> am talking about.
>>> I have a list that belongs to  a Bean that's wet in an action class.
>>>
>>> public AccountBean getAccountBean() {
>>>     return accountBean;
>>> }
>>>
>>> AccountBean has an ArrayList<Invoices>  calles invoices.
>>>
>>> now im my jsp, I need to display this in a datagrid, I am doing this,
>>> but it's not working:
>>>
>>>
>>>
>>> <dg:dataGrid items="${accountBean.invoices}" var="inv" 
>>> name="datagrid1" >
>>> <columns>
>>> <column>
>>> <header value="Name" />
>>> <item value="${inv.statementDate}" />
>>> </column>
>>> </dg:dataGrid>
>>>
>>>
>>> that's the error  I am getting:
>>>
>>> According to TLD or attribute directive in tag file, attribute items 
>>> does
>>> not accept any expressions
>>>         org.apache.struts2.dispatcher.Dispatcher.serviceAction(
>>> Dispatcher.java:518)
>>>         org.apache.struts2.dispatcher.FilterDispatcher.doFilter(
>>> FilterDispatcher.java:421)
>>>
>>>
>>> Any Idea ??
>>>
>>>
>>>
>>>
>>> mansour77@yahoo.com wrote:
>>> > I have a bean that is set in an action class. I can access it using
>>> > struts tag, but what do I do if I need to access it from somewhere 
>>> else
>>> ?
>>> >
>>> > for example, if I need to access it from a list iterator.
>>> >
>>> > Thanks.
>>> >
>>> >
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> > For additional commands, e-mail: user-help@struts.apache.org
>>> >
>>> >
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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


Re: Accesssing a bean from a jsp without struts tags

Posted by ma...@yahoo.com.
joey wrote:
> add request.setAttribute("invoices",accountBean.getInvoices()) in your
> action execute method.
> On 4/7/07, mansour77@yahoo.com <ma...@yahoo.com> wrote:
>

I thought that was set automatically by struts through the getters !


>> OK, let me include more details, may be someone will understand what I
>> am talking about.
>> I have a list that belongs to  a Bean that's wet in an action class.
>>
>> public AccountBean getAccountBean() {
>>     return accountBean;
>> }
>>
>> AccountBean has an ArrayList<Invoices>  calles invoices.
>>
>> now im my jsp, I need to display this in a datagrid, I am doing this,
>> but it's not working:
>>
>>
>>
>> <dg:dataGrid items="${accountBean.invoices}" var="inv" 
>> name="datagrid1" >
>> <columns>
>> <column>
>> <header value="Name" />
>> <item value="${inv.statementDate}" />
>> </column>
>> </dg:dataGrid>
>>
>>
>> that's the error  I am getting:
>>
>> According to TLD or attribute directive in tag file, attribute items 
>> does
>> not accept any expressions
>>         org.apache.struts2.dispatcher.Dispatcher.serviceAction(
>> Dispatcher.java:518)
>>         org.apache.struts2.dispatcher.FilterDispatcher.doFilter(
>> FilterDispatcher.java:421)
>>
>>
>> Any Idea ??
>>
>>
>>
>>
>> mansour77@yahoo.com wrote:
>> > I have a bean that is set in an action class. I can access it using
>> > struts tag, but what do I do if I need to access it from somewhere 
>> else
>> ?
>> >
>> > for example, if I need to access it from a list iterator.
>> >
>> > Thanks.
>> >
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>


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


Re: Accesssing a bean from a jsp without struts tags

Posted by joey <re...@gmail.com>.
add request.setAttribute("invoices",accountBean.getInvoices()) in your
action execute method.
On 4/7/07, mansour77@yahoo.com <ma...@yahoo.com> wrote:
>
> OK, let me include more details, may be someone will understand what I
> am talking about.
> I have a list that belongs to  a Bean that's wet in an action class.
>
> public AccountBean getAccountBean() {
>     return accountBean;
> }
>
> AccountBean has an ArrayList<Invoices>  calles invoices.
>
> now im my jsp, I need to display this in a datagrid, I am doing this,
> but it's not working:
>
>
>
> <dg:dataGrid items="${accountBean.invoices}" var="inv" name="datagrid1" >
> <columns>
> <column>
> <header value="Name" />
> <item value="${inv.statementDate}" />
> </column>
> </dg:dataGrid>
>
>
> that's the error  I am getting:
>
> According to TLD or attribute directive in tag file, attribute items does
> not accept any expressions
>         org.apache.struts2.dispatcher.Dispatcher.serviceAction(
> Dispatcher.java:518)
>         org.apache.struts2.dispatcher.FilterDispatcher.doFilter(
> FilterDispatcher.java:421)
>
>
> Any Idea ??
>
>
>
>
> mansour77@yahoo.com wrote:
> > I have a bean that is set in an action class. I can access it using
> > struts tag, but what do I do if I need to access it from somewhere else
> ?
> >
> > for example, if I need to access it from a list iterator.
> >
> > Thanks.
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Accesssing a bean from a jsp without struts tags

Posted by ma...@yahoo.com.
OK, let me include more details, may be someone will understand what I 
am talking about.
I have a list that belongs to  a Bean that's wet in an action class.

public AccountBean getAccountBean() {
    return accountBean;
}

AccountBean has an ArrayList<Invoices>  calles invoices.

now im my jsp, I need to display this in a datagrid, I am doing this, 
but it's not working:



<dg:dataGrid items="${accountBean.invoices}" var="inv" name="datagrid1" >
<columns>
<column>
<header value="Name" />
<item value="${inv.statementDate}" />
</column>
</dg:dataGrid>


that's the error  I am getting:

According to TLD or attribute directive in tag file, attribute items does not accept any expressions
	org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:518)
	org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)


Any Idea ??




mansour77@yahoo.com wrote:
> I have a bean that is set in an action class. I can access it using 
> struts tag, but what do I do if I need to access it from somewhere else ?
>
> for example, if I need to access it from a list iterator.
>
> Thanks.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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