Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: format code

  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,958
    Thanks
    120
    Thanked 76 Times in 76 Posts

    format code

    Code:
    ....
    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 ?

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    there are no specific rules as such...but, you can define your own to improve readability...its going to be difficult to follow though
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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;' ";
    &#37;>
    <a class = "knof" <%= bg %> ...
    <%
    }
    .....

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by LoriQuaid View Post
    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 (tutorial - part1, part2)
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •