• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

S2: Correct way to use s:include

 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to pull out some of my common jsp code, but it seems like I'm doing it incorrectly.

Here's what I'm trying:

Rendered JSP: WEB-INF/content/competitions/summary.jsp:


Included JSP: WEB-INF/components/competitions/identity-readonly.jsp


summary.jsp is the result of a Summary action. I also have an event.jsp backed by an Event action. In event.jsp the param's value will need to be ${event.competition}.

Eventually the identity-readonly.jsp will also include other values and will need to use the struts2 tags itself, but I'd rather it not be backed by a seperate action (and hence a separate request). I thought this was where we're supposed to use s:include.

However I get an empty page, with no error messages in my logs with the code listed above.

What I am doing wrong?
[ July 27, 2008: Message edited by: Eric Nielsen ]
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure exactly why the s:include is not working, but in this case it looks to me like a JSP include directive would be the best option. This just includes a snippet of code before the page is compiled and then the snippet is just included when the whole page is compiled. Example:
 
Eric Nielsen
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That style include doesn't allow (well not without other circumlocutions) renaming of the variable. (Ie the included fragments expects "comp" while the calling page has either competition-->comp or event.competition--->comp)

A regular jsp:include also fails as it doesn't provide an ValueStack/OGNL environment (which is why s:include is provided over jsp:include)

I got some help on the struts user mailing list that suggests I need to try prefacing the variable in the fragment page with "param." or user a c:set to import the parameter from that scope into page or request scope for easier access. I plan to give that a try this evening.
 
Eric Nielsen
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I tried the approach suggested on the struts user mailing list. It didn't work. I think part of it might have been a version issue. The user list said I needed to use a "param" prefix; the docs say I need to use a "parameters" prefix.

I got the parameters prefix version working with the s:component tag, but not the s:include tag. The draw back with s:component so far, as that I haven't been able to move the template directory under WEB-INF (by default it sits at webroot/template).

When I tried the struts.ui.templateDir property to move this directory it seemed to break all the existing struts 2 tags (errors in the log file about not being able to find something like a.ftl (error message on another computer so I'm paraphrasing here)).
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic