Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

need help in JSTL/STRUTS + Custom Tag

Thread view: 
Hole - 04 Oct 2006 14:25 GMT
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.
Manish Pandit - 04 Oct 2006 17:00 GMT
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 - 04 Oct 2006 17:02 GMT
> the Simple Model, you will use jspContext().findAttribute().

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

-cheers,
Manish
Hole - 05 Oct 2006 10:56 GMT
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
[quoted text clipped - 4 lines]
> -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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.