You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Steve Raeburn <st...@ninsky.com> on 2003/06/04 11:10:40 UTC

Accessing scope attributes with dotted names using JSTL

Is it possible to access a scoped attribute if the attribute name contains a
dot?

For example, if I set a request attribute:
  request.setAttribute("mydomain.mybean", bean);

I'd like to access it like this:
 <c:out value="${mydomain.mybean}/>

But that doesn't work because it tries to access the mybean property of a
mydomain bean. Is there a straightforward way to do  this or do I have to
abandon using dotted attribute names?

Thanks for your help.

Steve



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


why doesn't c:redirect work inside a file included with c:import?

Posted by "David N. Foote" <da...@pervasent.com>.
List,

In the files attached, navigating  to
http://localhost:8080/app-name/first.jsp will result in the text below:

Before redirect
I am the first page.

Does anyone know a way to make c:redirect from  a file included with
c:import effective?  If not, does anyone know how to use JSTL to access
query parameters inside a file included with the <% include %> directive?

Thank you in advance,

David Foote


Nested forEach tags

Posted by Eric Hauser <eh...@indiana.edu>.
I'm writing a struts application where two attributes are put in the
request and sent to a jsp: casesResult and chargeMap (casesResult is
anArrayList and chargeMap is an
org.apache.commons.collections.MultiHashMap).

<c:forEach items="${casesResult}" var="cases">
        <!-- print some info from each cases bean casesResult
ArrayList -->
        <c:forEach items="${chargeMap[cases.caseid]}" var="charges">
        <!-- print info in ArrayList retrieve from chargeMap with key
        value from the current instance of cases using field caseid.
-->
        </c:forEach>
</c:forEach>

Two questions ---
I keep getting the following error:
org.apache.jasper.compiler.CompileException:
/java/tomcat/webapps/custodyinformation/profile.jsp(68,3) Unable to
load
class null

This is the line for the first forEach tag. I know that casesResult is
sent in the request not equal to null. So, I'm not sure why this isn't
working. I tried using ${requestScope.casesResult}, and I even tried
setting the attributes in the session and using
${sessionScope.casesResult}

Also, since I have not been able to test it yet, is my method of
nesting
the other forEach tag the proper way to achieve my goal?. Thanks in
advance.
 
-------------------------------
Eric Hauser
ehauser@indiana.edu

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


RE: Accessing scope attributes with dotted names using JSTL

Posted by Steve Raeburn <st...@ninsky.com>.
No. I wanted to use the EL if possible. I guess I could use this as a last
resort.

Thanks for pointing it out.

Steve

> -----Original Message-----
> From: N. Chen [mailto:nickkc@u.washington.edu]
> Sent: June 4, 2003 1:27 PM
> To: Tag Libraries Users List
> Subject: Re: Accessing scope attributes with dotted names using JSTL
>
>
>
> have you try
>
> <c_rt:out value="<%=mydomain.mybeangetmethod%>/>
>
> nick
>


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


Re: Accessing scope attributes with dotted names using JSTL

Posted by "N. Chen" <ni...@u.washington.edu>.
have you try

<c_rt:out value="<%=mydomain.mybeangetmethod%>/>

nick

On Wed, 4 Jun 2003, Brian Buckley wrote:

> > Is there any way to do it without specifying the scope?
> > As in <c:out value="${\"mydomain.mybean\""} (which doesn't work).
>
> I asked this on the list awhile back and surprisingly the answer was no
> [short of writing one's own taglib to get it done].
>
> See http://marc.theaimsgroup.com/?l=taglibs-user&m=104939902508483&w=2
>
> Brian
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>


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


Re: Accessing scope attributes with dotted names using JSTL

Posted by Brian Buckley <br...@attbi.com>.
> Is there any way to do it without specifying the scope?
> As in <c:out value="${\"mydomain.mybean\""} (which doesn't work).

I asked this on the list awhile back and surprisingly the answer was no
[short of writing one's own taglib to get it done].

See http://marc.theaimsgroup.com/?l=taglibs-user&m=104939902508483&w=2

Brian






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


Re: Why not allow direct EL?

Posted by Gregory Guthrie <gu...@mum.edu>.
At 11:02 AM 06/07/2003 -0400, Serge Knystautas wrote:
>Gregory Guthrie wrote:
>>Just wondering why JSP evolution didn't chose to include this direction 
>>of feature(s).
>
>Please read the JSP 2.0 spec.  That's exactly what is supported.

-- Very neat, thanks; I hadn't seen that yet. I guess I'll wait for Tomcat 
5.0 release!

>Serge Knystautas

--------------------------------------------------------
Gregory Guthrie
guthrie@mum.edu         (641)472-1125    Fax: -1103
-------------------------------------------------------- 


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


Re: Why not allow direct EL?

Posted by Serge Knystautas <se...@lokitech.com>.
Gregory Guthrie wrote:
> Just wondering why JSP evolution didn't chose to include this direction 
> of feature(s).

Please read the JSP 2.0 spec.  That's exactly what is supported.

-- 
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com/
p. 1.301.656.5501
e. sergek@lokitech.com



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


Why not allow direct EL?

Posted by Gregory Guthrie <gu...@mum.edu>.
Why was it decided to not allow simple EL expressions in JSP itself, 
without requiring it as a tag expression?

E.g.
   Today is ${date.today}.

v.s. requiring a <c:out .... />
to get EL expressions.

Yes, it would require a change to JSP, or a global encompassing tag to 
invoke a pre-processor(!), but it seems much more convenient, and natural. 
Like Jakarta Velocity.  :-) Velocity pages are certainly a lot simpler to 
read/write.

Just wondering why JSP evolution didn't chose to include this direction of 
feature(s).

Gregory

--------------------------------------------------------
Gregory Guthrie
guthrie@mum.edu         (641)472-1125    Fax: -1103
-------------------------------------------------------- 


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


Re: Accessing scope attributes with dotted names using JSTL

Posted by Pierre Delisle <Pi...@Sun.COM>.
Serge Knystautas wrote:
> Steve Raeburn wrote:
> 
>> Thanks, but that's not what I'm trying to accomplish.
>>
>> It's very common to place beans into session or application scopes with
>> names such as "org.apache.struts.action.ACTION_MESSAGE". This is 
>> similar to
>> the Java package naming convention and accomplishes the same purpose of
>> avoiding name collisions.
>>
>> In order to access the bean, you need to be able to specify a dotted 
>> name,
>> but you might not always know in which scope it will be found. Hence the
>> need to be able to specify a dotted bean name in EL.
>>
>> The problem is that either EL interprets the string as a path to a nested
>> property or, if you escape the string, as a literal string.
>>
>> Ultimately, I need to be able to access the
>> PageContext.findAttribute(java.lang.String name) method using EL, but as
>> this method does not meet bean property naming conventions I can't 
>> even do
>> something like ${pageContext["dotted.name"]}.
> 
> 
> It's true you can't do find attribute with a dotted-name.  If you want 
> to jury rig something, do this...
> 
> ========================================
> <%!
> static class AttributeFascade extends HashMap {
>     PageContext context;
>     public AttributeFascade(PageContext context) {
>         this.context = context;
>     }
> 
>     public Object get(Object key) {
>         return context.findAttribute(key);
>     }
> }
> %>
> 
> <%
> pageContext.setAttribute("finder", new AttributeFascade(pageContext));
> %>
> 
> <c:out value="${finder['dotted.name']}" />
> 
> ========================================
> 
> You can flesh out AttributeFascade if you want to implement more methods 
> on Map, maybe make it a regular class, maybe have a taglib that sets 
> this for you, e.g.,
> 
> <foo:attributeFascade var="finder" />
> 
> Anyway, just a thought on how to do this if you must.  As you can see, 
> you start bending the brain in on itself, so that's part of why it was 
> left off of the spec. ;)

As shown by all emails on the topic, accessing scoped variables with a
dotted name is not as easy as it should be right out of the box.

I'll submit the issue to the JSP spec leads to see if maybe they'd be
willing to amend the EL syntax to make this easier.
[Either adding an extra implicit object such as 'allScopes'
to allow ${allScopes['my.dottted.scoped.var']},
or even maybe allowing something like ${['my.dotted.scoped.var']}).

    -- Pierre


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


RE: Accessing scope attributes with dotted names using JSTL

Posted by Steve Raeburn <st...@ninsky.com>.
That would be wonderful. It *should* be a straightforward thing to do and I,
for one, would be grateful if you could help make it happen!

Steve

> -----Original Message-----
> From: Pierre.Delisle@Sun.COM [mailto:Pierre.Delisle@Sun.COM]
> Sent: June 6, 2003 6:45 PM
> To: Tag Libraries Users List
> Subject: Re: Accessing scope attributes with dotted names using JSTL
>
> As shown by all emails on the topic, accessing scoped variables with a
> dotted name is not as easy as it should be right out of the box.
>
> I'll submit the issue to the JSP spec leads to see if maybe they'd be
> willing to amend the EL syntax to make this easier.
> [Either adding an extra implicit object such as 'allScopes'
> to allow ${allScopes['my.dottted.scoped.var']},
> or even maybe allowing something like ${['my.dotted.scoped.var']}).
>
>     -- Pierre
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>


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


Re: Accessing scope attributes with dotted names using JSTL

Posted by Pierre Delisle <Pi...@Sun.COM>.
Serge Knystautas wrote:
> Steve Raeburn wrote:
> 
>> Thanks, but that's not what I'm trying to accomplish.
>>
>> It's very common to place beans into session or application scopes with
>> names such as "org.apache.struts.action.ACTION_MESSAGE". This is 
>> similar to
>> the Java package naming convention and accomplishes the same purpose of
>> avoiding name collisions.
>>
>> In order to access the bean, you need to be able to specify a dotted 
>> name,
>> but you might not always know in which scope it will be found. Hence the
>> need to be able to specify a dotted bean name in EL.
>>
>> The problem is that either EL interprets the string as a path to a nested
>> property or, if you escape the string, as a literal string.
>>
>> Ultimately, I need to be able to access the
>> PageContext.findAttribute(java.lang.String name) method using EL, but as
>> this method does not meet bean property naming conventions I can't 
>> even do
>> something like ${pageContext["dotted.name"]}.
> 
> 
> It's true you can't do find attribute with a dotted-name.  If you want 
> to jury rig something, do this...
> 
> ========================================
> <%!
> static class AttributeFascade extends HashMap {
>     PageContext context;
>     public AttributeFascade(PageContext context) {
>         this.context = context;
>     }
> 
>     public Object get(Object key) {
>         return context.findAttribute(key);
>     }
> }
> %>
> 
> <%
> pageContext.setAttribute("finder", new AttributeFascade(pageContext));
> %>
> 
> <c:out value="${finder['dotted.name']}" />
> 
> ========================================
> 
> You can flesh out AttributeFascade if you want to implement more methods 
> on Map, maybe make it a regular class, maybe have a taglib that sets 
> this for you, e.g.,
> 
> <foo:attributeFascade var="finder" />
> 
> Anyway, just a thought on how to do this if you must.  As you can see, 
> you start bending the brain in on itself, so that's part of why it was 
> left off of the spec. ;)

As shown by all emails on the topic, accessing scoped variables with a
dotted name is not as easy as it should be right out of the box.

I'll submit the issue to the JSP spec leads to see if maybe they'd be
willing to amend the EL syntax to make this easier.
[Either adding an extra implicit object such as 'allScopes'
to allow ${allScopes['my.dottted.scoped.var']},
or even maybe allowing something like ${['my.dotted.scoped.var']}).

    -- Pierre


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


Re: Accessing scope attributes with dotted names using JSTL

Posted by Serge Knystautas <se...@lokitech.com>.
Steve Raeburn wrote:
> Thanks, but that's not what I'm trying to accomplish.
> 
> It's very common to place beans into session or application scopes with
> names such as "org.apache.struts.action.ACTION_MESSAGE". This is similar to
> the Java package naming convention and accomplishes the same purpose of
> avoiding name collisions.
> 
> In order to access the bean, you need to be able to specify a dotted name,
> but you might not always know in which scope it will be found. Hence the
> need to be able to specify a dotted bean name in EL.
> 
> The problem is that either EL interprets the string as a path to a nested
> property or, if you escape the string, as a literal string.
> 
> Ultimately, I need to be able to access the
> PageContext.findAttribute(java.lang.String name) method using EL, but as
> this method does not meet bean property naming conventions I can't even do
> something like ${pageContext["dotted.name"]}.

It's true you can't do find attribute with a dotted-name.  If you want 
to jury rig something, do this...

========================================
<%!
static class AttributeFascade extends HashMap {
     PageContext context;
     public AttributeFascade(PageContext context) {
         this.context = context;
     }

     public Object get(Object key) {
         return context.findAttribute(key);
     }
}
%>

<%
pageContext.setAttribute("finder", new AttributeFascade(pageContext));
%>

<c:out value="${finder['dotted.name']}" />

========================================

You can flesh out AttributeFascade if you want to implement more methods 
on Map, maybe make it a regular class, maybe have a taglib that sets 
this for you, e.g.,

<foo:attributeFascade var="finder" />

Anyway, just a thought on how to do this if you must.  As you can see, 
you start bending the brain in on itself, so that's part of why it was 
left off of the spec. ;)

-- 
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com


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


RE: Accessing scope attributes with dotted names using JSTL

Posted by Steve Raeburn <st...@ninsky.com>.
Thanks, but that's not what I'm trying to accomplish.

It's very common to place beans into session or application scopes with
names such as "org.apache.struts.action.ACTION_MESSAGE". This is similar to
the Java package naming convention and accomplishes the same purpose of
avoiding name collisions.

In order to access the bean, you need to be able to specify a dotted name,
but you might not always know in which scope it will be found. Hence the
need to be able to specify a dotted bean name in EL.

The problem is that either EL interprets the string as a path to a nested
property or, if you escape the string, as a literal string.

Ultimately, I need to be able to access the
PageContext.findAttribute(java.lang.String name) method using EL, but as
this method does not meet bean property naming conventions I can't even do
something like ${pageContext["dotted.name"]}.

I had a look through the JSTL 1.0 and JSP 2.0 specs last night and this case
just does not seem to be addressed. As this is a very common requirement,
I'm surprised that it's not covered.

Steve


> -----Original Message-----
> From: Daniel Montero [mailto:danim@soin.co.cr]
> Sent: June 5, 2003 10:24 AM
> To: Tag Libraries Users List; steve@ninsky.com
> Subject: Re: Accessing scope attributes with dotted names using JSTL
>
>
> You could access a variable as ${mydomain.mybean} if you created a bean
> "mydomain" (Hashtable, for example), and set any attributes you
> want there.
>
> <%
> Hashtable mydomainVar = new Hashtable();
> String mybeanVariable="this is a test";
> mydomainVar.put("mybean", mybeanVariable);
> request.setAttribute("mydomain", mydomainVar);
> %>
> <c:out value="${mydomain.mybean}"/>
>
>
> HTH,
>     danim
>
>
>
> ----- Original Message -----
> From: "Steve Raeburn" <st...@ninsky.com>
> To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> Sent: Wednesday, June 04, 2003 11:12 AM
> Subject: RE: Accessing scope attributes with dotted names using JSTL
>
>
> > Thanks, that works. You're a star!
> >
> > Now, a follow up ... :-)
> >
> > Is there any way to do it without specifying the scope?
> > As in <c:out value="${\"mydomain.mybean\""} (which doesn't work).
> >
> > Steve
> >
> > > -----Original Message-----
> > > From: Bruce Perry [mailto:brucewperry@attbi.com]
> > > Sent: June 4, 2003 2:42 AM
> > > To: Tag Libraries Users List
> > > Subject: Re: Accessing scope attributes with dotted names using JSTL
> > >
> > >
> > > Try this:
> > >
> > > >  <c:out value="${requestScope[\"mydomain.mybean\"]"} />
> > >
> > > "requestScope" is an EL implicit object.
> > >
> > > Bruce
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>


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


Re: Accessing scope attributes with dotted names using JSTL

Posted by Daniel Montero <da...@soin.co.cr>.
You could access a variable as ${mydomain.mybean} if you created a bean
"mydomain" (Hashtable, for example), and set any attributes you want there.

<%
Hashtable mydomainVar = new Hashtable();
String mybeanVariable="this is a test";
mydomainVar.put("mybean", mybeanVariable);
request.setAttribute("mydomain", mydomainVar);
%>
<c:out value="${mydomain.mybean}"/>


HTH,
    danim



----- Original Message ----- 
From: "Steve Raeburn" <st...@ninsky.com>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Wednesday, June 04, 2003 11:12 AM
Subject: RE: Accessing scope attributes with dotted names using JSTL


> Thanks, that works. You're a star!
>
> Now, a follow up ... :-)
>
> Is there any way to do it without specifying the scope?
> As in <c:out value="${\"mydomain.mybean\""} (which doesn't work).
>
> Steve
>
> > -----Original Message-----
> > From: Bruce Perry [mailto:brucewperry@attbi.com]
> > Sent: June 4, 2003 2:42 AM
> > To: Tag Libraries Users List
> > Subject: Re: Accessing scope attributes with dotted names using JSTL
> >
> >
> > Try this:
> >
> > >  <c:out value="${requestScope[\"mydomain.mybean\"]"} />
> >
> > "requestScope" is an EL implicit object.
> >
> > Bruce
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>


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


RE: Accessing scope attributes with dotted names using JSTL

Posted by Steve Raeburn <st...@ninsky.com>.
Thanks, that works. You're a star! 

Now, a follow up ... :-)

Is there any way to do it without specifying the scope? 
As in <c:out value="${\"mydomain.mybean\""} (which doesn't work).

Steve

> -----Original Message-----
> From: Bruce Perry [mailto:brucewperry@attbi.com]
> Sent: June 4, 2003 2:42 AM
> To: Tag Libraries Users List
> Subject: Re: Accessing scope attributes with dotted names using JSTL
> 
> 
> Try this:
> 
> >  <c:out value="${requestScope[\"mydomain.mybean\"]"} />
> 
> "requestScope" is an EL implicit object.
> 
> Bruce
> 


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


Re: Accessing scope attributes with dotted names using JSTL

Posted by Bruce Perry <br...@attbi.com>.
Try this:

>  <c:out value="${requestScope[\"mydomain.mybean\"]"} />

"requestScope" is an EL implicit object.

Bruce

On Wednesday, June 4, 2003, at 05:10 AM, Steve Raeburn wrote:

> Is it possible to access a scoped attribute if the attribute name 
> contains a
> dot?
>
> For example, if I set a request attribute:
>   request.setAttribute("mydomain.mybean", bean);
>
> I'd like to access it like this:
>  <c:out value="${mydomain.mybean}/>
>
> But that doesn't work because it tries to access the mybean property 
> of a
> mydomain bean. Is there a straightforward way to do  this or do I have 
> to
> abandon using dotted attribute names?
>
> Thanks for your help.
>
> Steve
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>


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