tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Karr, David" <david.k...@wamu.net>
Subject RE: Dynamic Expressions for Struts-EL and JSTL
Date Thu, 02 Sep 2004 16:09:29 GMT
I wonder if you need something like this:

  ${formBean[layoutObject.property][layoutObject.property2]}

Where "layoutObject.property" is "userInfo" and "layoutObject.property2"
is "firstName".

That will obviously be a litter harder to construct, but determining
whether this works would be one step forward.

> -----Original Message-----
> From: Asleson, Ryan [mailto:asleson@BIWORLDWIDE.com] 
> Sent: Thursday, September 02, 2004 8:33 AM
> To: 'taglibs-user@jakarta.apache.org'
> Subject: RE: Dynamic Expressions for Struts-EL and JSTL
> 
> 
> 
> We must be close.  I tried this:
> 
> 
> <c:out value="${formBean[layoutObject.property]}"/>
> (Assume that layoutObject.property evaluates to a String of
> userInfo.firstName)
> 
> 
> And the container threw this exception:
> 
> 
> 
> [ServletException in:/jsp/registration/registerDisplay.jsp] 
> An error occurred while evaluating custom action attribute 
> "value" with value
> "${formBean[layoutObject.property]}": Unable to find a value 
> for "userInfo.firstName" in object of class "app.MyFormBean" 
> using operator "[]" (null)' javax.servlet.jsp.JspException: 
> An error occurred while evaluating custom action attribute 
> "value" with value
> "${formBean[layoutObject.property]}": Unable to find a value 
> for "userInfo.firstName" in object of class "app.MyFormBean" 
> using operator "[]"
> (null) at
> org.apache.taglibs.standard.lang.jstl.Evaluator.evaluate(Evalu
> ator.java:146)
> at
> 
> 
> 
> Like I said before, I want c:out to output the resulting 
> String of formBean.getUserInfo.getFirstName, but it won't do 
> it.  Any more ideas??  I have to believe this can be done 
> somehow using these tags.
> 
> 
> 
> 
> 
> 
> -----Original Message-----
> From: Helios Alonso [mailto:halonso@atg.com.uy]
> Sent: Thursday, September 02, 2004 9:48 AM
> To: Tag Libraries Users List
> Subject: Re: Dynamic Expressions for Struts-EL and JSTL
> 
> 
> 
> So, you could change this:
> 
> >String expr = "formBean." + 
> >((app.LayoutObject)pageContext.getAttribute("layoutObject")).
> getPropert
> >y();
> 
> to this:
> 
> formBean[pageContext.layoutObject.property]
> 
> (If I understood you have a layoutObject with a property saying which 
> property read from formBean).
> 
> At 08:37 02/09/2004 -0500, you wrote:
> 
> >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
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
> 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
> 
> 

---------------------------------------------------------------------
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