struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeromy Evans <jeromy.ev...@blueskyminds.com.au>
Subject Re: OGNL Help
Date Wed, 06 Aug 2008 12:16:36 GMT
Zoran Avtarovski wrote:
> I¹m trying to achieve something with OGNL and I¹d like to know if it¹s
> possible and if so how to do it.
>
> In my action I have an object called surveyResult with setter/getter. I also
> have another object called questions with setter/getter.
>
> The question object has a string element called questionEntity which is in
> this case equal to ŒsurveyResult.initialvalue¹
>
> What I want to be able to do is use the value from the surveyEntity to get a
> value from the survey object.
>
> I¹ve tried <s:property value="%{questionEntity}"/> which just gives me
> ŒsurveyResult.intialvalue¹. Is there any way I can actually call
> surveyResult.intialvalue and get the stored value in surveyResult?
>
>
> Z.
>
>
>   

So, I understand that:
surveyResult.questionEntity="surveyResult.initialValue" (a String)
and you want to perform a nested evaluation:

eg.
interimResult = evaluate("surveyResult.questionEntity");
finalResult = evaluate(interimResult);

The s:property tag does recognise nested expressions. My guess is this:

<s:property value="#root.%{surveyResult.questionEntity}/>

which reads: evaluate surveyResult.questionEntity, then get the property 
with that name from the value stack.

**BUT, I can't remember if #root is right, or #stack, or #context.stack 
#top or something like that; whatever it is that refers to the value 
stack directly. This may be visible for the config browser.

The map notation may be clearer

<s:property value="#root[surveyResult.questionEntity]/>

In the worst case, you can invoke a method directly to get the stack.

Hope that helps a little,
Jeromy Evans

PS. I don't think this is a good idea as it is may be vulnerable to 
injecting OGNL expressions depending on how surveyResult.questionEntity 
is set.



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


Mime
View raw message