PDA

View Full Version : format code


BubikolRamios
10-12-2008, 08:10 PM
....
while(con.rs.next())
{
%>
<a class = "knof" <%if (con.rs.getString("grupa").equals("2")) { %>style = "background:#43E87F;"<%}else if (con.rs.getString("grupa").equals("1")){%> style = "background:#CC9F1B;"<%}else{%> style = "background:#6798E0;" <%}%>> <%=con.rs.getString("naziv")%></a>
<%
}
.....


How to format this, are there any rules about that ?

shyam
10-15-2008, 01:14 PM
there are no specific rules as such...but, you can define your own to improve readability...its going to be difficult to follow though :(

LoriQuaid
10-15-2008, 06:11 PM
Try putting your conditional logic in a single scriplet which sets a local variable. For example:

....
while(con.rs.next())
{
String bg = "style = 'background:";
if (con.rs.getString("grupa").equals("2"))
bg += "#43E87F;' ";
else if (con.rs.getString("grupa").equals("1"))
bg += "#CC9F1B;' ";
else
bg += "#6798E0;' ";
%>
<a class = "knof" <%= bg %> ...
<%
}
.....

shyam
10-15-2008, 06:52 PM
Try putting your conditional logic in a single scriplet which sets a local variable.

actually its better not to use scriptlets at all...they can be a huge source of pain when trying to fix bugs later...instead use JSTL (http://java.sun.com/products/jsp/jstl/index.jsp) (tutorial - part1 (http://www.onjava.com/pub/a/onjava/2002/03/13/jsp.html), part2 (http://www.onjava.com/pub/a/pub/a/onjava/2002/05/08/jstl.html))