I would try to fiddle around with incorrectQs to see why .contains
isn't working... I'm guessing that if you iterate both lists, although
not efficient, you might get better results -

<s:iterator value="questions" id="question">
<s:iterator value="incorrectQs" id="incorrectQ">
  <s:if test='%{#incorrectQ == #question.questionId}'>
    <div style="color: red; padding-bottom: 5px;">Print Something</div>
  </s:if>
</s:iterator>
</s:iterator>



On Wed, Aug 5, 2009 at 12:22 PM, Bhaarat Sharma<bhaara...@gmail.com> wrote:
> looks like it is not working only in contains.I tried the following:
>
> <s:iterator value="questions" status="status" id="question">
>        <s:if test='%{incorrectQs.contains(#question.questionId)}'>
>            <div style="color: red; padding-bottom: 5px;">Print
> Something</div>
>        </s:if>
>        <s:else>
>             <s:property value="#question.questionId"/> <!--Line 6-->
>        </s:else>
> </s:iterator>
>
> Line 6 prints fine and prints questionId...:(
>
> On Wed, Aug 5, 2009 at 12:09 PM, Bhaarat Sharma <bhaara...@gmail.com> wrote:
>
>> thanks for the explanation chris. but using what you suggested is not
>> making Print Something appear even once. so the test statement is never
>> evaluated to true. ...leading me to suspect that ognl expression is not
>> working.
>> I am not sure whether the random error that is happening for us is being
>> caused by using ${}. Now that you mentioned it is a security concern to use
>> that expression under s: tags I am ready to change it to #...considering I
>> find the syntax to do it..
>>
>>
>> On Wed, Aug 5, 2009 at 11:54 AM, Chris Pratt <thechrispr...@gmail.com>wrote:
>>
>>> You must be using a fairly old version of Struts 2.  The difference
>>> between
>>> the ${} and the # versions is that the ${} is a JSTL EL expression that is
>>> no longer allowed inside struts (s:) tags for security reasons.  The #
>>> version is OGNL and references the variable that Wes tried to define.  Try
>>> using the id attribute instead of the var attribute.  So something more
>>> like
>>> this:
>>>
>>> <s:iterator value="%{questions}" status="status" id="question">
>>>    <s:if test='%{incorrectQs.contains(#question.questionId)}'>
>>>        <div style="color: red; padding-bottom: 5px;">Print Something</div>
>>>    </s:if>
>>> </s:iterator>
>>>
>>> I like to make it obvious which attributes use OGNL by enclosing them in
>>> %{}
>>>   (*Chris*)
>>>
>>> On Wed, Aug 5, 2009 at 8:43 AM, Bhaarat Sharma <bhaara...@gmail.com>
>>> wrote:
>>>
>>> > oh and attribute 'var' seems to be invalid according to the TLD
>>> >
>>> > On Wed, Aug 5, 2009 at 11:42 AM, Bhaarat Sharma <bhaara...@gmail.com>
>>> > wrote:
>>> >
>>> > > ok thanks Wes. yeah that is def. more readable.
>>> > > could you please tell me what the difference is in doing
>>> > >     <s:if test='incorrectQs.contains("${questionId}")'>
>>> > > VS.
>>> > >     <s:if test='incorrectQs.contains(#question.questionId)'>
>>> > >
>>> > > beside the question.questionId part. I am more concerned about
>>> difference
>>> > > in '$' vs. '#'
>>> > >
>>> > >
>>> > > On Wed, Aug 5, 2009 at 11:39 AM, Wes Wannemacher <w...@wantii.com>
>>> > wrote:
>>> > >
>>> > >> I think this would be more readable -
>>> > >>
>>> > >> <s:iterator value="questions" status="status" var="question">
>>> > >>    <s:if test='incorrectQs.contains(#question.questionId)'>
>>> > >>         <div style="color: red; padding-bottom: 5px;">Print
>>> > >> Something</div>
>>> > >>     </s:if>
>>> > >> </s:iterator>
>>> > >>
>>> > >> -Wes
>>> > >>
>>> > >> On Wed, Aug 5, 2009 at 11:35 AM, Bhaarat Sharma<bhaara...@gmail.com>
>>> > >> wrote:
>>> > >> > I have the following code in a jsp
>>> > >> > Line1: <s:iterator value="questions" status="status">
>>> > >> > Line2:    <s:if test='incorrectQs.contains("${questionId}")'>
>>> > >> > Line3:        <div style="color: red; padding-bottom: 5px;">Print
>>> > >> > Something</div>
>>> > >> > Line4:    </s:if>
>>> > >> > Line5:</s:iterator>
>>> > >> >
>>> > >> > On Line1 questions is a list.  This list contains object of class
>>> > Exam.
>>> > >> > Class Exam has a getter/setter questionId
>>> > >> > On Line2 incorrectQs is a list.  This list contains strings.
>>> > >> >
>>> > >> > I am checking to see if list in Line2 contains a questionId that is
>>> in
>>> > >> > questions list on line1.
>>> > >> >
>>> > >> > Is this the best way to do this?
>>> > >> >
>>> > >> > the code seems to be working but 'randomly' sometimes Line2 never
>>> > seems
>>> > >> to
>>> > >> > be true ...when we know it IS true.
>>> > >> >
>>> > >> > I just want to make sure with some experienced people whether this
>>> is
>>> > >> the
>>> > >> > way to achieve this?
>>> > >> >
>>> > >>
>>> > >>
>>> > >>
>>> > >> --
>>> > >> Wes Wannemacher
>>> > >>
>>> > >> Head Engineer, WanTii, Inc.
>>> > >> Need Training? Struts, Spring, Maven, Tomcat...
>>> > >> Ask me for a quote!
>>> > >>
>>> > >> ---------------------------------------------------------------------
>>> > >> To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
>>> > >> For additional commands, e-mail: user-h...@struts.apache.org
>>> > >>
>>> > >>
>>> > >
>>> >
>>>
>>
>>
>



-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

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

Reply via email to