You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by David Goodenough <da...@btconnect.com> on 2002/06/24 17:06:14 UTC

selecting options

I am trying to convert from code from old (lots of embeded java) JSP to new
(no embeded java) using JSTL.  I have select objects (dropdown) that I want
to pre-select to its previous value after the form is posted back to itself,
so I used code of the form:

<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. 

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.

I am using the version of taglibs in the Sun JWSDP 1.0 package with tomcat
4.0.3.

Regards

David

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>