Re: constant strings in the tags
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"%> HTH, -ed On 1/24/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- "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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: constant strings in the tags
On 1/24/06, Dave Newton <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Surely they thought about this and decided there was some reason not to > > make the constants available in the tags. Or was it just too difficult a > > task for some finite period of development time? > > Probably not the right forum to ask. > Well, I'm not sure how you'd differentiate between a named, scoped bean > and a fully-specified class name except by checking for a named, scoped > bean and if that fails looking up a class definition. You could add a > parameter to tags, but that wouldn't help for JSP 2.0 non-tag EL > expressions. Maybe by declaring a package name somewhere you could > finagle a way around it, but still seems warty. > package constants; public class Foo { public static final String BAR = "bar"; //... } elsewhere, in a JSP 2.0 page: ${foo.BAR} <%-- Line of interest --%> The issue I quoted earlier says the above line should have the *desired* effect. -Rahul > > Dave > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: constant strings in the tags
[EMAIL PROTECTED] wrote: > Surely they thought about this and decided there was some reason not to make > the constants available in the tags. Or was it just too difficult a task for > some finite period of development time? > Well, I'm not sure how you'd differentiate between a named, scoped bean and a fully-specified class name except by checking for a named, scoped bean and if that fails looking up a class definition. You could add a parameter to tags, but that wouldn't help for JSP 2.0 non-tag EL expressions. Maybe by declaring a package name somewhere you could finagle a way around it, but still seems warty. Dave - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: constant strings in the tags
Surely they thought about this and decided there was some reason not to make the constants available in the tags. Or was it just too difficult a task for some finite period of development time? --- On Tue 01/24, Dave Newton < [EMAIL PROTECTED] > wrote: From: Dave Newton [mailto: [EMAIL PROTECTED] To: user@struts.apache.org Date: Tue, 24 Jan 2006 11:12:09 -0500 Subject: Re: constant strings in the tags [EMAIL PROTECTED] wrote:> But I want to be able to do something like>> >>> I've never actually tried this. Maybe I should before posting this, but I don't know why it would work. I thought the EL only had access to bean properties? So why would it be able to access a field directly?> Ah. Can't.Sucks, huh? As Rahul said, push for the fix.In general, when I've dealt with strong separation between presentationand back-end teams, I've just said "Hey, you have access to somethingthrough the 'user' name and here's what a 'user' has for you..." If itneeds to change (I don't think I've ever actually changed one) then Iwould have just passed on the change.One project I was marginally involved on (over-)used custom tags tohandle issues like this, so the page designer would just say etc. Didn't care for it myself, but JSP 2.0 didn'texist yet, and we were all pretty anti-scriptlet, so hey.Dave-To unsubscribe, e-mail: [EMAIL PROTECTED] additional commands, e-mail: [EMAIL PROTECTED] ___ Join Excite! - http://www.excite.com The most personalized portal on the Web! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: constant strings in the tags
[EMAIL PROTECTED] wrote: > But I want to be able to do something like > > > > > I've never actually tried this. Maybe I should before posting this, but I > don't know why it would work. I thought the EL only had access to bean > properties? So why would it be able to access a field directly? > Ah. Can't. Sucks, huh? As Rahul said, push for the fix. In general, when I've dealt with strong separation between presentation and back-end teams, I've just said "Hey, you have access to something through the 'user' name and here's what a 'user' has for you..." If it needs to change (I don't think I've ever actually changed one) then I would have just passed on the change. One project I was marginally involved on (over-)used custom tags to handle issues like this, so the page designer would just say etc. Didn't care for it myself, but JSP 2.0 didn't exist yet, and we were all pretty anti-scriptlet, so hey. Dave - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: constant strings in the tags
On 1/24/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Here's what I usually do: > > > request.setAttribute( Constants.USER, userObject ); > > and the Constants.java defines > > public final static String USER = "theUser"; > > then in the JSP > > > > > But I want to be able to do something like > > > > > I've never actually tried this. Maybe I should before posting this, but I > don't know why it would work. I thought the EL only had access to bean > properties? So why would it be able to access a field directly? > > Known issue, push for it to be resolved here: https://jsp-spec-public.dev.java.net/issues/show_bug.cgi?id=145 -Rahul - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: constant strings in the tags
Here's what I usually do: request.setAttribute( Constants.USER, userObject ); and the Constants.java defines public final static String USER = "theUser"; then in the JSP But I want to be able to do something like I've never actually tried this. Maybe I should before posting this, but I don't know why it would work. I thought the EL only had access to bean properties? So why would it be able to access a field directly? --- On Tue 01/24, Dave Newton < [EMAIL PROTECTED] > wrote: From: Dave Newton [mailto: [EMAIL PROTECTED] To: user@struts.apache.org Date: Tue, 24 Jan 2006 10:48:11 -0500 Subject: Re: constant strings in the tags [EMAIL PROTECTED] 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 youcan'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 JSPyou'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 JSPpage by <%@ page import="..."%>-ing it. You can access things by puttingthem into scope. You can put strings into a resource file and accessthem from both JSP and code, and you get automagically I18Nized to boot.Dave-To unsubscribe, e-mail: [EMAIL PROTECTED] additional commands, e-mail: [EMAIL PROTECTED] ___ Join Excite! - http://www.excite.com The most personalized portal on the Web! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: constant strings in the tags
[EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]