Separate JSP-Page and Content

Reply

Join Date: Nov 2008
Posts: 2
Reputation: flosweb is an unknown quantity at this point 
Solved Threads: 0
flosweb flosweb is offline Offline
Newbie Poster

Separate JSP-Page and Content

 
0
  #1
Nov 17th, 2008
Hi Guys,
I am new here in this community. I still did some stuff with JSP, but now I have a principle questions. Would be nice to receive some feedback...

I wanna build up a website with several JSP pages. But I don't want to place all the content into the JSP page. Well that's a common goal, separating content and structure.

What I am targeting on is referencing specific content-items in a JSP page by a key and language dependent, which can be handled via session scope. For example I have a line like this in a JSP page:
<mytag:include key="level1.sublevel4.intro.text"/>

This should load the targeting content stored in another JSP file (not simple XML) that only stores content items. For example like this:
<content-item key="level1.sublevel4.intro.text">
<language>en</language>
<content>A lot of <html:link href="..">text</html:link>...</content>
</content-item>

I not only wanna use a simple XML file for storing content, because I also wanna use JSP-TagLibs inthere, for example <html:link...> or others.

I also know about the MessageResources concept, but I doesn't think this fits my need, especially not the MessageResources_en_US.properties file idea.

Perhaps there is a very simple standard solution for this, I didn't found until know. Would be nice to receive some feedback. Thanks a lot in advance.

Best regrads from Germany.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Separate JSP-Page and Content

 
0
  #2
Nov 17th, 2008
> But I don't want to place all the content into the JSP page.
> This should load the targeting content stored in another JSP file (not simple XML)

The above two lines are contradictory; you still end up placing the content if your JSP file.

> I also know about the MessageResources concept, but I doesn't think this fits my need

Why? You can use Message bundles inside your JSP's with the fmt (format) JSTL tag library.

As far as your needs are concerned, you just need to create a JSP file which pulls the data from a message bundle (depending on a locale of course) and include it in your main JSP file. Pass in the required language(locale) to the included JSP as a parameter.
  1. [include.jsp]
  2.  
  3. <fmt:setLocale value="${param.lang}" scope="request" />
  4. <fmt:bundle baseName="Bundle">
  5. <table>
  6. <tr>
  7. <td>Name</td>
  8. <td><fmt:message key="name" /></td>
  9. </tr>
  10. <tr>
  11. <td>Hello</td>
  12. <td><fmt:message key="hello" /></td>
  13. </tr>
  14. <!-- and so on -->
  15. </table>
  16. </fmt:bundle>
  1. [Bundle_en.properties]
  2.  
  3. name=YourName
  4. hello=Hello-in-English
  1. [main.jsp]
  2.  
  3. <jsp:include page="include.jsp">
  4. <jsp:param name="lang" value="some-locale-like-en" />
  5. </jsp:include>
Google for these terms for more explanation and read the J2EE 5 tutorial. for more on tags.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 2
Reputation: flosweb is an unknown quantity at this point 
Solved Threads: 0
flosweb flosweb is offline Offline
Newbie Poster

Re: Separate JSP-Page and Content

 
0
  #3
Nov 19th, 2008
Hello,
sorry for late reply, but I was on working out a solution for this ;-)
And thank you very much for your feedback! This helped my on establishing nice results.
I would like to separate content and structure of a page, but both files should be jsp files.
So in principle the idea of include is good enough, but I don't like it because of the complicated syntax.
I solved this issue, with using "Tag Files", to wrap some JSP code and giving me a nice and clear API for storing content and for loading it via keys in the final page.

The first code example shows how to store the content snippets.
  1. [file for content storage]
  2. <my:content-provider-init keyprefix="level1.level2">
  3.  
  4. <my:content-provider-element key="intro" language="en">
  5. This is <i>english</i> content.
  6. </my:content-provider-element>
  7. <my:content-provider-element key="intro" language="de">
  8. Dies ist deutscher Inhalt.
  9. </my:content-provider-element>
  10.  
  11. </my:content-provider-init>

The second example shows how to call these above defined code snippets.
  1. [requested JSP page]
  2.  
  3. <%@ taglib tagdir="/WEB-INF/tags/my" prefix="my" %>
  4. <html>
  5. <body>
  6. <my:content-loader-init keyprefix="level1.level2"/>
  7. <br/>
  8. <my:content-loader key="intro"/>
  9. <br/>
  10. <my:content-loader key="paragraph1"/>
  11. </body>
  12. </html>
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,600
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 462
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Separate JSP-Page and Content

 
0
  #4
Nov 22nd, 2008
Good thing you found a solution to your problem but I still believe locale specific content needs to be moved to separate message bundles instead of being embedded in JSP's; but then again it might be a limitation imposed by your design.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JSP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC