Access to variable in custom tag

I have a custom tag called sendmail and I use it like this:
<cc:sendmail smtpServer="..." to="..." ....>
</cc:sendmail>
While the SendMailTag are processing the tag, it sets a boolean variable based on if the mail was sent or not. My tag extends BodyTagSupport, and everything works like it is supposed to. What I want to do now, is to allow the developer using the tag to have access to the boolean in the tag representing the status of the mail, inside the body of the tag, so he can do "this" if the mail was sent and "that" if it failed. Something like this:
<cc:sendmail smtpServer="..." to=".." ..>
if(status) {
// tell the user that the message was sent
else {
// present an error message
</cc:sendmail>
Yeah, I can use the bodyContent object to output the variable value, but I want to give the jsp developer the possibility to do whatever he like, based on that boolean value.
Anyone know how I can do this?

Well, your sendmail tag could add the boolean value to the session scope. For example inside your sendmail tag code after you send the mail message, do this..boolean ok = sendMailRoutine();
pageContext.setAttribute("isSent",ok,PageContext.SESSION_SCOPE);then in your jsp page after you call the send mail tag, you can get the boolean value by typing...boolean ok = (boolean)session.getAttribute("isSent");Alternativley, you can create another function in your sendmail tag library to get the isSent boolean value. Say for example you had<cc:isSent messageId="">  or whateverthen the tag code would beboolean ok = pageContext.getAttribute("isSent",PageContext.SESSION_SCOPE);This tag could then send a message back to the browser if the boolean value is false.pageContext.getOut().println("Failed to send message.");Now if your not confused... you don;t have to hard code the value "isSent". You can pass that in through your tag just like you did with the smtpServer and to IDs.
Hope this helps.
-S-

Similar Messages

  • 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

  • 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.

  • Access payroll variables from custom payroll function

    Hi All,
    I have a requirement to create a custom payroll function that returns some data from IT0006 and IT0032.
    I have written the code in PCBURZDE0, as the payroll is for Germany, it does read the data needed.
    My question is, how I can access the variables specified for the function in the payroll schema.
    Schema definition in PE01
    Zeile     Fkt        Par1  Par2 Par3 Par4 D Text
    000010 BLOCK BEG                              Fahrradleasing
    000020 _DFRD &PRO GEN
    000030 BLOCK END
    If I double-click Par1 for function _DFRD (&PRO), then I see he two variables I should write the data to:
    Zeile  VarArg. FZ T Operation        Operation Operation Operation Operation Operation *
           -------------+---------+------------------+---------+---------+---------+---------+
    000010                  AMT= PKWWRPRINT     *
    000020           1     AMT= ENTKM  PRINT
    So, as I understand I should write the two variables PKWWR and ENTKM, I have the values in the function code, but I don't know how to access these variables.
    Thanks for your help!
    Gyöngyi

    1 - PIT is a Function that is used in the Payroll Schema to "Process the Internal Table".
    2 - You mentioned that you had created a Custom Function to read IT0006 and IT0032, and I only suggested to you that you could have that Custom Function generate Information WageTypes and save them in the Input Table where they could then be used in PCRs.
    3 - I did not mention that you can read only one value through operation AMT, but I mentioned that using AMT=xxxxxx followed by AMT=yyyyyy means that the first statement is useless.  On the other hand, using AMT=xxxxxx followed by AMT+yyyyyy and AMT+zzzzzz will result in the amount being the total of the 3 values.
    4 - Please read some documents on Schemas, Functions and PCRs, such as in the Wikis on this site, and study your current Payroll Schema, it's sub-schemas, it's functions and the operations in it's PCRs.  Note that t-code pe01, pe02 and pe04 can be used to find some documentation on functions and operations.

  • 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(...,...)

  • Access JSTL variable outside JSTL tags

    hi
    I have this jstl tag:
    <sql:query var="brands" dataSource="${ds}">
    select brand
    from carbrand
    </sql:query>
    i want to manipulate the brands.rowCount without using the <c:set var="count" value="${brands.rowCount}"/>
    how can I read the ${brands.rowCount} outside the JSTL
    Because I want to use the Math.round, which I think can be use in
    <% Math.round(brands.rowCount/3)%>
    But I think its not reading the right variable or value?

    The variable is put into one of the JSP scope objects. You will be able to access it by using the pageContext.findAttribute("brands") method.
    Note: You will have to know the object's type. So look up the API for the sql tag and see what it is.
    Note: You will have to use brands.getRowCount() not brands.rowCount.

  • How to get accessed to pagecontext in a tag file in JSP2.0

    I am writing a custom tag using JSP 2.0 to clean up the JSP pages for a big website.
    Now a question comes up. I need to access pageContext variable in my tag file since I need to get the bean using a lookup method. I know in JSP2.0 there is jspContext implicit object instead of pageContext. But this is not the end of the story.
    then I read Denis' post. and his solution are these two line codes:
    <%
    PageContext pageCtx = (PageContext)jspContext;
    tagBean.init(pageCtx);
    %>
    I am confused here what the tagBean here. Is that a webBean? and how can I get this object in my tag so that I could initialize the pagecontext and reference it?
    thanks in advance

    The lookup method just returned me a null. So I believe that there is
    some trick behind this simple cast.First I would double check your basic assumptions.
    Is the attribute you are looking up actually there? That would be a simpler explanation for why the lookup method returned null.
    Try a jspContext.findAttribute() , specific request/session.getAttribute() to see if you actually retrieve anything.
    Also be aware that the RequestUtils.lookup() method has been deprecated in Struts 1.2, in favour of org.apache.struts.taglib.TagUtils.lookup().
    Cheers,
    evnafets

  • Custom tag attribute question

    How to assign value of expression or variable to custom tag attribute in jsp?

    I had the same problem in a design a couple of months ago and could not get around it so I switched the functionality into code and out of the tag lib.
    I take it you are trying to do something like this?
    <%
    String value="hiworld";
    %>
    <mytaglib:saysomething value="<%=value%>"/>

  • Orchestration Variable in Custom XSLT in Biztalk Map

    Hi,
    I have a custom xslt for mapping HL7 messages to CRM fields.
    For one field, I 'll get the data from DB so it is stored in my orchestration variable. How can I use that variable in my custom xslt file? Thanks.
    Regards,
    Lakshmi

    Hi Laxme,
    As far I know, there is no way you can access Orchestration variable in custom XSLT.
    Workaround : you can create a intermediate message with a field and assign the variable value (the data from DB) to it and later use message assignment to assign this value to the field which you want to the mesage which you created using custom
    xslt.
    Maheshkumar
    S Tiwari|User
    Page|Blog|BizTalk
    2013: Inserting RawXML (Whole Incoming XML Message) in SQL database

  • 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]

  • Custom taglib access the variable of jsp in the tag class

    Hi guys:
    I have a question about taglib.the scenario below
    there are a set of tag,they all need to access a variable that declare in the jsp.yes ,I can use the approach like this,
    first I declare a variable
    <%!String variable="test";%>
    then pass the value
    <myTag:hello att="<%=variable%>"/>,but I think that's stupid,because all tags access the same variable.why not get the variable in tag class?
    for example
    public int doStartTag() {
    String variable=;//get the variable at here
    I mean,I want to get the variable's value in my tag class directly without passing parameter in the jsp via attribute of tag ?
    can I do like this?if yes,how can I?
    thanks advance!

    Hi,
    Review pageContext, TagSupport from the JSP and Tag Extensions API. You can put the variable into any of the four scopes and retrieve it using the pageContext object.

  • Urgent-how to access custom tag from jsp tag

    I have a problem accessing a custom tag from a jsp expression.
    Details: I have a custom tag that returns a string variable. I need to access that variable from jsp expression <%%>.
    Can any body help me?

    Tags don't "return" values as in the normal sense.
    They can only support TEI (Tag Extra Information) that just stuffs a declared variable into the page's state.
    For example, if the tag class had a public method called getValue(), you could do the following:
    <xmp:mytag id="foo"/>
    <%
    out.println("value is " + foo.getValue());
    %>

  • 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?

  • 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

  • [Custom Tags] Dynamic Variable Name // Spring MVC

    I am having a problem with a tag,
    i try to make a dynamic select tag that is reuseable, the problem is that my spring controller generates a model where i can access the list information for a select and that i have to pass this to the dynamic tag, the model could have different name, so it could be ${listitemsa} ${listitemsb} ${listitemsc} and i want to pass this list to my custom tag.
    i tried the following, but the problem is that the var is passed as a string and not the list, does anybody know how to do this?
    <tag:formfield-selectbox name="listA" path="prototypeForm.selectionA" list="${listitemsa} " />
    <tag:formfield-selectbox name="listB" path="prototypeForm.selectionB" list="${listitemsb} " />
    <tag:formfield-selectbox name="listC" path="prototypeForm.selectionC" list="${listitemsc} " />     
    <%@ tag body-content="scriptless" %>
    <%@ attribute name="name" required="true" %>
    <%@ attribute name="path" required="true" %>
    <%@ attribute name="list" required="false" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %> 
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    <spring:bind path="${path}">
         <c:if test="${status.error}">
              <span class="error">
                   <c:forEach items="${status.errorMessages}" var="error">
                        <c:out value="${error}"/>
                   </c:forEach>
              </span><br />
         </c:if>
         <label for="<c:out value="${status.expression}"/>">${name}: </label>
         <form:select path="${path}">
              <form:option value="-1" label="--Please Select--" />
              <form:options items="${list}" />
         </form:select>
    </spring:bind>

    I've sorted it. Here's the solution for anybody experiencing the same problem.
    The problem is with switching from Java 1.2.1 to Java 1.3.0_02. Custom tags are (as of the JSP 1.1 spec) JavaBean compnents, and the Introspector appears to work differently in different Java versions.
    Consider this example:
    public void setAbc(String abc){}
    public boolean getAbc(){}Since the setter method takes a String and the finder method returns a boolean, the 1.2 Introspector takes the property type to be String, and returns null as the finder name. Java 1.3 (I haven't tested this explicitely, but this is what seems to be happening), returns null for both the setter name and the finder name (Probably a better way to do it, but breaks old code).
    We've rolled back to Java 1.2 and everything works again. It looks to me like the best way to fix the problem for 1.3 is to write custom BeanInfo classes for each JSP custom tag (Can anybody recommend a good JavaBeans book?). I don't yet know what will happen when you have multiple setter methods with different parameter types??? - something I've always found useful in custom tags.
    You don't get the problem on some JSP engines that don't use the Introspector (apparently JRun just puts the method name in the code and lets it fail at runtime if it doesn't exist, whereas apache and iPlanet check the methods exist at compile time).
    Here's where I got most of the answers from:
    http://groups.google.com/groups?hl=en&safe=off&ic=1&th=9330b85b1867cc7,3&seekm=8rnl24%24ef1%241%40nnrp1.deja.com#p
    http://groups.google.com/groups?hl=en&safe=off&ic=1&th=edd3053ac670ff5b,8&seekm=D8E32A666B62F7BD0076240185256A16.0073785185256A15%40webforums#p
    http://groups.google.com/groups?hl=en&safe=off&ic=1&th=7b5480449150ea26,3&seekm=3B2FA8C3.3F14A9F3%40switzerland.org#p

Maybe you are looking for

  • Approval request autoescalation

    The current scenario is like this. User Self Registration -------(Request No:1 is send to Group 1 Users for approval )---------> Group1-----------(atleast one user approves ,Request No:1 is passed to Group 2 users)-----> Group 2. I have achieved this

  • ERROR -50 CAN'T SAVE THE VIDEO

    I can't save the video because the computer says there is the error -50 what it is? thanks guys

  • Can't select rating in smart album

    It is impossible for me to create a smart album where my rating ("Mitt Betyg") is anything other that 4 or 5 stars. If I click in the star field, it is like the field is insensitive to clicks in the first three stars. I have tried this on Macs in a M

  • How to apply a user style with the Stylish extension for Web Developer Tools?

    I have firefox 27 and the fonts of Web Developer Tools (Inspector, Debugger..) are very small. The fonts of Stylish editor are very small also. Here https://support.mozilla.org/en-US/questions/943857 I found a similar question. GingerBread Man said :

  • More WIPEdit plugin customization questions

    Hi, I see from another thread called "WIPEdit plugin customization" that you can NOT remove/hide the tool bars that show up in the MLT (i.e. copy, paste, bold, etc..). I'm just wondering what other options are available as customization?  I see that