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.

Similar Messages

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

  • 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

  • Using JSTL variables in JSP or Javascript. Possible ?

    Hi All,
    Is it possible to share or use the variables which are declared are used by JSTL in JSP expression or scriplet code and in Java Script.
    Example:
    This Works:
    <fmt:set var="test" value="JSTL" />
    <fmt:out value="${test}" />
    But, this gives error:
    <% out.println(test) %>
    And passing the value of variable 'test' to Java Script code also gives error.
    How to use JSTL variables in JSP and in Javascript ?
    Yours,
    Sankar.B

    By default, JSTL variables are kept in servlet
    attributes. Default is to store it in the page
    context. You can make it request/session/application
    scope as required by an attribute of the set tag.Hi there,
    Can anyone advise how to access JSP variables in JSTL?
    Can it be done as the same method through request/session/application scope?
    Thnks...

  • 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

  • Accessing a variable declared in another form

    Can someone tell me how I access a variable outside from the form it was declared in? I've tried examples but they haven't worked.

    There are many right ways and many wrong ways to do what you want, the two below (one code example) and one link to a demo project are but two ways to do this.
    A simple example, form1 as two buttons, form2, two buttons, one text box. This replies on knowing the parent form.
    Public Class Form1
    Public SomeVar As String = "Karen"
    Public Property SomeProp As Integer = 4
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim f As New Form2 With {.Owner = Me}
    Try
    f.ShowDialog()
    Finally
    f.Dispose()
    End Try
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    MessageBox.Show(Me.SomeVar)
    End Sub
    End Class
    Form2
    Public Class Form2
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim MyParent As Form1 = CType(Me.Owner, Form1)
    MessageBox.Show(MyParent.SomeProp.ToString & Environment.NewLine & MyParent.SomeVar)
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim MyParent As Form1 = CType(Me.Owner, Form1)
    MyParent.SomeVar = Me.TextBox1.Text
    End Sub
    End Class
    The following link has a project which is much more involved, I allow non-modal forms to pass data between the two in real time and both forms stick to each other.
    https://onedrive.live.com/redir?resid=a3d5a9a9a28080d1!727&authkey=!AEQ4n6P1H4sD6QI&ithint=file%2czip
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.

  • Accessing a JSTL variable in a JSP Scriptlet (need to replace string )

    I have
    <c:set var="myVar" value="..." />
    I need to replace single quotes and double quotes to be escaped because I pass them into javascript functions and set them as ID for div sections
    ... onclick ="func('${myVar}')" ..
    <div id="${myVar}">
    but if the string contains ' single quotes it messes up the javascript or double quotes messes up the ID portion of the HTML tag
    I know there is the JSTL function fn but I can't figure out how to do it properly in JSTL
    <c:set var="myVar"
    value="${fn:replace(myVar, "'", "\"")"/>
    But that gets tricky since the value portion is enclosed in quotes
    So I was thinking of using a Scriptlet part instead.

A: Accessing a JSTL variable in a JSP Scriptlet (need to replace string )

escaping quotes within quotes within quotes.... ARGH!
Recipe for a headache if ever there was one.
However you must be strong and resist the temptations of the dark side (Scriptlet code)
My suggestion for cleaning this up - write your own static function for escaping javascript strings.
public static String escapeJavascriptString(String s){
  return .......
}Then define the function in a tld:
<function>
    <description>
      Escapes a string for javascript purposes
    </description>
    <name>escapeJavascript</name>
    <function-class>com.mypackage.ELFunctions</function-class>
    <function-signature>java.lang.String escapeJavascript(java.lang.String)</function-signature>
    <example>
      <c:out value="${myfunc:escapeJavascript(name)}">
    </example>
  </function>Cheers,
evnafets

escaping quotes within quotes within quotes.... ARGH!
Recipe for a headache if ever there was one.
However you must be strong and resist the temptations of the dark side (Scriptlet code)
My suggestion for cleaning this up - write your own static function for escaping javascript strings.
public static String escapeJavascriptString(String s){
  return .......
}Then define the function in a tld:
<function>
    <description>
      Escapes a string for javascript purposes
    </description>
    <name>escapeJavascript</name>
    <function-class>com.mypackage.ELFunctions</function-class>
    <function-signature>java.lang.String escapeJavascript(java.lang.String)</function-signature>
    <example>
      <c:out value="${myfunc:escapeJavascript(name)}">
    </example>
  </function>Cheers,
evnafets

  • Re:using javascript variable in jstl tag

    Hi,
    Can we access javascript variable in a jstl tag..
    For example
    function clickGroupByPO()
    var brand="hello";
    <c:set var="Var" value="${brand}" />
    alert("${Var}");
    I am geeting balnk in the alert.. I want to assign brand to value attribute in <c:set>
    Thanks and Reagrds,
    radha

    Doublepost, please proceed here: http://forum.java.sun.com/thread.jspa?threadID=5233323

  • How to use jstl variable in a jsp page

    Hi all,
    I am new to JSTL and i want to access the value of jstl in jsp.
    when i use the tag like below it is displaying the value ""
    <c:out value="${ack}"/>
    But as ack is string, i want to convert it into int. and i have written like
    <c:set var="ackvalue" value="${ack}"/>
    and int ack = Integer.parseInt(ackvalue);
    But it is showing error like varialbe can not be resolved: ackvalue
    can anybody please help me regarding this?
    Waiting for your warm response.
    Thanks in advance

    Hi,
    Thanks for your immediate reply.
    I am able to display the ackvalue when i am using
    <c:set var="ackvalue" value="${ack}"/>
    and <c:out value="${ackvalue}"/>
    But my actual requirement is to use the ack value in
    switch statement. if i can assign the value to a
    String variable, then it si easy for me to proceed.
    Please help me in this regard.
    Thanks,You can use the c:choose, c:when and c:otherwise tags
    <c:choose>
        <c:when test = "${ackvalue == 1}">
               //do stuff
        </c:when>
        <c:when test = "${ackvalue == 2}">
               //do some other stuff
        </c:when>   
       <c:otherwise>
              //stuff
        </c:otherwise>
    </c:choose>ram.

  • How to get java variable in jstl???

    Hi,
    I am wondering the way to retrieve or set java variable in jstl.
    <%
    String str="123";
    %>
    <c:set var='str'> <<?????
    Edited by: gohgss on Oct 17, 2007 9:30 AM

    No, they exist in different 'places'. The JSTL variables are in one of four scopes ( page, request, session or application ) while the scriptlet variables are simply local to the _jspService() method of the translated JSP.
    It's not recommended to mix up scriptlets and EL/ custom tags.
    But if you do need to you can do this:
    <%
    String str="123";
    request.setAttribute("str", str);
    %>
    <c:set var='str'>  //now you can work with str, but it'll be happening via the requestScope----------------------------------------------------------------
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • How to access XML attributes with JSTL

    Hello,
    I'm using the XML functions of JSTL. I'm trying to parse the following RSS feed.
    http://weather.yahooapis.com/forecastrss?p=USNY0996
    I can get it parsed and access the elements via JSTL, but is it possible to access the attributes of some of the elements?
    For example, how can I get the city attribute out of
    <yweather:location city="New York" region="NY" country="US" />

    Hello,
    I'm using the XML functions of JSTL. I'm trying to parse the following RSS feed.
    http://weather.yahooapis.com/forecastrss?p=USNY0996
    I can get it parsed and access the elements via JSTL, but is it possible to access the attributes of some of the elements?
    For example, how can I get the city attribute out of
    <yweather:location city="New York" region="NY" country="US" />

  • Processing Dynamic Variable in JSTL

    I have problem getting the result of a JSTL variable dynamically. Here is the scenario.
    I have defined messages for some status values as follows in the page.
    <c:set var="messagestatus1a" value="Less than 30 days with ME" /> <c:set var="messagestatus1b" value="30 days or more with ME" /> <c:set var="messagestatus2a" value="Less than 30 days with JPM"/> <c:set var="messagestatus2b" value="30 days or more with JPM" />
    I get a status value from the database (such as status1a, status1b, status2a, status2b) and I am concatenating with 'message' so that I can frame the appropriate variable name.
    <c:forEach var="suggestionsLoop" items="${suggestionQuery.rows}">
    <c:set var="msgDesc" value="message${suggestionsLoop.status}" />
    <!-- Now, 'msgDesc' variable has a value like 'messagestatus1a' or 'messagestatus1b' etc.,
    I would like to reprocess the value from msgDesc to diaplay the appropriate message.
    If I try ${${msgDesc}} obviously I am getting error. Any ideas how to accomplish this ?
    -->
    </c:forEach>
    Thanks,
    vmrao

    In this case you can use the squarebracket notation combined with the implicit map to all EL variables in scope.
    <c:out value="${pageScope[msgDesc]}"/>Cheers,
    evnafets

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

  • JSTL 1.1.2 tags with JDK 1.4.2_12

    Hi,
    We have used JSTL 1.1.2 tags in our application. It works fine with JDK 1.4.2_05 on weblogic server 8.1 sp4. The same application throws error on use with JDK 1.4.2_12. Is any patch available for support of JSTL in JDK 1.4.2_12. Kindly do reply on the same.
    Thanks in advance
    Thanks & Regards
    V. Pravina

    I ran into a similiar problem with JBuilder 5. The answers on their boards indicate the problem traces to the change Sun made with versioniong class files in JDK1.4.
    Someone offers a patch tool for JBuilder, but Borland does not support it. It will be interesting to see what Oracle does with this problem.
    Mark

  • JSTL variables

    Hello All,
    Need help , I'm new to JSTL. My page works fine on my local machine.
    I uploaded it to a hosting site
    and the JSTL variables show instead of it's content.
    for example, I see on the page :
    ${cfList.ClientID} ${cfList.LName} ${cfList.Address}
    instead of the content of ClientID,LName and Address
    I have jstl.jar and standard.jar in the directory /public_html/WEB-INF/lib/
    Please Help what could be the cause for this.

    Maybe you have to ensure you are running such a container before you worry about where you put the files. You've got it back to front.

  • Maybe you are looking for

    • ANY FUNCTION MODULE TO ADD LEADING ZEROS FOR A CHARACTER FIELD

      THE CHARACTER FIELD IS OF LENGTH 40 AND IT HAS 5 NON NUMERIC CHARACTERS

    • ITunes 12.0.1 Won't Open

      I have successfully installed OS X Yosemite and  iTunes 12.0.1 but iTunes will not open in Finder or from the dock. Whenever I left click on the icon nothing happens. There is a small upwards pointing arrow under the iTunes icon which I've never seen

    • Returning a SharePoint 2013 termset in a tree structure using JavaScript for MultiLingual

      Hi, How do we get the path of term,if my term label is in some other locale, lets say for Spanish but using currentTerm.get_pathOfTerm() property it returns default path of my term store, i.e English. But i need the path to use my values returned in

    • Office2010

      Hi I had to do a complete windows install and it wiped out my Office 2010.  I only have one license.  I tried to reinstall it and all seemed well, I put in the Product code and everything loaded as normal, but it keeps asking me to activate on line.

    • QM Dash Board

      Hi expert I was about design of Quality department manager Dash board So please advice me how i can proceed wether as a Functional person i can do it alone or i need any technical help Also please tell me what are the thing need to be in dash board n