Accessing a dynamic value in EL

2004-04-20 Thread Josh Holtzman
Hello my friends,

 

I am currently accessing a value for output by using the following EL
syntax:

 

c:out value=${sessionScope.USER_CONTAINER.account.userName} /

 

USER_CONTAINER is the key I use to store my UserContainer object in the
session.

 

I have created a global variable to identify the USER_CONTAINER.  It can be
accessed in a constant's class by the static variable AppConstants.USER_KEY.

 

Is it possible using Struts-EL to replace the literal USER_CONTAINER with
the variable AppConstants.USER_KEY, so as to write something like this:

 

c:out value=${sessionScope.%= AppConstants.USER_KEY%.account.userName}
/

 

This will not compile properly, so, either this is not possible, or my
syntax is incorrect.

 

Does anyone have any other suggestions?  

 

I'd rather use the constant to look up this value rather than a literal.  In
the event I need to change the name of the key to look up this value in the
session, I can then change it in one place rather than all the JSP pages
that make similar lookups.

 

Thanks in advance.

 

Regards,

 

Josh Holtzman

American Data Company

[EMAIL PROTECTED]

Voice: (310) 470-1257

Fax:(310) 362-8454

 

Sun Microsystems iForce Partner

 



RE: Accessing a dynamic value in EL

2004-04-20 Thread Karr, David
The EL only references scoped variables, not scriptlet variables.
Read the JSTL specification for a good summary of what you can do with
it.

If you have a small number of constants, then put your constants
directly into a scoped variable (application-scoped, most likely).  So,
if you define a scoped variable named USER_KEY, you could do this:

c:out value=${sessionScope[USER_KEY].account.userName}/

 -Original Message-
 From: Josh Holtzman [mailto:[EMAIL PROTECTED] 
 
 I am currently accessing a value for output by using the following EL
 syntax:
 
 c:out value=${sessionScope.USER_CONTAINER.account.userName} /
 
 USER_CONTAINER is the key I use to store my UserContainer 
 object in the session.
 
 I have created a global variable to identify the 
 USER_CONTAINER.  It can be accessed in a constant's class by 
 the static variable AppConstants.USER_KEY.
 
 Is it possible using Struts-EL to replace the literal 
 USER_CONTAINER with the variable AppConstants.USER_KEY, so as 
 to write something like this:
 
 c:out value=${sessionScope.%= 
 AppConstants.USER_KEY%.account.userName}
 /
 
 This will not compile properly, so, either this is not 
 possible, or my syntax is incorrect.
 
 Does anyone have any other suggestions?  
 
 I'd rather use the constant to look up this value rather than 
 a literal.  In the event I need to change the name of the key 
 to look up this value in the session, I can then change it in 
 one place rather than all the JSP pages that make similar lookups.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Accessing a dynamic value in EL

2004-04-20 Thread Josh Holtzman
Thank you David.



Josh Holtzman

American Data Company

[EMAIL PROTECTED]

Voice: (310) 470-1257

Fax:(310) 362-8454

 

Sun Microsystems iForce Partner


-Original Message-
From: Karr, David [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, April 20, 2004 9:43 AM
To: Struts Users Mailing List
Subject: RE: Accessing a dynamic value in EL

The EL only references scoped variables, not scriptlet variables.
Read the JSTL specification for a good summary of what you can do with
it.

If you have a small number of constants, then put your constants
directly into a scoped variable (application-scoped, most likely).  So,
if you define a scoped variable named USER_KEY, you could do this:

c:out value=${sessionScope[USER_KEY].account.userName}/

 -Original Message-
 From: Josh Holtzman [mailto:[EMAIL PROTECTED] 
 
 I am currently accessing a value for output by using the following EL
 syntax:
 
 c:out value=${sessionScope.USER_CONTAINER.account.userName} /
 
 USER_CONTAINER is the key I use to store my UserContainer 
 object in the session.
 
 I have created a global variable to identify the 
 USER_CONTAINER.  It can be accessed in a constant's class by 
 the static variable AppConstants.USER_KEY.
 
 Is it possible using Struts-EL to replace the literal 
 USER_CONTAINER with the variable AppConstants.USER_KEY, so as 
 to write something like this:
 
 c:out value=${sessionScope.%= 
 AppConstants.USER_KEY%.account.userName}
 /
 
 This will not compile properly, so, either this is not 
 possible, or my syntax is incorrect.
 
 Does anyone have any other suggestions?  
 
 I'd rather use the constant to look up this value rather than 
 a literal.  In the event I need to change the name of the key 
 to look up this value in the session, I can then change it in 
 one place rather than all the JSP pages that make similar lookups.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]