You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rachel Greenham <ra...@enetgroup.co.uk> on 2000/08/15 14:08:12 UTC
Using expressions in tag attributes
Should I be expecting this sort of thing to work?
<%
String name="wibble";
%>
<myprefix:GetVariable name="<%=name%>"/>
ie: using an expression in an attribute to a taglib tag. It doesn't
work, and I think I can see why, but as it does on HTML it would be
intuitive if it did.
Or is there another way of doing what I'm trying to do. Say for instance
I wanted to use this to list all variables:
<table>
<%
Iterator i = myobj.getVariableNames();
while (i.hasNext()
{
String name = i.next().toString();
%>
<tr><th><%=name%></th><td><myprefix:GetVariable name="<%=name%>"/>
<%
}
%>
Actually, on reflection it looks like a bit of an ugly mix - if I'm
putting that much Java in anyway, I may as well not be using the tag to
get the variable, just <%=myobj.getVariable(name)%>, or write another
tag for looping through variables.
--
Rachel
Re: Using expressions in tag attributes
Posted by Rachel Greenham <ra...@enetgroup.co.uk>.
William Brogden wrote:
>
> Using single quotes mixed with double quotes got this tag working:
>
> <ch11:signin studentId='<%= request.getParameter("stuid") %>'
> studentPw='<%= request.getParameter("stupw") %>'
> course='<%= request.getParameter("course") %>' >
>
> But note that it worked correctly with the Orion server when
> all quotes were double.
Ah, that's interesting in a terrifying sort of way.
So... Which is the *correct* behaviour? Are we talking about a bug in Tomcat
or an extra non-spec feature in Orion?
--
Rachel
Re: Using expressions in tag attributes
Posted by William Brogden <wb...@bga.com>.
Using single quotes mixed with double quotes got this tag working:
<ch11:signin studentId='<%= request.getParameter("stuid") %>'
studentPw='<%= request.getParameter("stupw") %>'
course='<%= request.getParameter("course") %>' >
But note that it worked correctly with the Orion server when
all quotes were double.
--
WBB - wbrogden@bga.com Chief Scientist, LANWrights, Inc.
Java Programmer Certification information and mock exam
at http://www.lanw.com/java/javacert/
Re: Using expressions in tag attributes
Posted by Craig McClanahan <Cr...@eng.sun.com>.
Rachel Greenham wrote:
> Craig McClanahan wrote:
> >
> > Rachel Greenham wrote:
> >
> > > Should I be expecting this sort of thing to work?
> > >
> > > <%
> > > String name="wibble";
> > > %>
> > > <myprefix:GetVariable name="<%=name%>"/>
> > >
> > > ie: using an expression in an attribute to a taglib tag. It doesn't
> > > work, and I think I can see why, but as it does on HTML it would be
> > > intuitive if it did.
> > >
> >
> > This should work if you declare, in your tag library descriptor file, that
> > this attribute takes runtime expression values. You would need something
> > like this:
> >
> > <attribute>
> > <name>name</name>
> > <required>true</required>
> > <rtexprvalue>true</rtexprvalue>
> > </attribute>
> >
> > Craig
>
> Yeah, I noticed that myself a little while after posting. :-} However, see
> my other postings, there do seem to be problems with this, in that things
> don't work properly if the expression you're passing contains any string
> constants (ie: quoted values)
>
> ie: to extend my above example:
>
> <myprefix:GetVariable name="<%=request.getParameter("name")%>"/> will fail.
>
Try single quotes for one set and double quotes for the other:
<myprefix:GetVariable name='<%= request.getParameter("name")%>'/>
>
> --
> Rachel
Craig
Re: Using expressions in tag attributes
Posted by Alec Bau <Al...@msdw.com>.
Rachel Greenham wrote:
>ie: to extend my above example:
><myprefix:GetVariable name="<%=request.getParameter("name")%>"/> will fail.
You should use single quotes in cases like these:
<myprefix:GetVariable name='<%=request.getParameter("name")%>'/>
Alec
Rachel Greenham wrote:
> Craig McClanahan wrote:
> >
> > Rachel Greenham wrote:
> >
> > > Should I be expecting this sort of thing to work?
> > >
> > > <%
> > > String name="wibble";
> > > %>
> > > <myprefix:GetVariable name="<%=name%>"/>
> > >
> > > ie: using an expression in an attribute to a taglib tag. It doesn't
> > > work, and I think I can see why, but as it does on HTML it would be
> > > intuitive if it did.
> > >
> >
> > This should work if you declare, in your tag library descriptor file, that
> > this attribute takes runtime expression values. You would need something
> > like this:
> >
> > <attribute>
> > <name>name</name>
> > <required>true</required>
> > <rtexprvalue>true</rtexprvalue>
> > </attribute>
> >
> > Craig
>
> Yeah, I noticed that myself a little while after posting. :-} However, see
> my other postings, there do seem to be problems with this, in that things
> don't work properly if the expression you're passing contains any string
> constants (ie: quoted values)
>
> ie: to extend my above example:
>
> <myprefix:GetVariable name="<%=request.getParameter("name")%>"/> will fail.
>
> --
> Rachel
Re: Using expressions in tag attributes
Posted by Rachel Greenham <ra...@enetgroup.co.uk>.
Craig McClanahan wrote:
>
> Rachel Greenham wrote:
>
> > Should I be expecting this sort of thing to work?
> >
> > <%
> > String name="wibble";
> > %>
> > <myprefix:GetVariable name="<%=name%>"/>
> >
> > ie: using an expression in an attribute to a taglib tag. It doesn't
> > work, and I think I can see why, but as it does on HTML it would be
> > intuitive if it did.
> >
>
> This should work if you declare, in your tag library descriptor file, that
> this attribute takes runtime expression values. You would need something
> like this:
>
> <attribute>
> <name>name</name>
> <required>true</required>
> <rtexprvalue>true</rtexprvalue>
> </attribute>
>
> Craig
Yeah, I noticed that myself a little while after posting. :-} However, see
my other postings, there do seem to be problems with this, in that things
don't work properly if the expression you're passing contains any string
constants (ie: quoted values)
ie: to extend my above example:
<myprefix:GetVariable name="<%=request.getParameter("name")%>"/> will fail.
--
Rachel
Re: Using expressions in tag attributes
Posted by Craig McClanahan <Cr...@eng.sun.com>.
Rachel Greenham wrote:
> Should I be expecting this sort of thing to work?
>
> <%
> String name="wibble";
> %>
> <myprefix:GetVariable name="<%=name%>"/>
>
> ie: using an expression in an attribute to a taglib tag. It doesn't
> work, and I think I can see why, but as it does on HTML it would be
> intuitive if it did.
>
This should work if you declare, in your tag library descriptor file, that
this attribute takes runtime expression values. You would need something
like this:
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
Craig
Re: Using expressions in tag attributes
Posted by Rachel Greenham <ra...@enetgroup.co.uk>.
Rachel Greenham wrote:
>
> Should I be expecting this sort of thing to work?
>
> <%
> String name="wibble";
> %>
> <myprefix:GetVariable name="<%=name%>"/>
Belay that, I just found the meaning of <rtexprvalue> in the tld.
Does exactly this.
:-}
--
Rachel