On Monday 24 June 2002 16:13, you wrote:
> On Mon, 24 Jun 2002, David Goodenough wrote:
> > <c:set var="group" value="${param.group}">
> > <select name="group">
> >   <option>Default value</option>
> >   <c:forEach var="g" items="${groups.rows}">
> >     <option <c:if test="${group == g.group}">selected</c:if>>
> >       <c:out value="g.group"/>
> >       </option>
> >     </forEach>
> >   </select>
> >
> > where there is a field called group in each row of the DB.  Doing such
> > comparisons in the old code with group.equals( newGroup) checks
> > returning selected when true used to work nicely.
> >
> > But even when the value of the variable group is equal to the value of
> > g.group the text does not emit selected into the option.
>
> I think we'll need a bit more information to help, because the comparison
> you have *should* work.  Try
>
>   <c:out value="group = '${group}'; g.group = '${g.group}'"/>
>
> before the <c:if> tag to see what the values currently are, for each round
> of the iteration.
>
> Note also that <c:out value="g.group"/> will output the text "g.group"
> literally; I think you probably mean <c:out value="${g.group}"/>.
yes, finger trouble.
>
> Anyway, please let us know if you need more help.
For some reason, possibly browser caching, otherwise I have no idea why,
it started working.  So this one is now closed, sorry to have bothered you.
>
> > As a side question what is the recommended sequence of tags to load up
> > the previous form value of a field into a variable.  I seem to have lots
> > of code of the form:-
> >
> > <c:set var="group" value="${param.group}">
> > <c:if test="${empty group}">
> >   <c:set var"group" value="some default value" />
> >   </c:if>
> >
> > at the top of my code.  There must be a better way.
>
> The <c:out> tag, which I assume you'll be using to output the final value
> of 'group' here, supports a 'default' attribute that takes care of this
> case.  Thus, you could write
>
>   <c:out value="${param.group}" default="some default value"/>
>
Are, well actually no, the next thing I want to do with these values is
typically some validation or calculation based on the values, not simply 
return them to the HTML stream for next time around.  What I want is the
same as the default attribute on the c:out on c:set, so that if the value
is null the default is used.  It could be done using the conditional 
assignment, so something like:-

<c:set var="group" value="${empty param.group ? default : param.group}" />

but again that is ugly and not entirely obvious. 

Now I realise that just after 1.0 is released is a bad time to raise this, 
so perhaps this should be a thought piece for the next release?

> Hope that helps,

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to