need help in JSTL/STRUTS + Custom Tag

H

Hole

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

Manish Pandit

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
 
M

Manish Pandit

Manish said:
the Simple Model, you will use jspContext().findAttribute().

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

-cheers,
Manish
 
H

Hole

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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top