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