need help in JSTL/STRUTS + Custom Tag

Discussion in 'Java' started by Hole, Oct 4, 2006.

  1. Hole

    Hole Guest

    Hi all!

    I need to access (without scriptlet) to any variables saved in a
    session, in order to use them in a custom tag (for pagination purpose).

    This is the custom tag.

    <p:pager range="" results="" page="" />

    If you need the doStartTag() code too, please tell me.

    The custom tag is very simple and could print a navigation table
    (pager) to browse within results.
    In the same JSP, I need to define the variables range, results and
    page, saved in a session previously (in an Action in struts framework).

    How can access to them? I tried to use JSTL and the tag <c:set> but now
    I know I cannot access to that variables out of JSTL tags.
    I don't know how to use <bean:define> to retrieve attributes from
    session.

    Thanks a lot in advance.
     
    Hole, Oct 4, 2006
    #1
    1. Advertising

  2. You can use EL and get attributes from the session. Something like
    ${sessionScope.result} and ${sessionScope.currentPage}. If you want to
    do it in your tag, and u're using the Classic Model, you can use
    pageContext.getRequest().getSession().getAttribute(). If you're using
    the Simple Model, you will use jspContext().findAttribute().

    -cheers,
    Manish
     
    Manish Pandit, Oct 4, 2006
    #2
    1. Advertising

  3. Manish Pandit wrote:
    > the Simple Model, you will use jspContext().findAttribute().


    Oops - that'd be getJspContext().findAttribute() or
    getJspContext().getAttribute().

    -cheers,
    Manish
     
    Manish Pandit, Oct 4, 2006
    #3
  4. Hole

    Hole Guest

    Manish Pandit ha scritto:

    > You can use EL and get attributes from the session. Something like
    > ${sessionScope.result} and ${sessionScope.currentPage}. If you want to
    > do it in your tag, and u're using the Classic Model, you can use
    > pageContext.getRequest().getSession().getAttribute(). If you're using
    > the Simple Model, you will use jspContext().findAttribute().
    >
    > -cheers,
    > Manish


    Thanks a lot for you replies.
    I tried to use EL in my tag but I get any errors.

    I've found the following solution (STRUTS save the form bean in the
    scope session, so you can retrieve the fields with
    <bean:define>...great!!):
    <code>

    <bean:define id="pagex" name="searchForm" property="page" />
    <bean:define id="results" name="searchForm" property="results" />
    <bean:define id="range" name="searchForm" property="range" />


    <!-- I would remove this scriptlet -->
    <%
    String pagexS=String.valueOf(pagex);
    String resultsS=String.valueOf(results);
    String rangeS=String.valueOf(range);
    %>

    <!-- at bottom...in my tag -->
    <p:pager range="<%= rangeS %>" results="<%= resultsS %>" page="<%=
    pagexS %>" />
    </code>

    If I save variables in a session and use something like <p:pager
    range="${sessionScope.range}"...I get a runtime exception because
    ${var} is not resolved.
     
    Hole, Oct 5, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shahbaz
    Replies:
    0
    Views:
    939
    shahbaz
    Oct 27, 2003
  2. Robert Mark Bram

    Custom JSTL that accepts JSTL expression

    Robert Mark Bram, Dec 15, 2004, in forum: Java
    Replies:
    0
    Views:
    1,007
    Robert Mark Bram
    Dec 15, 2004
  3. shruds
    Replies:
    1
    Views:
    931
    John C. Bollinger
    Jan 27, 2006
  4. Replies:
    1
    Views:
    1,380
    Richard Senior
    Apr 24, 2007
  5. DaFoot
    Replies:
    1
    Views:
    1,761
    DaFoot
    Oct 23, 2008
Loading...

Share This Page