You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "chadmichael@excite.com" <ch...@excite.com> on 2006/01/24 16:39:19 UTC

constant strings in the tags




In my action classes, and other java classes, I use defined constants for my Strings.  This is a common best practice.  

One frequent location of this practice is the names for the attributes I set on the session and request ojbects.  Most of the time, I then access these attributes on my JSP pages via various struts and jstl tags.  But when I reference these objects from the JSP side, I find that I can't use defined constants.  This undermines like 50% of the benefit of using defined constants for my attribute names.  

Since the strust platform seems to demonstrate best practices most of the time, I find it hard to believe that there isn't some what to use defined constants in the JSP side.  I guess that isn't strut's realm, strictly speaking.  It seems that if the JSP is really just a servlet, then surely I can use the defined constants just as I do from java code.  But I don't know how to do this.  Anybody know how?

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!



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


Re: constant strings in the tags

Posted by Dave Newton <ne...@pingsite.com>.
chadmichael@excite.com wrote:
> One frequent location of this practice is the names for the attributes I set on the session and request ojbects.  Most of the time, I then access these attributes on my JSP pages via various struts and jstl tags.  But when I reference these objects from the JSP side, I find that I can't use defined constants.  This undermines like 50% of the benefit of using defined constants for my attribute names.  
>   
Huh, don't know why you wouldn't be able to do that.

Wait: you say you access the attributes on the JSP page but then say you
can't reference the objects on the JSP side.

Are you saying that you do something like
:request.setAttribute(foo.bar.attributeNames.BAZ, results) but in JSP
you're not able to do the same thing?
> But I don't know how to do this.  Anybody know how?
>   
What, exactly, are you trying to do? You can access anything on a JSP
page by <%@ page import="..."%>-ing it. You can access things by putting
them into scope. You can put strings into a resource file and access
them from both JSP and code, and you get automagically I18Nized to boot.

Dave



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


Re: constant strings in the tags

Posted by Ed Griebel <ed...@gmail.com>.
I've just started using the taglib "unstandard" in the Jakarta Sandbox
which has a JSP tag that does exactly what you want. Say you have a
class called org.myorg.Constants, this tag creates an associative
array of the members like so:
<%@ taglib uri="http://jakarta.apache.org/taglibs/unstandard-1.0" prefix="un"%>
<un:useConstants var="Constants" className="org.myorg.Constants"/>
<c:out value="My constant value: ${Constants.FOO}"/>

HTH,
-ed

On 1/24/06, chadmichael@excite.com <ch...@excite.com> wrote:
>
>
>
>
> In my action classes, and other java classes, I use defined constants for my Strings.  This is a common best practice.
>
> One frequent location of this practice is the names for the attributes I set on the session and request ojbects.  Most of the time, I then access these attributes on my JSP pages via various struts and jstl tags.  But when I reference these objects from the JSP side, I find that I can't use defined constants.  This undermines like 50% of the benefit of using defined constants for my attribute names.
>
> Since the strust platform seems to demonstrate best practices most of the time, I find it hard to believe that there isn't some what to use defined constants in the JSP side.  I guess that isn't strut's realm, strictly speaking.  It seems that if the JSP is really just a servlet, then surely I can use the defined constants just as I do from java code.  But I don't know how to do this.  Anybody know how?
>
> _______________________________________________
> Join Excite! - http://www.excite.com
> The most personalized portal on the Web!
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


--
    "The greatest tyrannies are always perpetrated in the name of the
noblest causes." Thomas Paine
    "Those who would give up essential Liberty, to purchase a little
temporary Safety, deserve neither Liberty nor Safety" - Benjamin
Franklin

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