You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Keith Fetterman <kf...@go2marine.com> on 2006/02/08 07:01:27 UTC

Accessing static methods from Struts/JSTL

Folks,

We are converting old JSP pages to Struts and JSTL and I am running into 
a problem.  On the old JSP pages, we have some calls to static methods 
in scriptlets and runtime expressions.  On the new JSP pages, we have 
disabled scriptlets and runtime expressions.  Here is an example:

The old code will have an expression like:
<%= OrderRulesBean.getSmallOrderFeeLimit() %>

What is the best way (best practice or easiest to implement) to access 
static methods in the JSP pages without resorting to runtime expressions?

Thanks a lot for your help,
Keith


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Accessing static methods from Struts/JSTL

Posted by Keith Fetterman <kf...@go2marine.com>.
Keith,

I've done a lot of searching and reading since my last post and you are 
correct.  But, it has left me wondering what others are doing about 
mixing markup language and text.  Do they put the markup language in the 
resources file or breakup the text into chunks and leave the markup in 
the JSP files.  I will probably post a specific question related to find 
out what others are doing.

Thanks a lot for spending the time to help me. And the book recommendation.

Keith


Keith Sader wrote:
>>>Ok, since this app is internationalized, I'm guessing you have your
>>>.en, .fr, etc. files all ready to go?  If I'm reading this right, it
>>>looks like your app needs an internationalization effort put into it?
>>>Maybe I misread.
>>
>>That is correct.  As we cut over to Struts, we have been
>>internationalizing the messages, other template page text and text images.
>>
>>
>>>Is there a reason you're not using the Applications.resources.(country
>>>code) files to do this sort of thing?  Again, I'm probably missing
>>>something.
>>
>>I may not be doing this the right way.  Simple messages live in our
>>ApplicationResources.properties file.  Right now, we are only doing
>>english, which is the default.
>>
>>But, I didn't know what to do with more complex messages, which may be
>>multiple paragraphs, with HTML, images, links, etc. And may contain
>>Struts/JSTL tags too. So what we have done is created a directory in our
>>application:
>>
>>/messages/en/
>>
>>In that directory, we place JSP files that contain the more complex
>>messages.  In the ApplicationResouces.properties file, we specify a URL
>>to the file containing the complex message.
> 
> 
> Ok, I think you're making too much work for yourself.  If I understand
> it(I8N) correctly, the only thing one really has to do is name all of
> those .properties files with the right country code, insert the
> translated text with the correct subsitution placeholders,  and
> presto, the magic container will render the correct stuff for you. 
> Then you get a pony :-)  Mind you I'm recounting this from fuzzy
> memory so the last two sentences could be completely and totally
> inaccurate, but I'm pretty sure you get a pony...
> 
> Manning's _Struts in Action_ has a pretty good chaper (13) on App
> localization.  http://www.manning.com/books/husted/contents.


> 
> Best of luck Keith!
> 
> thanks,
> --
> Keith Sader
> ksader@gmail.com
> http://www.saderfamily.org/roller/page/ksader
> http://www.jroller.com/page/certifieddanger
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

-- 
-----------------------------------------------------------------
Keith Fetterman                          206-780-5670
Mariner Supply, Inc.                     kfetterman@go2marine.com
http://www.go2marine.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Accessing static methods from Struts/JSTL

Posted by Dave Newton <ne...@pingsite.com>.
Keith Sader wrote:
>> But, I didn't know what to do with more complex messages, which may be multiple paragraphs, with HTML, images, links, etc. And may contain Struts/JSTL tags too.[...]
>> In that directory, we place JSP files that contain the more complex
>> messages.  In the ApplicationResouces.properties file, we specify a URL to the file containing the complex message.
>>     
>
> Ok, I think you're making too much work for yourself.  If I understand
> it(I8N) correctly, the only thing one really has to do is name all of
> those .properties files with the right country code, insert the
> translated text with the correct subsitution placeholders,  and
> presto, the magic container will render the correct stuff for you. 
>   
I think the point was that it wasn't simply an issue of I18Ning prompts,
but rather the entire page (or chunks) could change. For various
language, cultural, or use-case reasons this makes sense.

For a never-deployed app we used the same idea of adding a locale
extension to the name of JSP files (which IIRC tied into some twisted
tile processing code???) so we had home_en.jsp, home_jp.jsp,
form1_en.jsp, etc.

Somehow or another the Right Thing happened but I'll be darned if I
remember how at this point, rendering this post OT :/

Dave


Re: Accessing static methods from Struts/JSTL

Posted by Keith Sader <ks...@gmail.com>.
> > Ok, since this app is internationalized, I'm guessing you have your
> > .en, .fr, etc. files all ready to go?  If I'm reading this right, it
> > looks like your app needs an internationalization effort put into it?
> > Maybe I misread.
>
> That is correct.  As we cut over to Struts, we have been
> internationalizing the messages, other template page text and text images.
>
> >
> > Is there a reason you're not using the Applications.resources.(country
> > code) files to do this sort of thing?  Again, I'm probably missing
> > something.
>
> I may not be doing this the right way.  Simple messages live in our
> ApplicationResources.properties file.  Right now, we are only doing
> english, which is the default.
>
> But, I didn't know what to do with more complex messages, which may be
> multiple paragraphs, with HTML, images, links, etc. And may contain
> Struts/JSTL tags too. So what we have done is created a directory in our
> application:
>
> /messages/en/
>
> In that directory, we place JSP files that contain the more complex
> messages.  In the ApplicationResouces.properties file, we specify a URL
> to the file containing the complex message.

Ok, I think you're making too much work for yourself.  If I understand
it(I8N) correctly, the only thing one really has to do is name all of
those .properties files with the right country code, insert the
translated text with the correct subsitution placeholders,  and
presto, the magic container will render the correct stuff for you. 
Then you get a pony :-)  Mind you I'm recounting this from fuzzy
memory so the last two sentences could be completely and totally
inaccurate, but I'm pretty sure you get a pony...

Manning's _Struts in Action_ has a pretty good chaper (13) on App
localization.  http://www.manning.com/books/husted/contents.

Best of luck Keith!

thanks,
--
Keith Sader
ksader@gmail.com
http://www.saderfamily.org/roller/page/ksader
http://www.jroller.com/page/certifieddanger

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Accessing static methods from Struts/JSTL

Posted by Keith Fetterman <kf...@go2marine.com>.
Keith Sader wrote:
> On 2/8/06, Keith Fetterman <kf...@go2marine.com> wrote:
> 
>>OrderRulesBean.getSmallOrderFeeLimit()
>>
>>This static method is returning a property from a properties file that
>>will be included in a message to the user. This class provides a
>>convenient way for java classes to reference a single instance of this
>>property.
>>
>> From what you said, I could create a page display backing bean and
>>expose it through there.  Good idea if it works. But, I was wondering if
>>there was a more general way without having to re-expose it.
> 
> 
> Well is it possible to just put this in as another property of what's
> being displayed on the page currently so that
> ${order.smallOrderFeeLimit} just delegates that call on the get to
> OrderRulesBean.getSmallOrderFeeLimit()?

I have thought of that, but I was hoping not to because it appeared 
redundant and bloated the class.

> 
> 
>>In my particular case, I might have a problem accessing the request
>>scoped page display bean.  The message that I am displaying to the user
>>is located in an internationalized message (JSP) file that will be
>>imported to the page using <c:import> tag after fetching the page URL
>>using <fmt:message> tag to get the URL from the
>>ApplicationResources.properties file.  I need to insert the value from
>>the static method in the text contained in the imported file.
> 
> 
> Ow, that made my head hurt :-)

This stuff makes my head hurt all of the time :)  Way too much stuff to 
master to roll out Web applications.

> 
> Ok, since this app is internationalized, I'm guessing you have your
> .en, .fr, etc. files all ready to go?  If I'm reading this right, it
> looks like your app needs an internationalization effort put into it? 
> Maybe I misread.

That is correct.  As we cut over to Struts, we have been 
internationalizing the messages, other template page text and text images.

> 
> Is there a reason you're not using the Applications.resources.(country
> code) files to do this sort of thing?  Again, I'm probably missing
> something.

I may not be doing this the right way.  Simple messages live in our 
ApplicationResources.properties file.  Right now, we are only doing 
english, which is the default.

But, I didn't know what to do with more complex messages, which may be 
multiple paragraphs, with HTML, images, links, etc. And may contain 
Struts/JSTL tags too. So what we have done is created a directory in our 
application:

/messages/en/

In that directory, we place JSP files that contain the more complex 
messages.  In the ApplicationResouces.properties file, we specify a URL 
to the file containing the complex message.

Then in the original JSP page, we use the <fmt:message> tag to get the 
URL and a <c:import> tag to import the file into the original JSP page.

Is there any easier way?

I have the Struts Recipes Book and Jakarta Struts Cookbook if you can 
point me there.

> 
> 
>>Is there is a direct way to access the static method without fetching it
>>from request scoped variable or object?  Another post said there is a
>>nonstandard Struts tag library that will work.
> 
> 
> FWIW, I'd stay away from those, but it might work for your situation.
> 
> 
>>BTW, what is best practice in Struts when providing data to JSP files?
> 
> 
> Good question, I know the technique I prefer is your #2 item below,
> but that might not be the best practice in your situation.

Its the technique I prefer too because it cuts down on creating extra 
classes.

> 
> 
>>1. Create a display backing bean that contains all of the objects that
>>will be used and store that in a single requested scoped variable?
>>
>>2. Store individual objects and values in requested scoped variables?
>>
> 
> 

Keith, doubly thanks for your help.  I really appreciate it.

-- 
-----------------------------------------------------------------
Keith Fetterman                          206-780-5670
Mariner Supply, Inc.                     kfetterman@go2marine.com
http://www.go2marine.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Accessing static methods from Struts/JSTL

Posted by Keith Sader <ks...@gmail.com>.
On 2/8/06, Keith Fetterman <kf...@go2marine.com> wrote:
>
> OrderRulesBean.getSmallOrderFeeLimit()
>
> This static method is returning a property from a properties file that
> will be included in a message to the user. This class provides a
> convenient way for java classes to reference a single instance of this
> property.
>
>  From what you said, I could create a page display backing bean and
> expose it through there.  Good idea if it works. But, I was wondering if
> there was a more general way without having to re-expose it.

Well is it possible to just put this in as another property of what's
being displayed on the page currently so that
${order.smallOrderFeeLimit} just delegates that call on the get to
OrderRulesBean.getSmallOrderFeeLimit()?

>
> In my particular case, I might have a problem accessing the request
> scoped page display bean.  The message that I am displaying to the user
> is located in an internationalized message (JSP) file that will be
> imported to the page using <c:import> tag after fetching the page URL
> using <fmt:message> tag to get the URL from the
> ApplicationResources.properties file.  I need to insert the value from
> the static method in the text contained in the imported file.

Ow, that made my head hurt :-)

Ok, since this app is internationalized, I'm guessing you have your
.en, .fr, etc. files all ready to go?  If I'm reading this right, it
looks like your app needs an internationalization effort put into it? 
Maybe I misread.

Is there a reason you're not using the Applications.resources.(country
code) files to do this sort of thing?  Again, I'm probably missing
something.

>
> Is there is a direct way to access the static method without fetching it
> from request scoped variable or object?  Another post said there is a
> nonstandard Struts tag library that will work.

FWIW, I'd stay away from those, but it might work for your situation.

> BTW, what is best practice in Struts when providing data to JSP files?

Good question, I know the technique I prefer is your #2 item below,
but that might not be the best practice in your situation.

> 1. Create a display backing bean that contains all of the objects that
> will be used and store that in a single requested scoped variable?
>
> 2. Store individual objects and values in requested scoped variables?
>

thanks,
--
Keith Sader
ksader@gmail.com
http://www.saderfamily.org/roller/page/ksader
http://www.jroller.com/page/certifieddanger

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Accessing static methods from Struts/JSTL

Posted by Keith Fetterman <kf...@go2marine.com>.
Keith Sader wrote:
 > IMO this is a design smell of the presentation layer.

Maybe.  And from the name of the class, I can see why you questioned that.

OrderRulesBean.getSmallOrderFeeLimit()

This static method is returning a property from a properties file that 
will be included in a message to the user. This class provides a 
convenient way for java classes to reference a single instance of this 
property.

 From what you said, I could create a page display backing bean and 
expose it through there.  Good idea if it works. But, I was wondering if 
there was a more general way without having to re-expose it.

In my particular case, I might have a problem accessing the request 
scoped page display bean.  The message that I am displaying to the user 
is located in an internationalized message (JSP) file that will be 
imported to the page using <c:import> tag after fetching the page URL 
using <fmt:message> tag to get the URL from the 
ApplicationResources.properties file.  I need to insert the value from 
the static method in the text contained in the imported file.

Is there is a direct way to access the static method without fetching it 
from request scoped variable or object?  Another post said there is a 
nonstandard Struts tag library that will work.


BTW, what is best practice in Struts when providing data to JSP files?

1. Create a display backing bean that contains all of the objects that 
will be used and store that in a single requested scoped variable?

2. Store individual objects and values in requested scoped variables?

Keith, thanks a lot for your feedback.

Keith


Keith Sader wrote:
> IMO this is a design smell of the presentation layer.
> 
> My suggestion would be to refactor these items down to the
> 'business-layer' and then have your actions put the results of that
> layer into the form/display bean.
> 
> Then the .jsp could just look like <c:out value='${order.smallOrderFeeLimit}'/>
> 
> There may be more to this with your particular site, but that's a
> first off-the-cuff guess.
> 
> hth,
> 
> 
> On 2/8/06, Keith Fetterman <kf...@go2marine.com> wrote:
> 
> 
>>We are converting old JSP pages to Struts and JSTL and I am running into
>>a problem.  On the old JSP pages, we have some calls to static methods
>>in scriptlets and runtime expressions.  On the new JSP pages, we have
>>disabled scriptlets and runtime expressions.  Here is an example:
>>
>>The old code will have an expression like:
>><%= OrderRulesBean.getSmallOrderFeeLimit() %>
>>
>>What is the best way (best practice or easiest to implement) to access
>>static methods in the JSP pages without resorting to runtime expressions?
> 
> 
> --
> Keith Sader
> ksader@gmail.com
> http://www.saderfamily.org/roller/page/ksader
> http://www.jroller.com/page/certifieddanger
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 

-- 
-----------------------------------------------------------------
Keith Fetterman                          206-780-5670
Mariner Supply, Inc.                     kfetterman@go2marine.com
http://www.go2marine.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Accessing static methods from Struts/JSTL

Posted by Nicolas De Loof <ni...@capgemini.com>.
You can use jakarta unstandard taglib. 
(http://jakarta.apache.org/taglibs/sandbox/doc/unstandard-doc/intro.html)

I use it to access const from JSP.  :

<%@ taglib prefix="u" 
uri="http://jakarta.apache.org/taglibs/unstandard-1.0" %>

<u:bind type="com.capgemini.gta.web.webapp.form.NumeroAssisteForm"
     var="base" field="BASE"/>

<html:select property="option">
        <html:option value="${base}">Base</html:option>
</html:select>

Nico.

Keith Sader a écrit :

>IMO this is a design smell of the presentation layer.
>
>My suggestion would be to refactor these items down to the
>'business-layer' and then have your actions put the results of that
>layer into the form/display bean.
>
>Then the .jsp could just look like <c:out value='${order.smallOrderFeeLimit}'/>
>
>There may be more to this with your particular site, but that's a
>first off-the-cuff guess.
>
>hth,
>
>
>On 2/8/06, Keith Fetterman <kf...@go2marine.com> wrote:
>
>  
>
>>We are converting old JSP pages to Struts and JSTL and I am running into
>>a problem.  On the old JSP pages, we have some calls to static methods
>>in scriptlets and runtime expressions.  On the new JSP pages, we have
>>disabled scriptlets and runtime expressions.  Here is an example:
>>
>>The old code will have an expression like:
>><%= OrderRulesBean.getSmallOrderFeeLimit() %>
>>
>>What is the best way (best practice or easiest to implement) to access
>>static methods in the JSP pages without resorting to runtime expressions?
>>    
>>
>
>--
>Keith Sader
>ksader@gmail.com
>http://www.saderfamily.org/roller/page/ksader
>http://www.jroller.com/page/certifieddanger
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>  
>

This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient,  you are not authorized to read, print, retain, copy, disseminate,  distribute, or use this message or any part thereof. If you receive this  message in error, please notify the sender immediately and delete all  copies of this message.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Accessing static methods from Struts/JSTL

Posted by Keith Sader <ks...@gmail.com>.
IMO this is a design smell of the presentation layer.

My suggestion would be to refactor these items down to the
'business-layer' and then have your actions put the results of that
layer into the form/display bean.

Then the .jsp could just look like <c:out value='${order.smallOrderFeeLimit}'/>

There may be more to this with your particular site, but that's a
first off-the-cuff guess.

hth,


On 2/8/06, Keith Fetterman <kf...@go2marine.com> wrote:

> We are converting old JSP pages to Struts and JSTL and I am running into
> a problem.  On the old JSP pages, we have some calls to static methods
> in scriptlets and runtime expressions.  On the new JSP pages, we have
> disabled scriptlets and runtime expressions.  Here is an example:
>
> The old code will have an expression like:
> <%= OrderRulesBean.getSmallOrderFeeLimit() %>
>
> What is the best way (best practice or easiest to implement) to access
> static methods in the JSP pages without resorting to runtime expressions?

--
Keith Sader
ksader@gmail.com
http://www.saderfamily.org/roller/page/ksader
http://www.jroller.com/page/certifieddanger

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org