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

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

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

    Manish Pandit, Oct 4, 2006
    1. Advertisements

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

    Manish Pandit, Oct 4, 2006
  4. Hole

    Hole Guest

    Manish Pandit ha scritto:
    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 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 my tag -->
    <p:pager range="<%= rangeS %>" results="<%= resultsS %>" page="<%=
    pagexS %>" />

    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
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.