Custom tag parameters

          hi,
          I have created custom tags from my EJB using ejb2jsp tool. I tried the following,
          1 works and the other doesn't,
          a) This works.
          <mytag:foo param1="<%="test"%>" />
          b) this gives me a "ClassCastException"
          <% String value="test"; %>
          <mytag:foo param1="<%=value%>" />
          What am I missing here..? Any help pls...
          thx
          -jay
          

Well, I'm pretty much at a loss here (and I've been trying to figure this out for a few days now!). I've tried setting the attribute value multiple ways including:
<first:sample atty="<%=strVariable%>"/>
<first:sample atty="<![CDATA[<%=strVariable%>]]>"/>
<first:sample atty="<jsp:expression>strVariable</jsp:expression>"/>
<first:sample>
<first:parameter name="atty"><jsp:expression>strVariable</jsp:expression></first:parameter>
</first:sample>
<first:sample>
<first:attribute name="atty"><jsp:expression>strVariable</jsp:expression></first:attribute>
</first:sample>
<first:sample>
<jsp:attribute name="atty"><jsp:expression>strVariable</jsp:expression></jsp:attribute>
</first:sample>
and none of them seem to work.
Anyone have any ideas???

Similar Messages

  • JSP Custom Tag and Expressions for parameters

    This should be an easy question. I am trying to use an expression for a
              parameter to a jsp or custom jsp tag. When I hard code a value for the
              parameter, the tag works fine but when I use the expression, the expression
              gets evaluated but the tag itself does not resulting in the tag being shown
              in my output.
              For example:
              <jsp:forward page="www.slashdot.org"/> works
              <jsp:forward page="<%=request.getParameter("DESTINATION")%>"/>
              places the following into my html output
              <jsp:forward page="www.slashdot.org"/>
              Can someone please tell me what I am doing wrong or at least offer some
              debugging hints?
              Thanks in advance!
              Jacob Meushaw
              

    I have experienced almost this exact same problem, but with a custom
              tag. And I did make sure that my attribute specified
              <rtexprvalue>true</rtexprvalue>. Here is the weird part.
              If I do the following JSP code everything works fine:
              <% String foo = request.getParameter("bar"); %>
              <mytag:custom param="<%= foo %>"/>
              But if I do this:
              <mytag:custom param="<%= request.getParameter("bar") %>"/>
              I get the following in my html output:
              <mytag:custom param="whatever bar is set to in the request"/>
              It appears that the JSP container only does a one pass evaluation.
              Is this the spec of is this a bug?
              Jacob Meushaw wrote:
              >
              > This should be an easy question. I am trying to use an expression for a
              > parameter to a jsp or custom jsp tag. When I hard code a value for the
              > parameter, the tag works fine but when I use the expression, the expression
              > gets evaluated but the tag itself does not resulting in the tag being shown
              > in my output.
              >
              > For example:
              >
              > <jsp:forward page="www.slashdot.org"/> works
              >
              > <jsp:forward page="<%=request.getParameter("DESTINATION")%>"/>
              > places the following into my html output
              > <jsp:forward page="www.slashdot.org"/>
              >
              > Can someone please tell me what I am doing wrong or at least offer some
              > debugging hints?
              >
              > Thanks in advance!
              >
              > --
              > Jacob Meushaw
              Jeff Smith
              [email protected]
              BEA Systems, Inc.
              720-565-6613
              

  • SendRedirect in custom tag

              Hi,
              I have a custom tag that invokes sendRedirect() in the doAfterBody(). I'm curious
              as to why the redirection output is not complete. Here's what I always got:
              start of output ---------------------------------
              HTTP/1.1 302 Moved Temporarily
              Location: http://xenon:7001/ctl/error?WebLogicSession=OtCL5lprXh5wN0S5JJF4GFsDfU
              BKZk40AQ8mluIVsHKw2TcG5xpz|6804183543513756739/167846717/6/7001/7001/7002/7002/7
              001/-1
              Server: WebLogic 5.1.0 Service Pack 8 12/20/2000 16:34:54 #95137
              Content-Length: 481
              Content-Type: text/html
              Set-Cookie: WebLogicSession=OtCL5lprXh5wN0S5JJF4GFsDfUBKZk40AQ8mluIVsHKw2TcG5xpz
              |6804183543513756739/167846717/6/7001/7001/7002/7002/7001/-1; path=/
              Connection: Close
              <html><head><title>302 Moved Temporarily</title></head>
              <body bgcolor="#FFFFFF">
              <p>This document you reque
              -- end of output-------------
              As you can see, the Content Length is huge compared to the incomplete returned
              document.
              Can anyone help please?
              Thanks,
              Iwan
              

    you can pass the response object as argument to your
    method..Thanks for your response!
    Unfortunately I can't change the doEndTag() method parameters as doEndTag() is defined in the Tag interface. But if you mean pass the response object as an attribute of the tag i suppse that is possible.
    However, that's pretty close to the hack I currently have to work around this problem except I'm putting the response object in a request attribute in the page and then retrieving it in the doEndTag() method.
    But I am after something a little cleaner than either of these options..... I'm hoping I can just get the response object from another object I have access to. Any more thoughts?

  • Questions in Custom Tag

    Hi,
    I have couple of questions in Custom Libraray Tags:
    1) How I can from Tag Java file to open a new JSP window without the toolbars and determine the window size.
    2) How I can read a JSP parameter from Tag Java file. For example I have a field called "x" in JSP is not connected to the TAG by setAttribute.
    3) How I can pass a dynamic value to custom tag. <route:routeList agentID = "1" >
    how I can change the "1" to a field. When I change it to: <route:routeList agentID = "<%=request.getParameter("agentID")%>" > or to <route:routeList agentID = <%=request.getParameter("agentID")%> > I get empty value, even though the field has a value.
    Thank you ...

    [email protected] ... Well, if you put something as an attribute in the pageContext object, you can get it... same as request or session scope attributes, but I thought the OP meant to do this (I guess not, though.. see below):
    <%
    String str = "...";
    %>
    <mytag:stuff .... />
    And within the stuff tag, use str as a variable. I don't believe that's possible, because the compiled page in effect becomes like this:
    String str = "...";
    doStuffTag(whatever the parameters are);
    Obviously that's not the right naming for the tag, but you get the idea...
    JavaUserProg....
    2) First, it's best to put quotes around the tag attributes...
    <INPUT readOnly style="WIDTH: 84px; HEIGHT: 22px" name="operation[<%= lineNum%>"] value="<%=operation%>">
    Second, do you mean you want to read from the tag what the HTML input field has in it? First, you have to submit the form, then the call request.getParameter("fieldname") to get the value. Otherwise, I'm not clear on what you are really trying to do.
    3) If the field in the tag is an int field: setAgentID(int)
    Then you can define the tag value as:
    <mytag:stuff agentID="1" />
    or
    <% int aid = 1; %>
    <mytag:stuff agentID="<%= aid %>" />
    If you just put a static string value like the first way, it converts it. If you put an expression, the expression has to match the type of value it really is. So int for int, String for String, Collection for Collection.

  • Initialization of parameter values in JSP Custom Tag Handlers

    Hi - I have a tag handler for a custom tag that has no body, but accepts
              some parameters.
              If the parameters are optional and are passed with the tag in the source jsp
              page, then all is fine.
              However, for subsequent uses of the same tag in the same page if the
              optional parameters are omitted, the previous values remain in the instance
              of the tag handler class, as the attributes for the tag handler are declared
              as instance variables (with corresponding getters and setters) as per the
              tag handler specs.
              eg:
              <abc:sometag attrib1="a" attrib2="b"/>
              if attrib1 and attrib2 are optional, then a subsequent use of this tag, eg:
              <abc:sometag/>
              attrib1 and attrib2 still have their previously assigned values of "a" and
              "b".
              Is there a method I can call to get the actual values of the attributes that
              were passed on a particular call to the tag handler, or is there a way to
              initialize the attributes before the tag handler processing method, eg
              doBeforeBody(), doAfterBody(), is called?
              Thanks,
              Kevin Hooke
              

    Yeah, just call the JSPWriter's print method instead of using the StringBuffer, or write your own subclass of StringBuffer (or StringBuilder if Java 5+) which will do this for you automatically when the size is at a certain point, and clear it out)

  • Custom tag lib with output parameter

    Hi,
    I need a tag libray that gives me a specific element of a Vector.
    Here there is the line I have in my jsp.
    <ct:partizione tronco="${contenitoreCentralineTronco}" indice="index" partizione="tmpPartizione"/>
    ...-contenitoreCentralineTronco is an Object that contains a Vector of other specif objects.
    -indice is the vector index of the specif instance I need.
    -partizione should be the output instance.
    This is part of my tld file:
        <tag>
             <name>partizione</name>
            <tagclass>ss.aspi.classi.centraline.grafica.tagSupport.Partizione</tagclass>
            <bodycontent>empty</bodycontent>
            <info>Estrae una partizione da un vettore di partizioni dato l'indice</info>
            <attribute>
                <name>tronco</name>
                <required>true</required>
                <rtexprvalue>true</rtexprvalue>
            </attribute>
            <attribute>
                <name>indice</name>
                <required>true</required>
            </attribute>
            <attribute>
                <name>partizione</name>
                <required>false</required>
            </attribute>
         </tag>
    ...this is part of the class called by the tag:
         private ContenitoreTroncoBean tronco;
         private Integer indice;
         private ContenitorePartizioneBean partizione;
         public int doStartTag() throws JspException {
              try {
                   Vector<ContenitorePartizioneBean> partizioni = tronco.getPartizioniBean();
                   partizione = partizioni.get(indice);
              }catch (Exception e) {
                   log.error("Errore nell'estrazione della Partizione "+indice);
                   e.printStackTrace();
              return TagSupport.SKIP_BODY;
         //All getter and setter functionsWhen I run the application I get this exception:
    jsp.error.beans.property.conversion
    looking deeper in the class code jenerated from the jsp, I noted that the problem refers to the third attribute of the tag <ct:partizione>.
    It seems It trys to set the attribute "partizione" with the value "tmpPartizione", but partizioni should be an output attribut non input. The varible tmpPartizione doesn't exist... the tag should create it.
    I realized I didn't get how I should create a tag with output parameters.
    Anyone can explane me it?
    Thanks.

    One suggestion: Take a closer look at the EL (expression language)
    It has an excellent syntax for accessing collections/maps
    ${contenitoreCentralineTronco[index]} would exactly what you want, without having to write a custom tag for it.
    If you REALLY want to do this as a custom tag, then you need to treat the input attribute as a String (the name of the variable you are going to create?) Right now your tag declares the attribute partizione as being of type ContenitorePartizioneBean which is probably the cause of the problem - you are passing it a String.
    Cheers,
    evnafets

  • Custom tag attribute named operation

              Hi,
              I ported a web application from WL6.1sp4 to WL7.0sp2 and expirienced a wired problem.
              All my JSP's did not compile anymore. I received a error message "no setter for
              attribute operation defined", although there was a a method setOperation in the
              current code and there were no code modifications at all.
              After replacing all attributes named operation with opmode the system worked fine
              again.
              Is there any restriction in naming your attributes in custom tags?
              Thanks for help
              Michael
              

              Me again,
              I checked again the parameters of the VM (Sun JDK 1.3.1_06) and tried the the
              different options of the HotSpot compiler. I found out that the problem I reported
              with the last posting can easily be reproduced if you run the VM in HotSpot-Classic
              mode.
              I suppose it is a bug in Sun's VM for Windows. Does somebody have similar expiriences?
              Michael
              "Michael" <[email protected]> wrote:
              >
              >Hi,
              >
              >I ported a web application from WL6.1sp4 to WL7.0sp2 and expirienced
              >a wired problem.
              >All my JSP's did not compile anymore. I received a error message "no
              >setter for
              >attribute operation defined", although there was a a method setOperation
              >in the
              >current code and there were no code modifications at all.
              >
              >After replacing all attributes named operation with opmode the system
              >worked fine
              >again.
              >
              >Is there any restriction in naming your attributes in custom tags?
              >
              >Thanks for help
              >Michael
              

  • Creating an action link in a custom tag

    What is the recommended way of creating an action url (and some parameters) through code, not through a netui tag? I'm writing a custom tag that is being used in a PageFlow application. Ultimately the tag puts out a set of links based on some data it collects. I want the links to be action links to the current pageflow and to 'play nice' with the current page flow and other tags.
    Since it's in my own custom tag I don't really have the option of using the netui:anchor tag, I need to create the URL for the action invocation through code.
    Thanks for any tips.
    -Chris

    Closing the thread...

  • Finding the custom tag name from inside the tag handler

    Hello,
    I searched the forum, but couldnt find the answer (or in the API). In my custom tag handler, I want to know what the name of the custom tag was. Is this possible?
    Thanks in advance.
    Chris
    ps. Without parsing the .tld file... :)

    Hmm, that's unfortunate. Thanks a lot for your work. I had a feeling since it wasn't in the API that it wasn't possible. Here's why, and maybe they will add this feature later...
    We are making our own tags for buttons on our app (the button will be an HTML table, with a clickable background, that looks like an image, but isnt).
    The HTML designers want tags they can drag and drop to the screen in DreamWeaver, including visual feedback on what they dragged and dropped. So the tag <fast:blueButton>Continue</fast:blueButton> will show a blue button image in dreamWeaver with "Continue" as the text. There are a lot of parameters to set for each button, like height, width, border, etc. that will be configured in an XML config file for each button.
    It would be nice if all the buttons we invent in the tld point to the same generic button class, and when the generic button class runs, sees which button called it, and gets its config from an XML file.
    This way the designer could add more buttons with the tld and XML config, and no more java classes are needed. However, if a generic button is sent with a type param: <fast:button type="blue">Continue</fast:button> then there is no visual feedback in the tool (in the first case we could have set the fast:blueButton to be the image of a blue button) and it cant be picked from a list in the tool (the designer needs to remember which types exist). It seems not important to programmers, but for designers it is important.
    Oh well, I will see if there is another way to NOT have tons of Java classes to support.
    Thanks,
    Chris

  • JSP Custom Tags, Tag Handlers, Passing values

    Multiple questions here while I try to work with custom tags (its a requirement):
    From what I have had so far - I have a .tld file, a .java file and a .jsp page.
    (this is not a working version as I just got it from a website)
    platform: tomcat on an xp box.
    I was wondering if we can pass the parameters that are passed to the the jsp page (like blah.jsp?param1=value1&param2=valu2 ) to the tag handler?
    This is because the processing that I need to do in the handler would depend on what I have in the passed values.
    Any help in letting me know where to place those files on the tomcat context root would help. Please see, I do have a couple of servlets running on the box also and they might be in the same context root.
    Any good short tutorial link is also welcome as a short answer as I try to unravel the custom tags in jsp.

    I am using TomCat 5.5
    What I need to do using tags is to build a web-page on the fly by polling a couple of different tables in the database.
    This is to be done using a jsp and custom tag (requirement) which would be able to handle any resultsets. We also have to come up with pageContext attribute names and supply column names as those attributes. Thus we will have to come up with the meta data file and a tag library descriptor as well.
    I found a helloworld solution on a website and was trying to modify it to meet my needs. But I guess I under-estimated the work that needed to be done in this one.

  • Is it possible to pass dynamic values to custom tag?

    Hi there, I'm trying to build a calendar custom tag so I can drop the calendar into an existing webpage easily.
    I have got the calendar displaying on the page but the problem I have is when I try to create 'previous' and 'next' links. Is it possible to pass parameters to a custom tag that have dynamic values?
    In PHP it would looks something like:
    <a href="bla.php?page=$pagenumber">next page</a>When I create the calendar object I set it to the current date so when I try to increase or decrease the month (next/prev month) it doesn't work because the code is run again and hence setting the current date again.
    Any ideas?
    Cheers in advance
    Message was edited by:
    MajorMahem

    for eg
    <a href=" Display.jsp?id='+<%=customerId%>">Result Page</a>
    Please try this,
    i didn't work out, any how apply this sample to your code

  • JSP in custom tag attributes...

    Sirs,
              A very nice feature from a development perspective, would be the ability
              to use JSP code within custom tags. Say I have a page on which I wish
              to give all the information on a widget. Say further that I have
              implemented a tag that writes out all the info of a widget as HTML
              table. I would like to write something like this:
              <mytaglib:widgetTag widgetID="<%=request.getParameter("widget_id")%>"
              />
              As far as I know, in the current implementation of custom taglibs this
              does not seem to be possible. Instead you end up writing something like
              this:
              <mytaglib:widgetTag>
              <mytaglib:getWidget><%=request.getParameter("widget_id")%>"</mytaglib:getWidget>
              <mytaglib:displayWidget />
              </mytaglib:widgetTag>
              Which is much more like a scripting language than a heirarchical XML .
              Now, I could always just use the request object within the tag helper
              classes, but this gives up flexibility and can introduce security
              issues, and it also makes the tags much more difficult to work with...
              In short, we should push for JSP evaluation of tag attributes. Weblogic
              could leap ahead of other app servers in this area (making up for the
              custom tag performance issues, to be solve in sp6) and Sun would, once
              again, follow Weblogic's lead and rewrite the standard to include this
              functionality.
              Regards,
              Carson Gross
              

    Carson,
              Perhaps the problem is that you are treating custom tags like one would
              construct an imperative language. I have never had to put Java or use beans
              or %= or even parameters to tags into a JSP because of custom tags.
              The real problem is writing/packaging/maintaining all those tags; sure could
              use a tool that did just that ;-)
              Peace,
              Cameron Purdy
              [email protected]
              http://www.tangosol.com
              WebLogic Consulting Available
              "Carson Gross" <[email protected]> wrote in message
              news:[email protected]...
              > Sirs,
              >
              > A very nice feature from a development perspective, would be the ability
              > to use JSP code within custom tags. Say I have a page on which I wish
              > to give all the information on a widget. Say further that I have
              > implemented a tag that writes out all the info of a widget as HTML
              > table. I would like to write something like this:
              >
              > <mytaglib:widgetTag widgetID="<%=request.getParameter("widget_id")%>"
              > />
              >
              > As far as I know, in the current implementation of custom taglibs this
              > does not seem to be possible. Instead you end up writing something like
              > this:
              >
              > <mytaglib:widgetTag>
              >
              >
              <mytaglib:getWidget><%=request.getParameter("widget_id")%>"</mytaglib:getWid
              get>
              >
              > <mytaglib:displayWidget />
              > </mytaglib:widgetTag>
              >
              > Which is much more like a scripting language than a heirarchical XML .
              > Now, I could always just use the request object within the tag helper
              > classes, but this gives up flexibility and can introduce security
              > issues, and it also makes the tags much more difficult to work with...
              >
              > In short, we should push for JSP evaluation of tag attributes. Weblogic
              > could leap ahead of other app servers in this area (making up for the
              > custom tag performance issues, to be solve in sp6) and Sun would, once
              > again, follow Weblogic's lead and rewrite the standard to include this
              > functionality.
              >
              > Regards,
              > Carson Gross
              >
              

  • Custom tag - unable to find setter method error

    I see this compileException on IAS but not on BEA app server and iWS.
    JSPProvider.processJSPFile(): jsp=searchContent.jsp, org.apache.jasper.compiler.CompileException
    Unable to find setter method for attribute: input
    The reason is because the custom tag has a setInput() that takes a String parameter while the getInput() returns an InputStream.
    Should both get and set methods have the same type of parameters or is this a due to a bug in the app server ?

    I see this compileException on IAS but not on BEA app
    server and iWS.
    JSPProvider.processJSPFile(): jsp=searchContent.jsp,
    org.apache.jasper.compiler.CompileException
    Unable to find setter method for attribute: input
    The reason is because the custom tag has a setInput()
    that takes a String parameter while the getInput()
    returns an InputStream.
    Should both get and set methods have the same type of
    parameters or is this a due to a bug in the app server
    I was only going off info from the original post. The error specifically states "Unable to find setter method for attribute: input" with a lower case i for the input attribute. You also specifcally stated "The reason is because the custom tag has a setInput()" with a capital I for the setInput method. This would most definitely cause the error you were receiving. That is unless you corrected this between your original post and your followup testing.
    Cliff

  • Scripting variables and custom tags

    Hello,
    I wonder how I could use a scripting variable in a custom tag? I have written a tag that formats number and dates, and would like to be able to do somethin like
    <% double x = 12,345; %>
    <x:write name="x" format="xyz" />
    Also I wonder how best to implement tags with parameters? I don't suppose it's possible to nest tags or scriplets in a way like <x:bla name="test" value="<%= 12345 %>" />? It seems tedious having to create an Object just to pass a Parameter.
    Many thanks in advance for any help!
    Bjoern

    I think I found the solution,
    pageContext.setAttribute(...,...)

  • ApplicationResources.properties value as custom tag attribute value

    I have a custom tag which takes 4 parameters, can accept static strings or expressions.
    I would like to send in the value of a key in my ApplicationResources.properties file as one of the values for my attributes but i'm unsure how to do so. I have not found any pertinent information out there either, is this even possible?
    Thanks,
    JP

    you can, but you can't nest tags like this:
    <my:tag attr="<bean:message key="abc">">
    so you'd have to do this, presuming the attribute allows rtexpressions:
    <%
    MessageResources mr = (MessageResources)application.getAttribute(Globals.MESSAGES_KEY); // or the bundle name
    Locale locale = (Locale)session.getAttribute(Globals.LOCALE_KEY);
    %>
    <my:tag attr="<%=mr.getMessage(locale, "abc") %>">

Maybe you are looking for