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}"/>.

Anyway, please let us know if you need more help.

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

Hope that helps,

-- 
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com
(coming in July 2002 from Manning Publications)


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

Reply via email to