tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Asleson, Ryan" <asle...@BIWORLDWIDE.com>
Subject Dynamic Expressions for Struts-EL and JSTL
Date Thu, 02 Sep 2004 13:37:12 GMT

Hello,

I'm using the Struts-EL and JSTL custom tag implementations in my Web app.

I want to use the c:out tag to output dynamic data.  The tricky part is I
want to dynamically build the EL expression at runtime by building up a
String that should be evaluated.  I don't want to output the String, I want
the String to be evaluated by the expression engine and then that written
out.  An example follows below.



<%
//Assume that after this line runs, expr has a value of
formBean.property.value 
//This is the expression I want evaluated
String expr = "formBean." +
((app.LayoutObject)pageContext.getAttribute("layoutObject")).getProperty();

pageContext.setAttribute("expr", expr);
%>

<c:out value="Expression Value is: ${expr}" />



The c:out tag above renders the text Expression Value is:
formBean.property.value  .

This isn't what I want -- I want it to evaluate the formBean.property.value
down to an expression, and then spit out the value of that expression
(basically, formBean.getProperty().getValue() ).

Interestingly, if I "hard code" the expression, it works:

<c:out value="${formBean.property.value}"/>

The only problem is I need to dynamically change this expression at runtime.

Can this be done?  If so, how?  I'm hoping so otherwise I'll have a mountain
of new code to write.  Also, is there a more elegant way to do what I show
in the example above, like using tags instead of scriptlets?  I don't care
if I use Struts-EL tags, JSTL tags, or both.

Thank you very much!!

This e-mail message is being sent solely for use by the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution is prohibited.
 If you are not the intended recipient, please contact the sender by phone or reply by e-mail,
delete the original message and destroy all copies. Thank you.

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


Mime
View raw message