Actually I figured out a partial answer to my question. Change
VariableInfo.AT_BEGIN to VariableInfo.NESTED, which makes the variable
visible only within the tag. In the tag the developer needs to do
something like

<%String myUser = "";%>
<zp:checkAuth>
  <%myUser = zapatecUser;%>
</zp:checkAuth>

to fetch the user's name. So "zapatecUser" is only visible inside the
tag.

Dror

On Sun, Sep 08, 2002 at 03:23:31PM -0700, Dror Matalon wrote:
> This and the hint from Dmitry Namiot put me on the right track. The
> article at http://www.stardeveloper.com:8080/articles/081601-1.shtml,
> provided the needed details. Basically:
>
> 1. In my tag I had to set the variable's value, in my case
>       pageContext.setAttribute("zapatecUser", user.getUserName());
>
> 2. I had to create a class with the extra info. In my case:
> public class CheckAuthVar extends TagExtraInfo {
>
>   public VariableInfo[] getVariableInfo(TagData data) {
>     return new VariableInfo[] {
>       new VariableInfo("zapatecUser", "java.lang.String",
>           true, VariableInfo.AT_BEGIN)
>     };
>   }
> }
>
> 3. Had to add an extra line to the TLD:
>       <teiclass>com.zapatec.tags.CheckAuthVar</teiclass>
>
> Looking at the generated JSP:
>       java.lang.String zapatecUser = null;
>                       try {
>                                       int _jspx_eval_zp_checkAuth_0 = 
>_jspx_th_zp_checkAuth_0.doStartTag();
>                                       zapatecUser = (java.lang.String)
>                                       pageContext.findAttribute("zapatecUser");
>                                       ...
>
> We can see how the variable zapatecUser comes to life.
>
> Question:
> Why doesn't the tag library use the same mechanism for getters as it
> does for setters? Since
> <zp:foo bar='<%=aaa%>'>
> gets tranlated into setBar(aaa);
>
> seems like
> <zp:foo value='bar' variable='<%=aaa%>'>
> could get translated into aaa=getBar();
>
> I hate the idea of bringing to life variables with magic names. Is there
> a better mechanis in JSPs to do this?
>
> Thanks,
>
> Dror
>
>
>
>
> On Sun, Sep 08, 2002 at 11:28:59AM -0400, Shawn Bayern wrote:
> > On Sat, 7 Sep 2002, Dror Matalon wrote:
> >
> > > How do you do the opposite, how do you fetch a var from a tag into your
> > > java code? I'd like to have a tag that fetches the user name and makes
> > > it available to the java code. Something like:
> > >
> > > <%
> > > String user = "";
> > > %>
> > >
> > > <zp:authenticate "<%=user%>"=userName/>
> > >
> > > <%
> > > if(userName.equals("joe"))
> > >         ...
> > > else
> > >         ...
> > > %>
> >
> > In JSP 1.2, this is done using either the <variable> element in the TLD or
> > a TagExtraInfo class.  See the spec or a book for details.
> >
> > In newer pages -- those that use JSTL or the upcoming JSP 2.0 standard --
> > it will probably be easier to use the expression language, which simply
> > requires that you insert variables into page, request, session, or
> > application scope.  The use of scripting variables, which are tied
> > primarily to scriptlet code, effectively becomes obsolete, or at least
> > unfashionable.  (Of course, JSP will always support scripting variables,
> > but the goal is for people to wonder, "Why would I ever do it *that* way
> > now?")
> >
> > --
> > Shawn Bayern
> > "JSTL in Action"   http://www.jstlbook.com
> >
> > ===========================================================================
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> >  http://archives.java.sun.com/jsp-interest.html
> >  http://java.sun.com/products/jsp/faq.html
> >  http://www.esperanto.org.nz/jsp/jspfaq.jsp
> >  http://www.jguru.com/faq/index.jsp
> >  http://www.jspinsider.com
>
> --
> Dror Matalon
> Zapatec Inc
> 1700 MLK Way
> Berkeley, CA 94709
> http://www.zapatec.com

--
Dror Matalon
Zapatec Inc
1700 MLK Way
Berkeley, CA 94709
http://www.zapatec.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to