tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Einfeldt" <ralph.einfe...@uptime-isc.de>
Subject AW: JSP not returning full page problem
Date Fri, 22 Feb 2002 17:14:25 GMT
Not Faster but less redundancy:

String mSelected
for (int a=1;a<32;a++)
    {
    if ( a==day )
      mSelected = "SELECTED";
    } else {
      mSelected = "";
    } 
    %>
    <OPTION <%= mSelected %>  VALUE="<%= a %>"><%= a %></OPTION>
    <%
} 
%>

Or a bit shorter but harder to read:

<% for (int a=1;a<32;a++) { %>
    <OPTION <% if ( a==day ) { %><%= SELECTED %><% } %> VALUE="<%=
a
%>"><%= a %></OPTION>
<% } %>

Or even shorter:
<% for (int a=1;a<32;a++) { %>
    <OPTION <%= (a==day) ? "SELECTED" : "" %> VALUE="<%= a %>"><%= a
%></OPTION>
<% } %>

Or if you need this in more places:

<%!
String getSelected(boolean aSelected) {
  if (aSelected) {
    return "SELECTED";
  } else {
    return "":
  }
}
%>
<% for (int a=1;a<32;a++) { %>
    <OPTION <%= getSelected(a==day)) %> VALUE="<%= a %>"><%= a
%></OPTION>
<% } %>

> -----Urspr√ľngliche Nachricht-----
> Von: David Cassidy [mailto:dcassidy@hotgen.com]
> Gesendet: Freitag, 22. Februar 2002 17:49
> An: Tomcat Users List
> Betreff: Re: JSP not returning full page problem
<snip/> 
> would be easier as ..
> 
> for (int a=1;a<32;a++)
>     {
>     if ( a==day )
>         out.write("<OPTION SELECTED  VALUE=\"" + a +"\">" 
> +a+"</OPTION>\n");
>     else
>           out.write("<OPTION  VALUE=\"" + a +"\">" +a+"</OPTION>\n");
>      }
<snip/>

--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message