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 Richard Sand <rs...@vgalleries.com> on 2001/11/08 02:27:52 UTC

cannot update page variable for use with xtags?

Hi all-

The problem I am encountering is that when I use an xtags tag with a
variable from the request or page scope, I cannot alter the variable in my
JSP code.

I'm trying to do the following:

I have a help page generator called help.jsp which uses xtags to display the
selected help topic from an xml file (each topic is a tree such as:
<topic><topic-key>mytopic</topic-key>....</topic>).  The page gets invoked
with the desired topic on the query string, such as:

/help.jsp?topic=changepassword

When my xtag usage is as follows, to get the variable directly from the
request, it works fine, i.e.:

<xtags:forEach select="/help/topic[topic-key=$topic][1]">

However, what I want to do is make sure that the "topic" is provided, so I
check the value of topic and if its missing, I set it, as follows:

<xtags:variable id="helptopic" select="$topic"/>

<%
   if ("".equals(helptopic)) helptopic = "nohelp";
   if (helptopic == null) helptopic = "nohelp";  // wasn't sure if i'd see
an empty string or null
%>

<xtags:forEach select="/help/topic[topic-key=$helptopic][1]">

However, this doesn't work!  The xtags treats helptopic as null and exits
immediately.  I've also tried other hacks like creating a new page variable,
but that doesn't work either.  Basically, what I am seeing is that xtags
allows me to see variables in my page, but it won't pick up on any changes
to those variables in the page.

Is this the expected behavior?

Thank!

Best regards,

Richard


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: xtags question with when tag

Posted by James Strachan <ja...@yahoo.co.uk>.
Hi Richard

----- Original Message -----
From: "Richard Sand" <rs...@vgalleries.com>
> Hi all,
>
> I have a simple xtags file that loops through all of the topics and
keywords
> in an xml help file.
>
> My loop is:
>
> <xtags:forEach select="/help/topic | /help/keyword">
>
> Within this loop, I want to process topics different than keywords.  I
> haven't been able to find a way to do this. I tried to do it by testing
for
> the existence of a child that only exists for a keyword, but the xtag:when
> tag doesn't seem to accept wildcards in its test parameter, i.e.:
>
> <xtags:forEach select="/help/topic | /help/keyword">
>    <xtags:choose>
>       <xtags:when test="keyword_file=*">
>          ....
>       </xtags:when>
>       <xtags:otherwise>
>          .....
>       </xtags:otherwise>
>    </xtags:choose>
> </xtags:forEach>

You could try this...

<xtags:when test="keyword_file">

which will match if the current node (a <keyword> or <topic>) has at least
one child <keyword_file> child.

> Is there some way to do this?

Maybe something like this, iterate through all children of <help> then
branch based on the name

<xtags:forEach select="/help/*">
   <xtags:choose>
      <xtags:when test="name()='topic'">
         ....
        process a <topic>
        ...
      </xtags:when>
      <xtags:when test="name()='keyword'">

         ....

        process a <keyword>
        ...
      </xtags:when>
      <xtags:otherwise>
         .....
      </xtags:otherwise>
   </xtags:choose>
</xtags:forEach>


James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


xtags question with when tag

Posted by Richard Sand <rs...@vgalleries.com>.
Hi all,

I have a simple xtags file that loops through all of the topics and keywords
in an xml help file.

My loop is:

<xtags:forEach select="/help/topic | /help/keyword">

Within this loop, I want to process topics different than keywords.  I
haven't been able to find a way to do this. I tried to do it by testing for
the existence of a child that only exists for a keyword, but the xtag:when
tag doesn't seem to accept wildcards in its test parameter, i.e.:

<xtags:forEach select="/help/topic | /help/keyword">
   <xtags:choose>
      <xtags:when test="keyword_file=*">
         ....
      </xtags:when>
      <xtags:otherwise>
         .....
      </xtags:otherwise>
   </xtags:choose>
</xtags:forEach>

Is there some way to do this?

Thanks!

-Richard


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: rtexprvalue apparently being ignored for xtag forEach select parameter

Posted by Richard Sand <rs...@vgalleries.com>.
Sorry BTW when I put the entire select string into a variable, it works,
i.e. this works:

<% String xpath = "/help/" + subjectstr + "[" + subjectstr +
"-key=$subjectjey][1]"; %>
<xtags:forEach select="<%= xpath %>"/>

So, the conclusion that I draw is that the JSP compiler isn't accepting a
combination of text and expression inside a tag parameter.  This also
explains why my other tags work.  Is this normal behavior?

Thanks!

-Richard


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: rtexprvalue apparently being ignored for xtag forEach select parameter

Posted by Richard Sand <rs...@vgalleries.com>.
Hi James-

I looked at the .java for my compiled page, and I see the following:

When I use my own tag library with an expression inside a tag, I see the
following:

My custom tag:
     <ipa:helpLink
keyword="<%=keyword_file%>"><%=keyword_title%></ipa:helpLink>

gets interpreted as:
    _jspx_th_ipa_helpLink_0.setKeyword(keyword_file);

where you can see that the expresion is properly evaluated.

But when I use the xtags tag in the same file, I see:

Tag:
<xtags:forEach
select="/help/<%=subjectstr%>[<%=subjectstr%>-key=$subjectkey][1]">

interpreted as:

_jspx_th_xtags_forEach_0.setSelect("/help/<%=subjectstr%>[<%=subjectstr%>-ke
y=$subjectkey][1]");

Can this be a bug in the jsp compiled?

Thanks!

-Richard

----- Original Message -----
From: "Richard Sand" <rs...@vgalleries.com>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Wednesday, December 19, 2001 11:28 AM
Subject: Re: rtexprvalue apparently being ignored for xtag forEach select
parameter


> Hi James-
>
> I tried both actually, neither work.  It just seems that the expression is
> not being evaluated!  I'd suspect something in Tomcat4 or the servlet api
> but I have other custom tags in the same page that include java
expressions
> in their variables and they work.  When I put the whole expression in a
> variable (your second suggestion), my page returns empty, and when I put
the
> expression into my select parameter (your first suggestion), the exception
> changes to:
>
> org.apache.jasper.compiler.ParseException: /help/help.jsp(45,28) Attribute
> has no value
> at
>
org.apache.jasper.compiler.JspReader.parseAttributeValue(JspReader.java:563)
>
> What else can I check?  Of course, if I go back to hardcoded "topic" or
> "keyword" so there is no expression in the select parameter, the page
works,
> so I know its not a problem with my data or expression.
>
> Thanks!
>
> -Richard
>
> ----- Original Message -----
> From: "James Strachan" <ja...@yahoo.co.uk>
> To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
> Sent: Wednesday, December 19, 2001 11:13 AM
> Subject: Re: rtexprvalue apparently being ignored for xtag forEach select
> parameter
>
>
> > Hi Richard
> >
> > ----- Original Message -----
> > From: "Richard Sand" <rs...@vgalleries.com>
> > > Hi,
> > >
> > > My xtags tag is:
> > >
> > > <xtags:forEach
> > > select="/help/<%=subjectstr%>[<%=subjectstr%>-key=$subjectkey][1]">
> >
> > Try building up the xpath in one single expression. e.g.
> >
> > <xtags:forEach select="<%= "/help" + subjectstr + "[" + subjectstr +
> > "-key=$subjectjey][1]" %>"/>
> >
> > Or using a variable for the XPath expression...
> >
> > <% String xpath = "/help" + subjectstr + "[" + subjectstr +
> > "-key=$subjectjey][1]"; %>
> >
> > <xtags:forEach select="<%  xpath %>"/>
> >
> > James
> >
> >
> > >
> > > where subjectstr is a string that can be set to "topic" or "keyword".
> > >
> > > However, I get the following exception:
> > >
> > > Message: org.dom4j.InvalidXPathException: Invalid XPath expression:
> > > /help/[-key=$subjectkey][1] Expected one of '.', '..', '@', '*',
> > >
> > > You can see from the exception that the variable 'subjectstr' is not
> being
> > > put into the expression.  I commented out the rest of my code and left
> > > <%=subjectstr%> there just to make sure that the variable was set
> properly
> > > and it was.  It seems to me like the "rtexprvalue" is being ignored
from
> > the
> > > tld for the select parameter.
> > >
> > > Has anyone else seen this behavior?
> > >
> > > I'm using Tomcat 4.01 on W2k.
> > >
> > > Thanks!
> > >
> > > Best regards,
> > >
> > > Richard
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > >
> > >
> >
> >
> > _________________________________________________________
> > Do You Yahoo!?
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: rtexprvalue apparently being ignored for xtag forEach select parameter

Posted by Richard Sand <rs...@vgalleries.com>.
Hi James-

I tried both actually, neither work.  It just seems that the expression is
not being evaluated!  I'd suspect something in Tomcat4 or the servlet api
but I have other custom tags in the same page that include java expressions
in their variables and they work.  When I put the whole expression in a
variable (your second suggestion), my page returns empty, and when I put the
expression into my select parameter (your first suggestion), the exception
changes to:

org.apache.jasper.compiler.ParseException: /help/help.jsp(45,28) Attribute
has no value
	at
org.apache.jasper.compiler.JspReader.parseAttributeValue(JspReader.java:563)

What else can I check?  Of course, if I go back to hardcoded "topic" or
"keyword" so there is no expression in the select parameter, the page works,
so I know its not a problem with my data or expression.

Thanks!

-Richard

----- Original Message -----
From: "James Strachan" <ja...@yahoo.co.uk>
To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
Sent: Wednesday, December 19, 2001 11:13 AM
Subject: Re: rtexprvalue apparently being ignored for xtag forEach select
parameter


> Hi Richard
>
> ----- Original Message -----
> From: "Richard Sand" <rs...@vgalleries.com>
> > Hi,
> >
> > My xtags tag is:
> >
> > <xtags:forEach
> > select="/help/<%=subjectstr%>[<%=subjectstr%>-key=$subjectkey][1]">
>
> Try building up the xpath in one single expression. e.g.
>
> <xtags:forEach select="<%= "/help" + subjectstr + "[" + subjectstr +
> "-key=$subjectjey][1]" %>"/>
>
> Or using a variable for the XPath expression...
>
> <% String xpath = "/help" + subjectstr + "[" + subjectstr +
> "-key=$subjectjey][1]"; %>
>
> <xtags:forEach select="<%  xpath %>"/>
>
> James
>
>
> >
> > where subjectstr is a string that can be set to "topic" or "keyword".
> >
> > However, I get the following exception:
> >
> > Message: org.dom4j.InvalidXPathException: Invalid XPath expression:
> > /help/[-key=$subjectkey][1] Expected one of '.', '..', '@', '*',
> >
> > You can see from the exception that the variable 'subjectstr' is not
being
> > put into the expression.  I commented out the rest of my code and left
> > <%=subjectstr%> there just to make sure that the variable was set
properly
> > and it was.  It seems to me like the "rtexprvalue" is being ignored from
> the
> > tld for the select parameter.
> >
> > Has anyone else seen this behavior?
> >
> > I'm using Tomcat 4.01 on W2k.
> >
> > Thanks!
> >
> > Best regards,
> >
> > Richard
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: rtexprvalue apparently being ignored for xtag forEach select parameter

Posted by James Strachan <ja...@yahoo.co.uk>.
Hi Richard

----- Original Message -----
From: "Richard Sand" <rs...@vgalleries.com>
> Hi,
>
> My xtags tag is:
>
> <xtags:forEach
> select="/help/<%=subjectstr%>[<%=subjectstr%>-key=$subjectkey][1]">

Try building up the xpath in one single expression. e.g.

<xtags:forEach select="<%= "/help" + subjectstr + "[" + subjectstr +
"-key=$subjectjey][1]" %>"/>

Or using a variable for the XPath expression...

<% String xpath = "/help" + subjectstr + "[" + subjectstr +
"-key=$subjectjey][1]"; %>

<xtags:forEach select="<%  xpath %>"/>

James


>
> where subjectstr is a string that can be set to "topic" or "keyword".
>
> However, I get the following exception:
>
> Message: org.dom4j.InvalidXPathException: Invalid XPath expression:
> /help/[-key=$subjectkey][1] Expected one of '.', '..', '@', '*',
>
> You can see from the exception that the variable 'subjectstr' is not being
> put into the expression.  I commented out the rest of my code and left
> <%=subjectstr%> there just to make sure that the variable was set properly
> and it was.  It seems to me like the "rtexprvalue" is being ignored from
the
> tld for the select parameter.
>
> Has anyone else seen this behavior?
>
> I'm using Tomcat 4.01 on W2k.
>
> Thanks!
>
> Best regards,
>
> Richard
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


rtexprvalue apparently being ignored for xtag forEach select parameter

Posted by Richard Sand <rs...@vgalleries.com>.
Hi,

My xtags tag is:

<xtags:forEach
select="/help/<%=subjectstr%>[<%=subjectstr%>-key=$subjectkey][1]">

where subjectstr is a string that can be set to "topic" or "keyword".

However, I get the following exception:

Message: org.dom4j.InvalidXPathException: Invalid XPath expression:
/help/[-key=$subjectkey][1] Expected one of '.', '..', '@', '*',

You can see from the exception that the variable 'subjectstr' is not being
put into the expression.  I commented out the rest of my code and left
<%=subjectstr%> there just to make sure that the variable was set properly
and it was.  It seems to me like the "rtexprvalue" is being ignored from the
tld for the select parameter.

Has anyone else seen this behavior?

I'm using Tomcat 4.01 on W2k.

Thanks!

Best regards,

Richard


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cannot update page variable for use with xtags?

Posted by James Strachan <ja...@yahoo.co.uk>.
Hi Richard

XTags uses JSP scopes or 'attributes'. It cannot see the values of scriptlet
expressions unless they are explicitly exported using the pageContext.

If you modify the code as follows it should work...

> <xtags:variable id="helptopic" select="$topic"/>
>
> <%
>    if ("".equals(helptopic)) helptopic = "nohelp";
>    if (helptopic == null) helptopic = "nohelp";  // wasn't sure if i'd see
> an empty string or null

       pageContext.setAttribute( "helptopic", helptopic );


> %>
>
> <xtags:forEach select="/help/topic[topic-key=$helptopic][1]">

James

----- Original Message -----
From: "Richard Sand" <rs...@vgalleries.com>
To: <ta...@jakarta.apache.org>
Sent: Thursday, November 08, 2001 1:27 AM
Subject: cannot update page variable for use with xtags?


> Hi all-
>
> The problem I am encountering is that when I use an xtags tag with a
> variable from the request or page scope, I cannot alter the variable in my
> JSP code.
>
> I'm trying to do the following:
>
> I have a help page generator called help.jsp which uses xtags to display
the
> selected help topic from an xml file (each topic is a tree such as:
> <topic><topic-key>mytopic</topic-key>....</topic>).  The page gets invoked
> with the desired topic on the query string, such as:
>
> /help.jsp?topic=changepassword
>
> When my xtag usage is as follows, to get the variable directly from the
> request, it works fine, i.e.:
>
> <xtags:forEach select="/help/topic[topic-key=$topic][1]">
>
> However, what I want to do is make sure that the "topic" is provided, so I
> check the value of topic and if its missing, I set it, as follows:
>
> <xtags:variable id="helptopic" select="$topic"/>
>
> <%
>    if ("".equals(helptopic)) helptopic = "nohelp";
>    if (helptopic == null) helptopic = "nohelp";  // wasn't sure if i'd see
> an empty string or null
> %>
>
> <xtags:forEach select="/help/topic[topic-key=$helptopic][1]">
>
> However, this doesn't work!  The xtags treats helptopic as null and exits
> immediately.  I've also tried other hacks like creating a new page
variable,
> but that doesn't work either.  Basically, what I am seeing is that xtags
> allows me to see variables in my page, but it won't pick up on any changes
> to those variables in the page.
>
> Is this the expected behavior?
>
> Thank!
>
> Best regards,
>
> Richard
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>