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]

Similar Messages

  • How to access report designer in customer system

    How to access report designer in customer system as we dont have direct acces to Customer BI System. Is there sny transaction code for report designer/web application designer or we can go through RRMX.
    Thanks in Advance.

    Hi
    If I got your question properly, You need authorization for the accessing Client System. You can see the Reports at RSRT , RRMX may also lead to Query Analyser.
    Hope it helps

  • 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

  • How to access variables from other class

        public boolean inIn(Person p)
            if  (name == p.name && natInsceNo == p.natInsceNo && dateOfBirth == p.dateOfBirth)
                 return true;
            else
                 return false;
        }//returns true if Person with same name/natInsceNo/dateOfBirth as phello,
    here am trying to compare the existing object with another object.
    could you please tell me how to access the variables of other class because i meet this error?
    name cannot be resolved!
    thank you!

    public class Person
        protected String name; 
        protected char gender;      //protected attributes are visible in the subclass
        protected int dateOfBirth;
        protected String address;
        protected String natInsceNo;
        protected String phoneNo;
        protected static int counter;//class variable
    //Constractor Starts, (returns a new object, may set an object's initial state)
    public Person(String nme,String addr, char sex, int howOld, String ins,String phone)
        dateOfBirth = howOld;
        gender = sex;
        name = nme;
        address = addr;
        natInsceNo = ins;
        phoneNo = phone;
        counter++;
    public class Store
        //Declaration of variables
        private Person[] list;
        private int count;
        private int maxSize;
    //constructor starts
        public Store(int max)
             list = new Person[max];//size array with parameters
             maxSize = max;
             count = 0;
        }//end of store
    //constructor ends
    //accessor starts  
        public boolean inIn(Person p)
           return (name == p.name && address == p.address && natInsceNo == p.natInsceNo);
        }//returns true if Person with same name/natInsceNo/dateOfBirth as phope it helps now!

  • How to access variables outside user exit

    Hi,
    I'm working with a user exit and my problem is that in a particular moment I have to access variables located outside the scope of the user exit (they are in a standard program)
    How can I reach these variables?
    thanks in advance

    Hi,
    If they are global variables then you can access them using Global assign technique,
    For example,
    FIELD-SYMBOLS: <fs_value> TYPE ANY.
    ASSIGN ('(SAPMV45A)XVBAK') TO <fs_value>.
    It is basically,
    ASSIGN ('(<Std. Program Name>)<Variable name>') TO <field symbol>.
    NOTE: To make sure they are accessible in your user exit, just put a break-point in the user exit and once you are there in debugging, type in,
    (<Std. Program Name>)<Variable name> in the Field names section and if it does not show it in RED then it is accessible..
    Hope this helps.. 
    Sri
    Message was edited by: Srikanth Pinnamaneni

  • How to access variables??

    how to access public variables of any other class??
    suppose i have a file temp.java file ..& i know all the public variables. and
    i want to access the variable of those temp.class file which extends JApplet or Applet..
    and as u know it will declare public void init() .. & in this function only all declaration will be there.
    so now how to invoke this init() function from any mymethod()..to access public variables...

    its not working. for me..
    the variable which i m trying to access is non static.. its displays the error :
    Exception in thread "AWT-EventQueue-1" java.lang.Error: Cannot call invokeAndWait from the event dispatcher thread
    and by one method i have connected database also.. and it has been called from init()..
    i have collected the data from the database..and i m storing the data in one ArrayList ..
    and i want to access that ArrayList..

  • How to Access Variables defined in the PopUpWindow

    Hi Friends
    I am building a flex site using flex builder 2.....
    Here I need your help.....
    My Problem is how to store a variable from a popup window
    I have this problem while in the login window comes as popup
    while clicking login button in the page a popup where user
    can enter username and password...
    after submitting if the login is successufl the popup
    vanish...
    After a successful login I need to store the logged user name
    in the main index page but I am not able to store
    At first I created a variable 'loggedUsername' in the popup
    panel and after success log i assigned the username to it ... after
    it i am not able to get the loggedUsername..
    doubting I defined the variable in the main index.mxml page
    but this variable is not accessible from the loginwidow.mxml page
    where the popup will function...
    Heip me
    how to store the name if the user login is success..
    thanks
    Chintu...

    Lets say you have a public property in your application like
    public var name:String = "John Smith";
    to access this using an inline item renderer:
    <mx:itemRenderer>
    <mx:Component>
    <mx:VBox>
    <mx:TextInput text={outerDocument.name} />
    </mx:VBox>
    </mx:Component>
    </mx:itemRenderer>
    To access variables of the applicaton you can use
    Application.application.name (for example) to reference "global"
    variables, so you might also use this technique. With an inline
    item renderer, the outerDocument property will refer to the
    component which contains the renderer.

  • How to access variables declared in java class file from jsp

    i have a java package which reads values from property file. i have imported the package.classname in jsp file and also i have created an object for the class file like
    classname object=new classname();
    now iam able to access only the methods defined in the class but not the variables. i have defined connection properties in class file.
    in jsp i need to use
    statement=con.createstatement(); but it shows variable not declared.
    con is declared in java class file.
    how to access the variables?
    thanks

    here is the code
    * testbean.java
    * Created on October 31, 2006, 12:14 PM
    package property;
    import java.beans.*;
    import java.io.Serializable;
    public class testbean extends Object implements Serializable {
    public String sampleProperty="test2";
        public String getSampleProperty() {
            return sampleProperty;
    }jsp file
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="java.sql.*,java.util.*"%>
    <html>
    <head>
    <title>Schedule Details</title>
    </head>
    <jsp:useBean id="ConProp" class="property.testbean"/>
    <body>
    Messge is : <jsp:getProperty name="msg" property="sampleProperty"/>
    <%
      out.println(ConProp.sampleProperty);
    %>
    </body>
    </html>out.println(ConProp.sampleProperty) prints null value.
    is this the right procedure to access bean variables
    thanks

  • How can i use JSTL inside custom tag attribute

    Hi,
    I have one button tag which displays the button with round corner. I will show the button like this:
    <ep:button key="buttons.submit" name="submitBtn" styleClass="But"
              onClick='submitPage(''<c:out value='${buttonName}' />)' />
    I am getting the problem with the above code. how can i use JSTL inside the custom tags.
    Thanks in Advance,
    LALITH

    No. The details are given below:
    I have included the follwing line in web.xml file:
    <taglib>
        <taglib-uri>/tags/button</taglib-uri>
        <taglib-location>/WEB-INF/button.tld</taglib-location>
      </taglib>button.tld file
    <taglib>
         <tlibversion>1.0</tlibversion>
         <jspversion>2.0</jspversion>
         <shortname>button</shortname>
         <tag>
              <name>button</name>
              <tagclass>com.ksi.ep.web.taglib.ButtonTag</tagclass>
              <bodycontent>empty</bodycontent>
              <attribute>
                   <name>name</name>
                   <required>true</required>
                   <rtexprvalue>false</rtexprvalue>
              </attribute>
              <attribute>
                   <name>key</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
              </attribute>
              <attribute>
                   <name>onClick</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
              </attribute>
    </taglib>ButtonTag.java :
    public class ButtonTag extends TagSupport {
       private static final long serialVersionUID = 6837146537426981407L;
         * Initialise the logger for the class
        protected final transient Log log = LogFactory.getLog(ButtonTag.class);
         *  holds the Value of the button tag
        protected String onClick = null;
         *  holds message resources key
        protected String key = null;
         * The message resources for this package.
        protected static MessageResources messages =
                             MessageResources.getMessageResources
                                       ("ApplicationResources");
          *  (non-Javadoc)
          * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
         public int doStartTag() throws JspException {    
            StringBuffer label = new StringBuffer();         
            HttpServletRequest request = (HttpServletRequest)pageContext.getRequest();
            try {             
                   log.debug("in doStartTag()");
                   Locale locale = pageContext.getRequest().getLocale();
                 if (locale == null) {
                     locale = Locale.getDefault();
                 log.info("");
                 label.append("<a border=\"0\" style=\"text-decoration:none;color:#FFFFFF\" href=\"JavaScript:");
                 label.append(onClick);
                 label.append("\" >");
                   label.append("<table  onClick=\"");
                   label.append(onClick);               
                   label.append("\" ");
                   if(onmouseout!=null && !"".equalsIgnoreCase(onmouseout))
                    label.append(" onmouseout=\"");
                    label.append(onmouseout);               
                    label.append("\" ");
                   if(onmouseover!=null && !"".equalsIgnoreCase(onmouseover)){
                    label.append(" onmouseover=\"");
                    label.append(onmouseover);               
                    label.append("\" ");
                   if(title!=null && !"".equalsIgnoreCase(title)){
                    label.append(" title=\"");
                    label.append(title);               
                    label.append("\" ");
                   label.append("style=\"cursor:hand\" tabindex=\"1\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" background=\"");
                   label.append(request.getContextPath());
                   label.append(System.getProperty("file.separator"));
                   label.append("images");
                   label.append(System.getProperty("file.separator"));
                   label.append("background1.jpg\" > ");
                 label.append("<tr><td width=\"10\"><img  border=\"0\" src=\"");
                 label.append(request.getContextPath());
                   label.append(System.getProperty("file.separator"));
                   label.append("images");
                   label.append(System.getProperty("file.separator"));
                 label.append("leftcorner.jpg\" ></td> ");
                 label.append("<td valign=\"middle\"  style=\"padding-bottom:2px\"><font color=\"#FFFFFF\" style=\"");
                 label.append(styleClass);
                 label.append("\">");
                 label.append(messages.getMessage(key));
                 label.append("</font></td>");
                 label.append("<td width=\"10\" align=\"right\"><img src=\"");
                 label.append(request.getContextPath());
                   label.append(System.getProperty("file.separator"));
                   label.append("images");
                   label.append(System.getProperty("file.separator"));            
                 label.append("rightcorner.jpg\" border=\"0\"  ></td>");
                 label.append("</tr></table></a>");
                 pageContext.getOut().print(label.toString());
              } catch (Exception e) {               
                   log.error("Exception occured while rendering the button", e);
                   throw new JspException(e);
            return (SKIP_BODY);
         * Release all allocated resources.
        public void release() {       
            this.name=null;
            this.key=null;
            this.onClick=null;
    }In my JSP I have mentioned the taglib directive as
    <%@ taglib uri="/tags/button" prefix="ep"%>and
    <ep:button key="buttons.submit" name="submitBtn" styleClass="But"
         onClick='overwritePreApprovals('<c:out value='${transactionalDetails['inPrepList']}' />')' />Servlet.service() for servlet action threw exception
    org.apache.jasper.JasperException: /pages/pms/coordinator/Dashboard.jsp(325,48) Unterminated <ep:button tag
    Thanks,
    LALITH

  • How to access variables declared in main mxml in itemrenderer files

    Hi,
    I have a main mxml which has a cutomRenderer that defines two
    mxml components
    namely raidobutton and textinput.
    Now in this TextInput.as i need to access variable defined in
    main mxml.
    Please suggest a way.
    Thanks,
    Lucky

    Lets say you have a public property in your application like
    public var name:String = "John Smith";
    to access this using an inline item renderer:
    <mx:itemRenderer>
    <mx:Component>
    <mx:VBox>
    <mx:TextInput text={outerDocument.name} />
    </mx:VBox>
    </mx:Component>
    </mx:itemRenderer>
    To access variables of the applicaton you can use
    Application.application.name (for example) to reference "global"
    variables, so you might also use this technique. With an inline
    item renderer, the outerDocument property will refer to the
    component which contains the renderer.

  • Dynamic include inside custom tag body

    I am trying to perform the dynamic include of another JSP from within the body of a custom tag using JSP1.1. It cannot be done using <jsp:include> since flush=true is required and thus an exception is thrown when called from inside the body of a custom tag - it can be done in JSP1.2 since flush does not have to be set to true but upgrading is not possible at this time.
    Does anyone know of any custom tag or the code needed to perform this function with JSP1.1?
    I am using Tomcat 3.2.3.
    Using a RequestDispatcher and calling include() does not have the desired effect since the output is witten directly to the response and does not go into the correct position in the calling JSP.
    I think the solution involves making a call to the included JSP (is it possible to use a RequestDispatcher that doesn't write directly to the page output stream?) and then append the response to the BodyContent object which is buffering the body content of the custom tag until the doAfterBody() method is called. Is it possible to create a dummy ServletResponse object to pass to the RequestDispatcher and then obtain the HTML response from the internal buffer?

    I don't know if there is a solution to the problem you are having with JSP 1.1. If you look in the spec, it actually warns you that dynamic includes can not be done inside a body tag. The spec actually states that the included code shout write directly to the response and not to the BodyContent.
    I was excited to find out they had fixed this in JSP 1.2, but they seem to have foiled me again. If my tag calls PageContext.include(), the spec says that include must call the flush method, which causes BodyContent to throw an exception since flush is not a valid call.

  • JSF custom tag body content problem

    Hi, I'm having some problem with a custom tag I built, but the body of the tag content is not rendered correctly.
    I have:<foo:bar>
        <ul>
            <li>blah</li>
            <li>blah</li>
        </ul>
    </foo:bar>
    </pre>But the rendered html source look like this:    <ul>
            <li>blah</li>
            <li>blah</li>
        </ul>
    <!-- beging foo tag -->
    <!-- end foo tag -->The <ul> tags are supposed to be inside of the <!-- begin foo --> & <!-- end foo -->. I've declared in TLD it has JSP content. I've compared to the J2EE tutorial and corejsp book again and again, couldn't figure where I went wrong. So, am I missing something?
    Thanks a lot.

    Use <f:verbatim> around the non-jsf content.
    I.e.<foo:bar>
    <f:verbatim>
        <ul>
            <li>blah</li>
            <li>blah</li>
        </ul>
    </f:verbatim>
    </foo:bar>--
    Sergey : jsfTutorials.net

  • How to access variables in dynamically created custom components? (Flex 4.5)

    Hi i have another riddle here.
    i have few custom MXML components in my library and i am adding them to the stage by script, after that i want to fill some data, lets say Label.text, inside this component.
    The question is how to acces / reference variables or other components inside the main custom component which was added to the stage by script???
    thx M.

    ok, the answer is here
    http://blog.flexexamples.com/2008/08/28/creating-a-component-instance-by-class-name-in-act ionscript-30/

  • In tag body how to access variable defined outside?

    Suppose the following jsp fragement: <% String x = "wwlhp"; %>
    <c:mytag>
      want to use variable x defined above
    </c:mytag>  anyone have ideas about which approach should i take? Thx a lot!

    Sorry, I have made a terrible mistakes:).

  • How to access variables across JSP and JavaScript?

    Hi,
    I have some .js files and in those files, some of the methods need to access to the variables that I'd declare in the jsp files. How do I do it?
    Anne

    You can do it this way, but I'm not sure if this is what you had in mind.
    Say you had a java variable called XString. And you wanted to display
    the value of XString in a javascript Alert. Here's how:
    <html>
    <body>
    <% String XString = "Hi There!"; %>
    </body>
    <script language="javascript">
    alert("<%=XString%>");
    </html>Hope This Help,
    P.

Maybe you are looking for

  • How can I get my iTunes to start up after a clean re-install?

    Following the corruption of many of my Applications and Files, I had to have a Clean Re-install done. That solved most of the problems, but when I try to start iTunes it comes up with the iTunes Software Licence Agreement. When I click on Agree, I ge

  • Send an output with dispath time 3, from an external report.

    Hi, It would be very appreciated if someone could help us with the following question:    We have an output message in a shipment which print a form.    This output is defined with dispatch time 3 ‘Send with application own transaction’.    Then we h

  • How to track harm process

    Hi, all! our sysadmin discovered that from my computer is sending spam. Antivirus programms can't find the virus. Ofcouse, it seems it is not virus, but the working process. Maybe someone have any idea how to track this process? Thanks in advance.

  • For all entries on custom tables

    i have created 2 custom tables::zhospital_info n zpatient_info.. zhospitalinfo tab fields:::_ doc_name::prim key patient_name:::prim key place::prim key zpatientinfo tab fields::_          ZDATE ::prim key          JOINING          MEDICINE         

  • Workflow Ends in Error " No auth to send IDocs with message type ORDRSP"

    Hello All, I have created an RFC user with limited Authoprizations including WE* tciodes and a few ME* transactons for an ALE Set up. I want to make sure i would not be giving more authorizations (extensive) to this RFC user and assign Just required