Like EL, is it possible to use any OGNL expressions outside of the s: tags in regular HTML?
e.g., if I wanted to get the value of some bean in EL I would do something like <div>${beanName.propertyName}
within DIV
blocks or something.
How can this be done using OGNL. I've got a code block:
<s:iterator value="parentBean.qna" var="questionAndAnswers"
status="qIndex">
<li>
<s:label theme="simple"
value="Question %{#qIndex.index+1} - %{#questionAndAnswers.question}"/>
<ul>
<s:iterator value="%{#questionAndAnswers.answers}" var="answer" status="answersStat">
<li>
<input type="radio" name="parentBean.answerMap['%{qIndex}']" />'
value='<s:property value="%{#answersStat.index}"/>'><s:property value="%{#answer}" /></input>
</li>
</s:iterator>
</ul>
<br/>
</li>
</s:iterator>
Where it says input type="radio" name="parentBean.answerMap['%{qIndex}']" ...
I want the value of qIndex
to be replaced dynamically with the current index so that the value can be set to the corresponding key at the back. So, if it was parentBean.answerMap[1]
, I'm assuming the map at the Action would have the key=1
and value of the input.
Any help?
Not using OGNL syntax, no; JSP doesn't know anything about OGNL.
S2's request wrapper will allow querying the value stack using JSP EL syntax (${}
) but I don't believe that will extend to named values (values that aren't pushed on to the stack, like the iterator index).
Of course, you don't need to–use <s:property value="#qIndex.index"/>
in your tag's attributes, just like you do for the value
attribute.