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 Soefara Redzuan <so...@hotmail.com> on 2002/05/10 05:27:15 UTC

Re: How to pre-select an option in a pull-down

As somebody kindly pointed out off list, it should be "if you are comparing 
strings, you need to use .equals not ==".  He is correct, and this made me 
realize that I didn't express the question clearly. I was actually trying to 
confirm whether the output from taglibs can be used within scriptlet 
expressions.

<% if (x == %><sql:getColumn colName="X"/><% ) { %>selected<% } %>

Because I keep getting JSP compiler errors. If <sql:getColumn colName="X"> 
returns the value Xval, is this in actual fact converted to the Java code 
out.write(Xval) ? If so, that will break the scriptlet.

How does one do such comparisons ?

Soefara Redzuan.


>From: "Soefara Redzuan" <so...@hotmail.com>
>Reply-To: "Tag Libraries Users List" <ta...@jakarta.apache.org>
>To: taglibs-user@jakarta.apache.org
>Subject: How to pre-select an option in a pull-down Date: Thu, 09 May 2002 
>19:50:02 +0800
>
>I wish to create a pull-down where the options are pulled from a database, 
>but pre-select one of the options depending on a scriptlet value. Here is 
>an easier example.
>
><%
>String chosencolor="red";
>%>
>
><select name="color">
>
><sql:preparedStatement id="stmt" conn="conn">
>  <sql:query>
>    select color from allcolors
>  </sql:query>
>  <sql:resultSet id="rset">
>  <option <% if (chosencolor == %><sql:getColumn colName="color"/><% ) { 
>%>selected<% } %>/>"><sql:getColumn colName="color"/>
>  </sql:resultSet>
></sql:preparedStatement>
>
></select>
>
>As you can see it's a mess on the option line and it doesn't work. :(
>How can I use the <sql: geColumn> output inside a scriptlet ?
>
>Again I must be overlooking something.
>
>Soefara Redzuan.
>
>_________________________________________________________________
>MSN Photos is the easiest way to share and print your photos: 
>http://photos.msn.com/support/worldwide.aspx
>
>
>--
>To unsubscribe, e-mail:   
><ma...@jakarta.apache.org>
>For additional commands, e-mail: 
><ma...@jakarta.apache.org>


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


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


Re: How to pre-select an option in a pull-down

Posted by Shawn Bayern <ba...@essentially.net>.
On Fri, 10 May 2002, Soefara Redzuan wrote:

> As somebody kindly pointed out off list, it should be "if you are comparing 
> strings, you need to use .equals not ==".  He is correct, and this made me 
> realize that I didn't express the question clearly. I was actually trying to 
> confirm whether the output from taglibs can be used within scriptlet 
> expressions.
> 
> <% if (x == %><sql:getColumn colName="X"/><% ) { %>selected<% } %>

You can't mix tags and scriptlets in this fashion.  If you want them to
collaborate, you'll need to do so explicity -- e.g., by storing a scoped
attribute and retrieving it in the scriptlet with PageContext.
findAttribute().

-- 
Shawn Bayern
"JSP Standard Tag Library"   http://www.jstlbook.com
(coming this summer from Manning Publications)


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