I like Tiles, too, and think it is definitely worth a look for your site.
One of the best parts about it relative to some other page templating
techniques is that tiles page definitions support inheritance so you don't
have to specify the same stuff over and over for each page. Your proposed
solution avoids the duplication of the standard includes, too, but Tiles
affords this feature as well. In your scenario, you might create a base page
definition that includes all the usual stuff (top, left, right, footer,
buttom :-)) and then extend it for each unique page. The SearchPage would be
a definition that extends the base page definition and sets MAIN to the
'search.jsp' in your scenario. Struts allows you to forward to a page
definition (as opposed to a JSP, etc.), so you can just have the forward for
that action go right to the SearchPage definition, without having to create
an actual JSP page that includes search.jsp or any of the other stuff.
That's just a conceptual description, but it seems this feature of Tiles
would be very useful for your situation.

Short of that, this might work with your JSP solution:

<jsp:include page='<%=request.getAttribute("specialPage")+".jsp"%>' />

I seem to recall that you can't mix a <%= %> and static text in setting an
attribute for a tag attribute. For example, this won't work:

<sometaglib:sometag attribute='<%="Hello"%> World'/>

But this should:

<sometaglib:sometag attribute='<%="Hello" + " World"%>'/>

The attribute value in the second one is one big <%= %>, rather than a
mixture of a <%= %> and static text.

And the request.getAttribute("specialPage") part will retrieve the
"specialPage" attribute value from the request scope.

But I urge you to look at Tiles. It does what you want to do very cleanly,
is integrated with Struts very nicely, and is a standard solution that you
don't have to develop or document, and that your team members may already
have experience with or at least be more excited about learning than an
in-house, one-off system since that experience will have more value in the
marketplace.

-Max

----- Original Message ----- 
From: "Morten Andersen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, September 24, 2003 11:57 PM
Subject: How to include part of a page dynamically?


> I'm developing a site where the pages consists of a number of different
parts:
>
> top, left, right, MAIN, footer, buttom
>
> I want to dynamically include the MAIN part, so that I include a page,
that
> I generate in the action that forwards to the page. For instance I would
> like to say:
>
> In
> ViewPage.action I do a: request.setAttribute("specialPage" , "search").
>
> Then in the jsp page I would like to write something like:
> <jsp:include page="<%specialPage%>.jsp" />  and get the "search.jsp" page
> included in the MAIN block.  This way I could extend the site by just
> adding a jsp page.
>
> How can that be done?
>
>
> Thanks
>
>
> Morten Andersen
> Master of applied mathematics and computer science
> Amanuensis (in e-learning)
>
> The Maersk Institute of Production technology at Southern Danish
University
> www.mip.sdu.dk
> Campusvej 55
> DK-5230 Odense M
> Denmark
> +45 6550-3654
> +45 6171-1103
> Jabber id: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to