Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having a common bean for menu tile?

Status
Not open for further replies.

znapper

Programmer
Oct 2, 2002
8
0
0
NO
Hi

I'm running a simple web app which use tiles to keep the layout consistent trough the whole web.

Now, my "header" tile, defined as usual in the tiles defs xml, is a header.jsp file. My plan is that this particular jsp should show a menu with some options for the user.

So far so good, however, I plan to fetch the data to show in the menu from a database. This will demand locig in an action, a population of a formbean and then logic to pluck out the data from that formbean in the header.jsp to create the menu.

This, in turn, creates the need of a "common" formbean which contains the menu data troughout the application, because i will have to actually pluck out the data from the same formbean, no matter what other action was ran.

My application use an abstract self implemented superclass (BaseAction, which extends a normal struts action) for my actions, so that I can implement common logic (like login etc) for the web as a whole in this one.

I am in the dark though on how to implement a "common" formbean which the header.jsp can always read to create the menu for me.

How would I go about creating a formbean that lies in the session scope, that the header.jsp reads and the first initial action fires up and populates for me?
(That is, how to i actually use it in the jsp? And how do I actually set a bean into session scope, making it usable for jsp's as a normal session scoped formbean?).

Sorry for the lenghty question, but I hope I have explained the problem well enough for a fairly simple answer from some of you gurus out there. :)

Regards
 
Allright, been having some time to think about this one, and the sollution was rather simple;

- In the startup action normally used to create the regular data you show on the first page, simply create the (second) form you need for the menu, populate it and then save it into the request.getSession().setAttribute() call.

Then, ie. in a iteration in the JSP, simply add scope="session" to the iteration call to access the bean now in session. You don't even have to declare it in the struts config.xml file.

Now, my problem was a need for a read only session scoped bean, accessible in one of the tiles troughout the whole application. I do not know how to solve this ie. in a read/write situation, as you would have to tell struts to handle input from that form somehow.

Anyways, I solved my problem.

Regard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top