Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2005

Tip: Looking for answers? Try searching our database.

locale-specific include for JSP?

Thread view: 
rhassinger12@yahoo.com - 21 Jun 2005 05:39 GMT
Is there a way to use a jsp:include for a locale? For example, if the
locale is US, then take homepage_us.html, if it's ES, use
homepage_es.html, etc.

This seems obvious to me (since I don't want to have all that stuff in
a .properties file) but I can't find anything about it, except for a
feature of BEA weblogic.
SMC - 21 Jun 2005 07:15 GMT
On Tue, 21 Jun 2005 14:39:06 +1000, rhassinger12 wrote:

> Is there a way to use a jsp:include for a locale? For example, if the
> locale is US, then take homepage_us.html, if it's ES, use
[quoted text clipped - 3 lines]
> .properties file) but I can't find anything about it, except for a
> feature of BEA weblogic.

You could of course do:

if (locale = US)
 include homepage_us
else if (locale = ES)
 include homepage_es

But more elegant might be to write a custom include tag perhaps? We wrote
our own to decide which JSP of the given name to include from a set of
rules. For your case, the tag could be

<o:include page="homepage"/>

The taglib body might be as simple as:

   protected String page = "";
   public String getPage(){ return page; }
   public void setPage(String page){
           this.page = page;
   }

   public int doStartTag() throws JspException{
       try{
           JspWriter out = pageContext.getOut();
           if ("true".equals(flush) && !(out instanceof BodyContent))
                   out.flush();

           ServletContext context = pageContext.getServletContext();
           ServletRequest request = pageContext.getRequest();
           ServletResponse response = pageContext.getResponse();

       // Some locale code here
       String localeExt; /* = something */

       String resourcePath = path + localeExt + ".jsp";
       RequestDispatcher rd = request.getRequestDispatcher(resourcePath);
       rd.include(request,new ServletResponseWrapperInclude(response,
out));

    }catch(Exception e){
       throw new JspTagException("IncludeTag ("+module+"):"+e.toString());
    }
    return SKIP_BODY;
   }

Or something like that.

Signature

Sean

I don't suffer from insanity, I enjoy every minute of it.

rhassinger12@yahoo.com - 21 Jun 2005 23:36 GMT
Thanks, I was thinking about this approach too. However the obvious
problem is that this doesn't fall back to a default page when someone
from an unknown country connects. On every include, we would have to
check the filesystem to see if a jsp exists, then fall back (to avoid
exceptions slowing us down). I was thinking that another possibility
would be to have the filename in the resources properties file itself,
but that means keeping things in two places. Not very maintainable. I
would have thought JSTL would have a feature such as this. BEA got the
right idea and implemented it.

> On Tue, 21 Jun 2005 14:39:06 +1000, rhassinger12 wrote:
>
[quoted text clipped - 57 lines]
>
> I don't suffer from insanity, I enjoy every minute of it.
SMC - 22 Jun 2005 02:13 GMT
We had to check for the existence of a file like you say, but we kept a
(static) hash of the results so that we only had to do it once. Something
like:

   protected static Hashtable resourceList = new Hashtable();

   ...

   URL url = application.getResource(thisFile);
   if (url != null){
        // Mark that this file exists
        resourceList.add(thisFile,new Boolean(true));
   }else{ // ignore missing resources
       // Mark that this file doesn't exist
       resourceList.add(thisFile,new Boolean(false));
   }

If a feature like this existed in the JSTL, it would have to address this
itself somehow anyway, as no doubt the BEA version would too. If the BEA
version were open source we could see how they did it :-)

On Wed, 22 Jun 2005 08:36:20 +1000, rhassinger12 wrote:

> Thanks, I was thinking about this approach too. However the obvious
> problem is that this doesn't fall back to a default page when someone
[quoted text clipped - 68 lines]
>>
>> I don't suffer from insanity, I enjoy every minute of it.


Signature

Sean

I've always found [the news media] quite accurate, except when they're
reporting on a topic I know something about. --usenet post



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.