Solved

How to alternate table row background colors using JSTL?

Posted on 2003-07-29
41
4,385 Views
Last Modified: 2013-11-24

How to alternate table row background colors using JSTL?





 SQL is : <br>
  <c:out value='${rPipeStatus}' /> <BR> <BR>
  <c:out value='${rPipeStatus.rowCount}'/> rows returned
      <p>

Display Element Status and task -

<table border="1">
    <%-- Get the column names for the header of the table --%>
      <tr>
         <th> Name</th>
         <th> Task</th>
         <th> Status</th>
         <th>  Assigned</th>
      </tr>
    <%-- Get the value of each column while iterating over rows --%>

    <c:forEach var="rowData" items="${rPipeStatus.rows}">
       <tr>
<c:choose>
      <c:when test='${sName == rowData.str_name}'> <td>  <c:out value=  ''/></td> </c:when>
      <c:otherwise> <td>     <c:out value='${rowData.str_name}'/> <br>  <c:out value='${rowData.type}'/> </td> <c:set var= 'sName' value = '${rowData.str_name}'/>
      </c:otherwise>
</c:choose>
           <td><c:out value='${rowData.task}'/></td>
           <td><c:out value='${rowData.str_value}'/></td>
           <td><c:out value='${rowData.str_email1}'/> </td>
       </tr>
     </c:forEach>

</table>
0
Comment
Question by:sdesar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 22
  • 19
41 Comments
 
LVL 7

Expert Comment

by:tbone343
ID: 9033304
You just have to keep up with the rowNumber that you are on... if it is even than do one thing and odd do another thing.  you can probably use the old MOD 2 thing to check.  at any rate, this only amounts to adding one more if/then type of block with everything you have between forEach

in one case change all the <td> to:   <td bgcolor="#gg8899">

And in the other case change <td> to:  <td bgcolor="ffaaff">

so you see you only need an if/then block and to pick colors.
0
 

Author Comment

by:sdesar
ID: 9033809
I am new to JSTLs --- could you please give me the exact syntax, to plug it in to the code above...
thanks
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9034105
whoa... i'll do what i can for you.  but since there is no way for me to test what you have above on my computer, i'll write some code that is analogous.  you can then workout the differences, ok?  Here is my code:

<%@ page import="java.util.*" %>
<%@ taglib uri="/jstl-c" prefix="c" %>

<%
      Vector v = new Vector();
      v.addElement("ROW 1");
      v.addElement("ROW 2");
      v.addElement("ROW 3");
      v.addElement("ROW 4");
      pageContext.setAttribute("v",v);
      pageContext.setAttribute("index",new Integer(0));
%>


<table>

<c:forEach var="row" items="${v}">

      <tr>

            <c:if test="${index % 2 == 0}">
                  <td bgcolor="aabbcc">
                        <c:out value="${row}"/>
                  </td>
            </c:if>
      
            <c:if test="${index % 2 == 1}">
                  <td bgcolor="afaaff">
                        <c:out value="${row}"/>
                  </td>
            </c:if>

      </tr>
      
      <c:set var="index" value="${index + 1}"/>
      
</c:forEach>       

</table>
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

Author Comment

by:sdesar
ID: 9038175
Thanks for your help..
this is the code that I tried to implement and its not working... cam you please help me fix it...

<table border="1">
    <%-- Get the column names for the header of the table --%>
      <tr>
         <th> Name</th>
         <th> Task</th>
         <th> Status</th>
         <th>Email</th>

      </tr>

    <%-- Get the value of each column while iterating over rows --%>

    <c:forEach var="rowData" items="${rPipeStatus.rows}">
     <c:forEach  items="${rPipeStatus.rows}" var="current" varStatus="status" begin="0" end="${rPipeStatus.rowCount}">
       <c:set var="cellColor">
         <c:choose>
           <c:when test="${status.count % 2 == 1}">red</c:when>
           <c:otherwise>blue</c:otherwise>
         </c:choose>
       </c:set>
      </c:forEach>



       <tr>

      <c:choose>
      <c:when test='${sName == rowData.str_name}'> <td>  <c:out value=  ''/></td> </c:when>
      <c:otherwise> <td>     <c:out value='${rowData.str_name}'/> <br>  <c:out value='${rowData.type}'/> </td>
        <c:set var= 'sName' value = '${rowData.str_name}'/>
      </c:otherwise>
      </c:choose>

           <td bgcolor="${cellColor}"><c:out value='${rowData.task}'/></td>
           <td bgcolor="${cellColor}"><c:out value='${rowData.str_value}'/> </td>
           <td><c:out value='${rowData.str_email1}'/> </td>

      </tr>




     </c:forEach>

</table>

--Awaiting a response...
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9038453
  <c:forEach var="rowData" items="${rPipeStatus.rows}">
    <c:forEach  items="${rPipeStatus.rows}" var="current" varStatus="status" begin="0" end="${rPipeStatus.rowCount}">

what does this mean?  you should only have to loop over it once... this says that you are looping through the all the rows again on an inner loop.  my best guess w/o being able to run it looks something like:

    <c:forEach  items="${rPipeStatus.rows}" var="current" varStatus="status">
            <c:set var="cellColor">
                  <c:choose>
                        <c:when test="${status.count % 2 == 1}">red</c:when>
                        <c:otherwise>blue</c:otherwise>
                  </c:choose>
            </c:set>

            <tr>
            <c:choose>
                  <c:when test="${sName == rowData.str_name}">
                        <td bgcolor="${cellColor}"><c:out value=""/></td>
                  </c:when>
                  <c:otherwise>
                        <td><c:out value="${rowData.str_name}"/><br><c:out value="${rowData.type}"/></td>
                        <c:set var="sName" value="${rowData.str_name}"/>
                  </c:otherwise>
            </c:choose>
                  <td bgcolor="${cellColor}"><c:out value="${rowData.task}"/></td>
                  <td bgcolor="${cellColor}"><c:out value="${rowData.str_value}"/></td>
                  <td bgcolor="${cellColor}"><c:out value="${rowData.str_email1}"/></td>
            </tr>
    </c:forEach>


BY the way, <c:when test="${sName == rowData.str_name}"> at this line, have you defined what sName is?  you better take a look at that...
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9038468
OOPS, you also don't need

varStatus="status"

on your first line since this doesn't do anything... the variable "status" is taken care of for you
0
 

Author Comment

by:sdesar
ID: 9038735
BY the way, <c:when test="${sName == rowData.str_name}"> at this line, have you defined what sName is?  you better take a look at that...
sName -I need this and it works I am looking to see if the cell above has the same value if so dont display it.
example -
p1 test
p1 alex
P2 bob
P3 harry


I implemented the code as follows -


<table border="1">
    <%-- Get the column names for the header of the table --%>
      <tr>  
         <th> Asset</th>
         <th> Task</th>
         <th> Status</th>
         <th> Artist Assigned</th>

      </tr>

    <%-- Get the value of each column while iterating over rows --%>
   
    <c:forEach var="rowData" items="${rPipeStatus.rows}">

      <c:forEach  items="${rPipeStatus.rows}" var="current">
         <c:set var="cellColor">
              <c:choose>
                   <c:when test="${status.count % 2 == 1}"> <c:out value="${status.count}"/> red</c:when>
                   <c:otherwise>blue</c:otherwise>
              </c:choose>
         </c:set>

    <tr>

      <c:choose>
      <c:when test='${sName == rowData.str_name}'> <td>  <c:out value=  ''/></td> </c:when>
      <c:otherwise> <td>     <c:out value='${rowData.str_name}'/> <br>  <c:out value='${rowData.type}'/> </td>                    <c:set var= 'sName' value = '${rowData.str_name}'/>
      </c:otherwise>
      </c:choose>
     
         <td  bgcolor="${cellColor}"><c:out value='${rowData.task}'/></td>
         <td  bgcolor="${cellColor}"><c:out value='${rowData.str_value}'/> </td>
           <td><c:out value='${rowData.str_email1}'/> </td>
     
      </tr>

       </c:forEach>


     </c:forEach>

</table>

The result in the HTML - am am getting is
<td   bgcolor="${cellColor}">Complete </td>

for some reason bgcolor="${cellColor}"> is not being set to bgcolor="red">

awaiting suggestions ..

BTW - thanks fpr helping me
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9038797
ONCE AGAIN wat does this mean?

   <c:forEach var="rowData" items="${rPipeStatus.rows}">
     <c:forEach  items="${rPipeStatus.rows}" var="current">

you should only have ONE loop...  a row has data.  you make the columns yourself by <td> tags and using stuff like ${rowData.str_name} and ${rowData.task}.  what you have above means that you are looping through the rows twice.  look more closely at what i just posted last time.
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9038841
OOPS, i just checked something out...

   <c:forEach  items="${rPipeStatus.rows}" var="current" varStatus="status">

keep varStatus="status" in there... you need it.. i'm checking on your c:set right now
0
 
LVL 7

Accepted Solution

by:
tbone343 earned 500 total points
ID: 9038904
OK, this should enlighten you... I wrote a program that does the same thing you are trying to do with different data...  now watch how i only need one loop to loop about the rows.  the columns are made up by the properties of a given row...

<%@ page import="java.util.*" %>
<%@ taglib uri="/jstl-c" prefix="c" %>

<%! public class Person {

            private String first;
            private String last;
            private int age;
            
            public Person(String first, String last, int age) {
                  this.first = first;
                  this.last = last;
                  this.age = age;
            }
            
            public String getFirst() {return this.first;}
            
            public String getLast() {return this.last;}
            
            public int getAge() {return this.age;}
            
      }
%>

<%
      Vector v = new Vector();
      Person p1 = new Person("Janet", "Jackson", 35);
      Person p2 = new Person("Joe", "Schmoe", 10);
      Person p3 = new Person("Robert", "Smith", 25);
      Person p4 = new Person("Heather", "Gunns", 22);
      v.addElement(p1);
      v.addElement(p2);
      v.addElement(p3);
      v.addElement(p4);
      pageContext.setAttribute("v",v);
%>


<table>
      <tr>  
            <th>First Name</th>
            <th>Last Name</th>
            <th>Age</th>
      </tr>



<c:forEach var="row" items="${v}" varStatus="status">

      <tr>

        <c:set var="cellColor">
             <c:choose>
                  <c:when test="${status.count % 2 == 1}">gray</c:when>
                  <c:otherwise>yellow</c:otherwise>
             </c:choose>
        </c:set>

            <td bgcolor="<c:out value="${cellColor}"/>">
                  <c:out value="${row.first}"/>
            </td>

            <td bgcolor="<c:out value="${cellColor}"/>">
                  <c:out value="${row.last}"/>
            </td>

            <td bgcolor="<c:out value="${cellColor}"/>">
                  <c:out value="${row.age}"/>
            </td>

      </tr>
      
</c:forEach>       

</table>


This should clarify everything.
0
 

Author Comment

by:sdesar
ID: 9038936
Thanks I guess I was looping twice ...
here's what I have now -

<table border="1">
    <%-- Get the column names for the header of the table --%>
      <tr>
         <th> Name</th>
         <th> Task</th>
         <th> Status</th>
         <th> Email</th>

      </tr>

    <%-- Get the value of each column while iterating over rows --%>

    <c:forEach var="rowData" items="${rPipeStatus.rows}" varStatus="status">
         <c:set var="cellColor">
              <c:choose>
                   <c:when test="${status.count % 2 == 1}">red</c:when>
                   <c:otherwise>blue</c:otherwise>
              </c:choose>
         </c:set>
    <tr>

      <c:choose>
      <c:when test='${sName == rowData.str_name}'> <td>  <c:out value=  ''/></td> </c:when>
      <c:otherwise> <td>     <c:out value='${rowData.str_name}'/> <br>  <c:out value='${rowData.type}'/> </td>                    <c:set var= 'sName' value = '${rowData.str_name}'/>
      </c:otherwise>
      </c:choose>

         <td  bgcolor="${cellColor}" ><c:out value='${rowData.task}'/></td>
         <td><c:out value='${rowData.str_value}'/> </td>
           <td><c:out value='${rowData.str_email1}'/> </td>

      </tr>

     </c:forEach>

</table>



<br>

<c:out value='${rPipeStatus.rowCount}'/> rows returned <br>
<font size='1'>
<p>
<jsp:useBean id='now' class='java.util.Date' />
Date: <fmt:formatDate value='${now}' dateStyle='full' />
</body>
</html>



But still the result shows -
<td  bgcolor="${cellColor}" >Mirroring</td>

instead of the
<td  bgcolor="red" >Mirroring</td>
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9038956
Make a JSP page with what I just sent you, run it, and try to see the differences
0
 

Author Comment

by:sdesar
ID: 9038958
oops I made a mistake with the points - I wanted to assign 100 points .. how can I fix it?
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9038973
i don't think that you can.... why would you won't to take points away from me anyway?  :(
0
 

Author Comment

by:sdesar
ID: 9039015
Aweome ... thanks a million... now I know my mistake ...
<td bgcolor="<c:out value="${cellColor}"/>">


Thanks You.

0
 
LVL 7

Expert Comment

by:tbone343
ID: 9039032
no problem
0
 

Author Comment

by:sdesar
ID: 9050639
Also, how can I show the time it took to run the query -

so the code that I currently have just shows the row Count -
<c:out value='${rPipeStatus.rowCount}'/> rows returned <br>

How do I set the time at the beggin of the query and display the result of the time in the end of the query.

the code currently looks like this -
<html>
<head>
  <title>JSTL: SQL in action </title>
</head>
<body bgcolor="#FFFFFF">

  <sql:query var='rs' dataSource='jdbc/oracle'>
    select *from show
    where show.pk_show = shot.pk_show
     

  </sql:query>

  <font face="Arial, Helvetica, sans-serif">
  <c:out value='${rs.rowCount}'/> rows returned
  <p>

  <%-- An example showing how to populate a table --%>
  <table border="1">
    <%-- Get the column names for the header of the table --%>
    <c:forEach var="columnName" items="${rs.columnNames}">
      <th><c:out value="${columnName}"/></th>
    </c:forEach>

    <%-- Get the value of each column while iterating over rows --%>
    <c:forEach var="row" items="${rs.rows}">
      <tr>
      <c:forEach var="column" items="${row}">
        <td><c:out value="${column.value}"/></td>
      </c:forEach>
    </tr>
    </c:forEach>
  </table>

<font size='1'>
<p>
<jsp:useBean id='now' class='java.util.Date' />
Date: <fmt:formatDate value='${now}' dateStyle='full' />
</body>
</html>


Awaiting a response.
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9050995
I tell you what.  If you reward the points from the last question, then i'll try and help you out on the new one.  That seems fair.
0
 

Author Comment

by:sdesar
ID: 9051796
Here are your excellent points!
thanks for your help.
hipe to receive an answer soon.
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9051914
<html>
<head>
 <title>JSTL: SQL in action </title>
</head>
<body bgcolor="#FFFFFF">

<% long start = System.currentTimeMillis(); %>

 <sql:query var='rs' dataSource='jdbc/oracle'>
   select *from show
   where show.pk_show = shot.pk_show
 </sql:query>

<% long end = System.currentTimeMillis(); %>

 <font face="Arial, Helvetica, sans-serif">
 <c:out value='${rs.rowCount}'/> rows returned
 <p>

 <%-- An example showing how to populate a table --%>
 <table border="1">
   <%-- Get the column names for the header of the table --%>
   <c:forEach var="columnName" items="${rs.columnNames}">
     <th><c:out value="${columnName}"/></th>
   </c:forEach>

   <%-- Get the value of each column while iterating over rows --%>
   <c:forEach var="row" items="${rs.rows}">
     <tr>
     <c:forEach var="column" items="${row}">
       <td><c:out value="${column.value}"/></td>
     </c:forEach>
   </tr>
   </c:forEach>
 </table>

<font size='1'>
<p>

</body>
</html>


In the code above, end-start will give you the exact time the query took to go to the database and come back in terms of milliseconds.
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9051916
BTW, thx for the points.  i love to get points!
0
 

Author Comment

by:sdesar
ID: 9052225
thank for helping me.
I know i am being a little greedy ... but...
would you please help me an XML  question with these points?
0
 

Author Comment

by:sdesar
ID: 9052251
what is the syntax to do end-start ?
0
 

Author Comment

by:sdesar
ID: 9052336
this is what I did and the result is 0
<c:out value='$end-start}' />

0
 

Author Comment

by:sdesar
ID: 9052343
oops  .. this ...
<c:out value='${end-start}'  />
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9052445
here might be the problem:  i ran a test to see exactly how long something might take.  first i made a Bean to hold the timing

package com.tbone343;

public class QueryTime {

      private Long start;
      private Long end;
      private Long difference;
      
      public Long getStart() {
            start = new Long(System.currentTimeMillis());
            System.out.println(start);
            return start;
      }

      public Long getEnd() {
            end = new Long(System.currentTimeMillis());
            System.out.println(end);
            return end;
      }
      
      public Long getDifference() {
            if (end != null && start != null) {
                  return new Long(end.longValue() - start.longValue());
            }
            else return new Long(-1);
      }

      public void setEnd(Long end) {}
      public void setStart(Long start) {}
      public void setDifference(Long diff) {}
}


Then i used that same page from before:

<%@ page import="java.util.*" %>
<%@ taglib uri="/jstl-c" prefix="c" %>

<%
      Vector v = new Vector();
      v.addElement("ROW 1");
      v.addElement("ROW 2");
      v.addElement("ROW 3");
      v.addElement("ROW 4");
      pageContext.setAttribute("v",v);
%>

<table>

<jsp:useBean id="querytime" scope="page" class="com.tbone343.QueryTime" />


<c:out value="${querytime.start}"/>
<c:forEach var="row" items="${v}" varStatus="status">

      <tr>

            <c:if test="${status.count % 2 == 0}">
                  <td bgcolor="aabbcc">
                        <c:out value="${row}"/>
                  </td>
            </c:if>
      
            <c:if test="${status.count % 2 == 1}">
                  <td bgcolor="afaaff">
                        <c:out value="${row}"/>
                  </td>
            </c:if>

      </tr>
      
</c:forEach>

<%
int j = 0;
for (int i = 0; i < 10000000;i++) {
j+=i;
}
%>

<c:out value="${querytime.end}"/>

<c:out value="${querytime.difference}"/> milliseconds

</table>


notice that i put a loop up to 10,000,000 just to buy time in order for the difference not to be zero milliseconds.  this might be why you see zero.  OR you might have messed up.  check it out.
0
 

Author Comment

by:sdesar
ID: 9102272
The above coe is good but I would like to use the tag library if possible to get the difference between the begin and end  time in seconds...

this is what I am using to display begin and end time -

 <jsp:useBean id='nowBegin' class='java.util.Date' />
     18 BeginDate: <fmt:formatDate value='${nowBegin}'  timeStyle='full' />


<p>
      <jsp:useBean id='nowEnd' class='java.util.Date' />
     EndDate: <fmt:formatDate value='${nowEnd}' type='both' dateStyle='medium' time        Style='full' />


How can I just use JSP Tag library to parseDate and show  -
BeginTimeInSeconds minus EndTimeInSeconds.



Awaiitng suggestions...
0
 

Author Comment

by:sdesar
ID: 9139653
Hi tbone343 ,


In the above code for getting the time -

I removed -
package com.tbone343;

and also
class="com.tbone343.QueryTime"  changed to class="QueryTime"

I get this error -
:60: illegal start of expression
and
60: ';' expected
public class QueryTime {


how can I fix this?

awaiting suggestions
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9139981
you are missing a semicolon somewhere
0
 

Author Comment

by:sdesar
ID: 9141926
Help please I can't figure out where the ; is missing -

here's the code -



public class QueryTime {

    private Long start;
    private Long end;
    private Long difference;
   
     public Long getStart() {
         start = new Long(System.currentTimeMillis());
         System.out.println(start);
         return start;
    }

    public Long getEnd() {
         end = new Long(System.currentTimeMillis());
         System.out.println(end);
         return end;
    }
   
     public Long getDifference() {
         if (end != null && start != null) {
              return new Long(end.longValue() - start.longValue());
         }
         else return new Long(-1);
    }

    public void setEnd(Long end) {}
    public void setStart(Long start) {}
    public void setDifference(Long diff) {}
}


Then i used that same page from before:

<%@ page import="java.util.*" %>
<%@ taglib uri="/jstl-c" prefix="c" %>

<%
     Vector v = new Vector();
    v.addElement("ROW 1");
    v.addElement("ROW 2");
    v.addElement("ROW 3");
    v.addElement("ROW 4");
    pageContext.setAttribute("v",v);
%>

<table>

<jsp:useBean id="querytime" scope="page" class="QueryTime" />


<c:out value="${querytime.start}"/>
<c:forEach var="row" items="${v}" varStatus="status">

    <tr>

         <c:if test="${status.count % 2 == 0}">
              <td bgcolor="aabbcc">
                   <c:out value="${row}"/>
              </td>
         </c:if>
   
          <c:if test="${status.count % 2 == 1}">
              <td bgcolor="afaaff">
                   <c:out value="${row}"/>
              </td>
         </c:if>

    </tr>
   
</c:forEach>

<%
int j = 0;
for (int i = 0; i < 10000000;i++) {
j+=i;
}
%>

<c:out value="${querytime.end}"/>

<c:out value="${querytime.difference}"/> milliseconds

</table>
0
 

Author Comment

by:sdesar
ID: 9160429
Thanks for all your help . I found the error and fixed it.

I would like your help on one more related question...?

How can I find the rowCount of the rows that are alternating colors.
So if I have rows with 3 yellows in the cellColor and the 2 gray rows.

How can I get the count of this ?
I need these to store it in the rowspan.

Any suggestions?


Awaiting a response ..
Thanks a million!
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9162948
use <c:set

and set two variables to status.count each time through
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9162997
if you know what is in the collection, you can issue a command like this:

suppose the collection was a Vector and the name is "v":

v.size();  // tells u how many are in the collection so:
v.size() / 2;  // tells you how many grays
v.size() / 2 + v.size() % 2;  // tells you how many yellows
0
 

Author Comment

by:sdesar
ID: 9163466
I would like to count the number of times -

'${sName == rowData.str_name}'



how can I do a count of sName when sName == rowData.str_name ans store it in 'sNameCount '


I want to implement this in the code below...

<c:choose>
            <c:when test='${sName == rowData.str_name}'>
                <c:choose>
                    <c:when test='${sColor == 1}'> <tr bgcolor="#444444" > </c:when>
                    <c:otherwise> <tr bgcolor="#505050" > </c:otherwise>
                </c:choose>

                 <td >  <c:out value=  'X'/></td>
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test='${sColor == 1}'> <tr bgcolor="#505050"> <c:set var= 'sColor' value = '2'/> </c:when>
                    <c:otherwise> <tr bgcolor="#444444"> <c:set var= 'sColor' value = '1'/> </c:otherwise>
                </c:choose>
                <td rowspan="0"> <c:out value='${rowData.str_name}'/> <br>  <c:out value='${rowData.type}'/> </td>
                     <c:set var= 'sName' value = '${rowData.str_name}'/>
            </c:otherwise>
        </c:choose>


awaiting suggestions...
0
 

Author Comment

by:sdesar
ID: 9163515
Actually I want to store the result in the rowspan="<c:out value='sName.Count' /> "


so the result is - example -
rowspan="3"

awaiting suggestions!
0
 

Author Comment

by:sdesar
ID: 9163539
I tried this -

rowspan="<c:out value='${sName.count}' /> "

I get this error -
jasper.JasperException: An error occurred while evaluating custom action attribute "value" with value "${sName.count}": Unable to find a value for "count" in object of class "java.lang.String" using operator "." (null)

eagerly awaiting suggestions...
0
 

Author Comment

by:sdesar
ID: 9163582
Thanks for your suggestions  ... this is what I tried to do .. but the result is
<td rowspan=" "> 

I want it to have the count in there  .. ? what am I missing in the following code .... awaiting suggestions...?

<c:choose>
            <c:when test='${sName == rowData.str_name}' >
                <c:forEach var="sNameCount" items="${sName}" >

                <c:choose>
                    <c:when test='${sColor == 1}'> <tr bgcolor="#444444" > </c:when>
                    <c:otherwise> <tr bgcolor="#505050" > </c:otherwise>
                </c:choose>

                 <td >  <c:out value=  ''/></td>
                 </c:forEach>
            </c:when>
            <c:otherwise>
                <c:choose>
                    <c:when test='${sColor == 1}'> <tr bgcolor="#505050"> <c:set var= 'sColor' value = '2'/> </c:when>
                    <c:otherwise> <tr bgcolor="#444444"> <c:set var= 'sColor' value = '1'/> </c:otherwise>
                </c:choose>
                <td rowspan="<c:out value='${sNameCount.count}' />"> <c:out value='${rowData.str_name}'/> <br>  
<c:out value='${rowData.type}'/> </td>
                     <c:set var= 'sName' value = '${rowData.str_name}'/>
<%--        <td><IMG width=100 height=42 src="http://www/<c:out value='${rowData.str_proxy_filename}'/>" </td> --%>
            </c:otherwise>
        </c:choose>
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9163630
just look at my second post to this thread... look how i handle the variable "index"  and how i increment it
0
 

Author Comment

by:sdesar
ID: 9163683
I see it ..
<c:set var="index" value="${index + 1}"/>

but I stil need your help .. this is what the html looks like and I need to count ---

rowData.str_name   ie   /px/characters/dog <br>  px: character

how many times is occurs and store it in rowspan="<c:out value='${sNameCount.count}' />">


here is what the HTML looks like -
<STYLE TYPE="text/css">
TABLE    {
           border-collapse: collapse;
           border-spacing: 0px;
           border: 0px solid #666666;
           cellspacing: 1px;
           cellpadding: 3px;
             empty-cells: show}

TH {
      background: #444444;
      font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
      font-size: 11pt;
      font-weight: solid;
}

TD {
      font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
      font-size: 8pt;
      border: 1.0px solid silver;
      padding: 0em;
      align: bottom;
}

</STYLE>
<html>
<head>
  <title>JSTL: SQL Combo-box  and Parameters in action </title>
</head>
<body bgcolor=#282828 text=#ffffff>

Display  Status and task -
<div>
<table>
     <tr>  
         <th> Name</th>       <th> Task</th>         <th> Status</th>         <th> EMAIL</th>
      </tr>
    <tr>
  <tr bgcolor="#444444">  
     <td> /px/characters/cfa <br>  px: character </td>
         <td>Layout</td>
         <td>I/P </td>
       <td>ykang </td>
      </tr>
     <tr>
    <tr bgcolor="#444444" >     
<td > /px/characters/cfa <br>  px: character  </td>
<td>Modelling</td>
<td>I/P </td> <td>ykang </td> </tr>
<tr><tr bgcolor="#444444" >     
      <td > /px/characters/cfa <br>  px: character  </td>
      <td>Model</td>
<td>I/P </td>
 <td>kang </td>
</tr>
  <tr>
  <tr bgcolor="#505050">  
 <td> /px/characters/dog <br>  px: character </td>
 <td>Layout</td> <td>I/P </td><td>marv </td></tr>
     <tr><tr bgcolor="#505050" >
<td >/px/characters/dog <br>  px: character  </td><td>Modelling</td><td>I/P </td><td>marv

</td></tr>
<tr><tr bgcolor="#444444">
                <td> /px/characters/smk <br>  px: character </td>
                          <td>Layout</td>       
              <td>I/P </td>
            <td>marv </td>
     </tr>
     <tr><tr bgcolor="#444444" ><td > /px/characters/smk <br>  px: character

</td><td>Modelling</td>
              <td>I/P </td><td>marv </td></tr>

<tr><tr bgcolor="#505050"> <td> /px/characters/stm <br>  px: character </td>

<td>Layout</td> <td>I/P </td> <td>sanfo</td>
      </tr>

<tr>  <tr bgcolor="#505050" >  <td >/px/characters/stm <br>  px: character  </td>
<td>Modelling</td><td>I/P </td><td>sanfo</td></tr>
</table>
</div>
<p class="break"> <!-- Table is continued --></p>



<font size='1'>
<p>

Date: Wednesday, August 13, 2003
</body>
</html>

awaiiting suggestionss....
0
 
LVL 7

Expert Comment

by:tbone343
ID: 9163699
u can't... you would have to read through the entire thing once just to get the count.  Then, you would have to do it again.  if i were you, i would write a java bean class that performs this operation on the collection.  then you could write methods like getCount() and use them in your JSP.  remember the purpose behind JSTL.  we are trying to separate logic from presentation.  so it is better to do this logic computations in a java class where logic goes.  then in the JSP, you need only do  collectionName.count   which will run the getCount() method.  HTH
0
 

Author Comment

by:sdesar
ID: 9249514
Thanks for all your help.

thbone343 -- could you please help me with JSTL on this question ..
http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_20719733.html

thanks
0

Featured Post

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question