You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Larry Rogers <La...@mercmarine.com> on 2000/09/05 04:56:55 UTC

Page bean


Hi All,

It seems that many of the same types of information end up in all my JSPs, such
as

    * html <title>

    * status message, such as "The form was successfully submitted."

    * list of the app's top level pages with link addresses (for navigation bar)

    * name of the current top level page (for indicating in the navigation bar)

    * name of the current page within this level (for displaying at the top of
the page)

What I have done up to now is put these items in variables in the page before
calling a "header.jsp", which uses the variables in scriptlets to generate the
html for the navigation bar, etc.  But I would like to separate out the java
logic somehow.

Anyway, I was planning to start using a page bean that would contain this info
for the purposes of rendering the single page which receives control.  The bean
would be populated and placed in the response before forwarding to the page.  I
would write custom tags to render the html title, status message, and the nav
bar.

But does it make more sense for Struts to populate a page bean with info from
struts-config.xml such as

<top-level-pages>
    <page>
        <page-name>Main Menu</page-name>
        <page-link>/mainmenu.jsp</page-link>
    </page>
    <page>
        <page-name>Subscriptions</page-name>
        <page-link>/editSubscriptions.do</page-link>
    </page>
</top-level-pages>

Then the jsp could contain custom tags to iterate through the top level pages to
produce the customized navigation bar, with the current top level page
indicated, with HTML.  If the user wanted to use the other attributes, like html
title or status message, they could be set in the action class before the
forward--or maybe there is a better way.  The struts-config file is really great
in that it encourages you to plan your application before jumping right into the
code, and planning the top level pages would be natural here.

I know it sounds like I haven't thought this through, which is true, but I
wanted to see what you all think before plunging into my original plan.

Larry Rogers