Variable declaration in the custom tag

Hey,
I am using JSP2.0 to write a custom tag. and I need to declare a script variable in my tag so that it can be referenced in a jsp file. At the beginning, I used name-given and my tag works as it supposed to do. But I don't like to make the variable name hard-coded in my tag so that I changed name-given to name-from-attribute as folllows:
<jsp:directive.variable name-from-attribute="var" alias="local" variable-class="java.util.ArrayList" scope="AT_END"/>
<jsp:scriptlet>
out.println(local.getClass().getName());
</jsp:scriptlet>     
According to my understanding, variable "local" should be able to be referenced in my tag file and when the tag created in a jsp file
<tags:myTag var="myTest" />
the variable myTest should be able to be referenced in this jsp file too. But whenever I try this in jsp: out.println(myTest.getClass().getName());
I always got this error" myTest cannot be resolved"
I am totally stuck here. Someone could please give me some hints? thanks a lot!

Do you have a getter method to match that property?
Post some example code - what does your tld define for this property, and what get/set methods have you defined for it?

Similar Messages

  • 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

  • New to JSTL: jsp variable translated literally within the custom tag

    I have a basic custom tag that simply processes greeting. Neither of the below scenarios works and I am trying to understand why
    <%
    String name = (String)request.getParameter( "name" )
    %>
    <custom:greeting name="<%= name %>"/>
    <%
    pageContext.setAttribute( "name", name );
    %>
    <custom:greeting name="${name}"/>
    If you have any suggestions, I look forward to hearing from you.

    When i ran the code I get my "Hello <%= name %> "or "Hello ${name} "
    My source
    public class HelloTag extends TagSupport{
    public String name = "World";
    public void setName( String value )
    name = value;
    public int doEndTag()
    try{
    pageContext.getOut().println( "Hello " + name );
    }catch( IOException e){}
    public HelloTag()
    super();
    What do you mean by jsp level. It resides in my Root directory under Tomcat

  • Setter method not getitng called in the custom tag

    Hi,
    I have written a custom tag and I have declared an attribute in the tld file and have specified the setter method for the same in the java tag file but that setter method is not getting called...for rest of the attributes, the methods are getting called and not just for one!! any idea what could be the problem....
    Regards
    Deepak Saini

    Do you have a getter method to match that property?
    Post some example code - what does your tld define for this property, and what get/set methods have you defined for it?

  • Help with the custom tag

    Hi
    i want to make a custom tag encapsulating certain functionalities of existing tags in one tag namely tomahawk dataPanel and html facets.
    Where can I get the source for html jsf tags so that I can look into it and modify.
    Thanks

    Originally posted by: mbuc.edp-progetti.it
    Would you like to know a fine workaround?
    If you have in your jsps a reference to the tld like this:
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    make a C:\WEB-INF\ directory on your PC and copy in there your tlds
    (C:\WEB-INF\struts-html.tld). The same for linux: /WEB-INF/struts-html.tld.
    So you do not have to change anything in web.xml nor in the jsp pages!
    Bye,
    Marco.
    "marco" <[email protected]> ha scritto nel messaggio
    news:cfhrgj$bcj$[email protected]..
    > Davis,
    > thanks for the reply. I followed your suggestion and now I am able to see
    > the code assist working.
    > I am currently using the lomboz editor, but one thing that is missing in
    > lomboz and is present in the structured editor (and in Intellij Idea) is
    the
    > ability to see where a tag is opened and closed, also for html tags.
    Perhaps
    > to someone this should seem not so important, but for me it is very
    usefull!
    >
    > As a first impression, I can only make a lot compliments to both
    > contributions (ObjectWeb and IBM).
    >
    > Bye,
    > Marco.
    >
    >
    > "David Williams" <[email protected]> ha scritto nel messaggio
    > news:[email protected]..
    > >
    > > No, you're not missing anything. Its just with that version of code the
    > > "tld resolver" (that knows where to look for TLD's) is not correct. I
    > > haven't tried it with struts, but with a minor test I tried,
    > > I just made a copy of the TLD to put in the same folder as the JSP file.
    > > Then the editor (and content asssit), can find it and all should be ok.
    Of
    > > course, I'm not suggesting this for a long term solution, but just to
    see
    > > if it allows you to get a little further in evaluating overall.
    >
    >

  • How to clear the custom tags in the phonebook?

    some time create a label on the agenda of the phone contacts, your name is "profile", but now I want to delete because it is no longer useful, but not how to delete this custom tag.
    I want to know how can i delete this custom tag?

    Hi,
    We need to use FREE statement.
    please do this way:
    For
    form exit_program .
      call method cc1->free.
      call method cc2->free.
      call method cc3->free.
      call method cc4->free.
      call method cl_gui_cfw=>flush.
      if sy-subrc <> 0.
        call function 'POPUP_TO_INFORM'
          exporting
            titel = lv_repid
            txt1  = 'Error in Flush'(500)
            txt2  = sy-subrc.
      endif.
    endform.                    " exit_program
    module user_command_0100 input.
      case sy-ucomm.
        when 'BACK'.
          perform exit_program.
          set screen '0'.
        when 'EXIT' or 'CANC'.
          perform exit_program.
          leave program.
      endcase.
    endmodule.                 " USER_COMMAND_0100  INPUT
    thanx.

  • How to create the customizing TAG coloum in So10  transaction

    Hi All,
      I need to create the Tag Coloum in in SO10 ( standard text) transaction .
    Basically i want to create the customised tag format and attach it to the format where we will see all the standard tag in so10.
      I need to create the TAG in which first line should be start from 0.00 and from the second line onwards it should be start from the 2.3 .
    Dhiraj.

    Dhiraj,
    What you will have to do is to create a separate STYLE in sMART FORMS transaction and assign that STYLE to the TEXT in S010. You can do that Format --> Change STYLE.
    The tag column contains format keys which define the output formatting of the text or initiate control commands. The format keys possible and their respective meanings are defined in styles or forms. If a style or form is assigned to a text module you can use the paragraph formats defined there to format your text. Format keys which can be defined by the user can consist of one or two characters.
    I have not tried this though.
    regards,
    Ravi
    Note : Please mark the helpful answers

  • Problem in recognising instance variables declared in the class

    Hi all,
    I am trying to deploy an Servlet desiged in WebObjects5.1 application server on application on Iplanet Application server 6.5
    Back ground: All of you might be aware that WebObjects5.1 is an J2ee compliant application server. When an application is designed in WebObjects, it creates a WAR file which can be deployed on any J2ee complaint application server.
    I tried to create such application in WebObjects and tried to deploy on IplanetApplication server6.5(running on Windows using IIS web server).
    I am able to successfully deploy the application. But inorder to do this i had to manually add ias-Web.xml file to the war file generated( gave some arbitrary global id). The aplication just consists some string displaying hello world.
    Now when i try to deploy an application which has some instance variables, the instance variables are not getting recognised. This application works fine on WebObjects5.1. But variables are not getting recognised when deployed iplanet application server
    Has any one faced such kind of problem earlier? If yes please help me out
    Thanks
    Venkatesh

    Hi,
    Please send me your servlet code and war file.
    Thanks

  • How to access variables passed in custom tag body

    I am developing custom tags in my application. I need to pass some variables from the .jsp file into tag file. I want these to be passed as body of the tag rather than as tag parameter. It seems the correct syntax for this is:
    <myTags:display> someVariable </myTags:display>
    Question 1: Can I not use this as: <myTags:display someVariable /> Since this tag will be used at many places in the jsp, I dont want to write myTags:display twice for every usage.
    Question 2:
    I want to call the tags from main.jsp like:
    <% String var1 = "Display Me Please"; %>
    <myTags:display var1 />I want the tag file to do some processing on the value stored in var1. I've written the following code in tag file, display.tag:
    <jsp:doBody var="theBody" />
    <% Object obj = (Object) request.getAttribute ("theBody"); %>This code snippet gives me access to obj which has the value "var1". Now how do I access the value that is contained in "var1".
    Edited by: coolkomal on Jun 3, 2009 7:45 AM

    coolkomal wrote:
    I am developing custom tags in my application. I need to pass some variables from the .jsp file into tag file. I want these to be passed as body of the tag rather than as tag parameter. It seems the correct syntax for this is:
    <myTags:display> someVariable </myTags:display>
    Question 1: Can I not use this as: <myTags:display someVariable /> Since this tag will be used at many places in the jsp, I dont want to write myTags:display twice for every usage.
    <myTags:display var="<%=someVariable>"/> is a valid syntax for performing respective action of that variable. You can also use EL to pass the variable ${someVariable} provided the custom tag provide support for EL.
    >
    Question 2:
    I want to call the tags from main.jsp like:
    <% String var1 = "Display Me Please"; %>
    <myTags:display var1 />
    Just ensure that you declare all the related variables in Main.jsp and statically include Main.jsp in your jsp such that you do the checking
    [http://java.sun.com/products/jsp/tags/11/syntaxref117.html]
    >
    I want the tag file to do some processing on the value stored in var1. I've written the following code in tag file, display.tag:
    <jsp:doBody var="theBody" />
    <% Object obj = (Object) request.getAttribute ("theBody"); %>This code snippet gives me access to obj which has the value "var1". Now how do I access the value that is contained in "var1".Can be done provided you code it the right way. Start learning basics of how to create custom taglibraries to gain more knowledge on how things can be managed.
    [http://java.sun.com/javaee/5/docs/tutorial/doc/bnalj.html]

  • How can I use evaluate to get the instance variable in customized tag

    1.
    At first , I create a class called bean,and declared several params in it and do not define any getter function for the param.
    class bean{
    String param = "test";
    SomeClass scObj = new SomeClass();
    2.
    The second ,I use
    request.setAttribute("beanObj",new bean());
    3.
    And then I wanna use the customized tag to show a text box , then initialize it's value.
    <salt:text name="param" value="beanObj.param">
    <salt:text name="obj" value="beanObj.scObj.func()">
    4.
    I tried the evaluator provided by JexlContext ,Struts, JSTL and it seems that if I do not define the getter for the variable ,I can not get the bean's instance variable's value.
    Expression e = ExpressionFactory.createExpression( value );
    JexlContext jc = JexlHelper.createContext();
    jc.getVars().put(strInitBeanName, request.getAttribute("beanObj"));
    Object obj = e.evaluate(jc);
    the result of the obj is null....
    Can anybody recommand some other evaluator can get the value of a instance variable from an object?

    do you have any other suggestion ? Nops, somebody else may have though. AFAIK, all lookups of the type
    beanName.propertyNameuse reflection on the getXXX() methods to access the property.
    Having said that, I guess you could write one though in a custom tag, using the same - reflection (you will ahve to rely on the java.lang.reflect.Field class quite heavily) - but that would be reinventing the wheel for most other functionality that you would have to include (like looking up the bean in scope etc)
    cheers,
    ram.

  • How to use a variable of jsp custom tag in my java code?

    hi folks,
    i got a folderList tag like this:
    ArrayList list = new ArrayList(20);
    %>
    <foo:folderList path="${attributes.newsPath}" var="year" contentType="folder">
    <%
              list.add(${year.contentEntryName});   // of course, this doesn't work
    %>
    </foo:folderList>I think, its clear what I want to do. I am just wondering how I can use my Variable "year" in the Java code between <% %>...

    <% list.add(year.getContentEntryName()); %>
    You have to have defined in the custom tag that "var" relates to a scripting variable that you want defined.
    <tag>
      <variable>
        <name-given>var</name-given>
        <variable-class>myPackage.myClass</variable-class>
        <declare>true</declare>
        <scope>NESTED</scope>
      </variable>
    </tag> Cheers,
    evnafets

  • Accessing JSP Variables in Custom Tag Handler.

    Hi,
    I am creating a custom tag which builds a list view. I have certain String array in my JSP and I need to pass the same into my Tag Handler class. I tried following ways :
    1. In doStartTag() implementation I used
       public int doStartTag() {
             String[] myArray = (String[])pageContext.getAttribute("mystringarray", PageContext.PAGE_SCOPE;
       }This is not recognizing the String array variable defined in my JSP.
    2. I used separate attribute which is passed from the JSP to the custom tag as parameter having "rtexprvalue" as true. But I cann't pass a Sting array into my tag handler class. I can pass only String.
    How can I access variables which are defined in the JSP using declaration block. i.e.
    <%!
    String[] myArray = new String[100];
    %>
    Thanks for the time.

    You should be able to pass any type you like as an attribute to the tag.
    You just have to define its type as String[] in your tld:
    <attribute>
    <name>stringArray</name>
    <required>false</required>
    <rtexprvalue>true</rtexprvalue>
    <type>java.lang.String[]</type>
    </attribute>
    Alternatively, If you declare your array like:
    <%!
    String[] myArray = new String[100];
    %>You can do this:
    pageContext.setAttribute("mystringarray", myArray);
    which will put it into the page context for you to pick up in your custom tag.
    Hope this helps,
    evnafets

  • Template declaration error when variable assigned is the same as variable declared

    Hi Fedor,
    In comm-central repository, when compiling mozilla/mfbt/Compression.cpp using -std=c++11, it results in an error as follows:
    "../dist/include/mozilla/CheckedInt.h", line 400: Error: Unexpected type name "T" encountered.
    "../dist/include/mozilla/CheckedInt.h", line 400: Error: value is not defined.
    "../dist/include/mozilla/CheckedInt.h", line 400: Error: No direct declarator preceding ">".
    "../dist/include/mozilla/CheckedInt.h", line 400: Error: A declaration does not specify a tag or an identifier.
    "../dist/include/mozilla/CheckedInt.h", line 400: Error: Default template argument cannot be specified on the definition of a class template member that appears outside of its class.
    "../dist/include/mozilla/CheckedInt.h", line 400: Error: Templates can only declare classes or functions.
    "../dist/include/mozilla/CheckedInt.h", line 413: Error: No primary specialization for partial specialization NegateImpl<T, 0>.
    "../dist/include/mozilla/CheckedInt.h", line 416: Error: Too many arguments for template mozilla::detail::NegateImpl<T>.
    8 Error(s) detected.
    After a check on the file CheckedInt.h, it was narrowed down to the following code that resulted in the failure (the variable assigned, isSigned is the same as variable being declared) :
    template<typename T, bool IsSigned = IsSigned<T>::value>
    struct NegateImpl;
    This code, however compiles without problems in gcc-4.8.
    A workaround was to use a different variable declared in the template (e.g. bool IsTSigned = IsSigned<T>). But I just wanted to be sure whether is this a bug in 12.4 Beta or whether coding rules in templates do allow this kind of declaration? Kindly advise. Thanks.
    Regards,
    Brian

    Hi Steve,
    The declaration made below is not valid when -std=c++11 is not used (it causes the same compile-time errors when using July Refresh):
    template<typename U> class IsSigned;
    template<typename T, bool IsSigned = IsSigned<T>::value>
    struct NegateImpl;
    So far, the workaround was to use a different variable declared in the template (e.g. bool IsTSigned = IsSigned<T>).
    Regards,
    Brian

  • Why can't i edit the variable declaration in Netbeans GUI Applications?

    When i drag and drop jbutton,jlabel and other tools from toolbox on the jform the code is
    automatically generated by the Netbeans.
    At bottom the variable declaration for the jbutton and for the other tools is automatically
    generated.
    The part of that declaration is shaded as grey.
    Is it possible to edit those variables from Netbeans?

    Yup, as Chuck states, it is possible to edit that region of code, since the file is nothing more than a text file, but doing so "breaks" the code so that you cannot modify the GUI content in NetBeans WYSIWYG form editor. Please note, that there are ways of changing the characteristics of those variables without editing them directly. You should look into how to change properties of your GUI with NetBeans. The online tutorials can show you how.

  • How can a custom tag write multiple fragments in the response ?

    I have a custom tag that needs to write at least 2 html/xhtml fragments into the response in order to be html compliant. The custom tag outputs a script that must be located in the head section and other elements that refers to the script.
    Events handlers of html input elements follow this pattern. The handler may need to refer to script functions defined in the head section of the document.
    Is it possible with the custom tag architecture to handle this scenario ?

    I don't think so, unless the tag wraps the entire page, but that's harder to do. Maybe a tag could wrap the whole page and you could have another inner tag that acts as a marker of where to put things (kinda like Jakarta Commons Tiles tags).
    Otherwise, you could use 2 tags and share data put in the request scope by the header tag in the subsequent body tags.
    Or since you are writing Javascripts with the one tag, you don't strictly need to put the JS in the head. Although I'm not sure about that restriction in XHTML.

Maybe you are looking for