sdesar
asked on
How to alternate table row background colors using JSTL?
How to alternate table row background colors using JSTL?
SQL is : <br>
<c:out value='${rPipeStatus}' /> <BR> <BR>
<c:out value='${rPipeStatus.rowCo
<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}
</c:otherwise>
</c:choose>
<td><c:out value='${rowData.task}'/><
<td><c:out value='${rowData.str_value
<td><c:out value='${rowData.str_email
</tr>
</c:forEach>
</table>
ASKER
I am new to JSTLs --- could you please give me the exact syntax, to plug it in to the code above...
thanks
thanks
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>
<%@ 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("
pageContext.setAttribute("
%>
<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>
ASKER
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.rowCoun t}">
<c:set var="cellColor">
<c:choose>
<c:when test="${status.count % 2 == 1}">red</c:when>
<c:otherwise>blue</c:other wise>
</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_email 1}'/> </td>
</tr>
</c:forEach>
</table>
--Awaiting a response...
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}
<c:set var="cellColor">
<c:choose>
<c:when test="${status.count % 2 == 1}">red</c:when>
<c:otherwise>blue</c:other
</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}
<c:set var= 'sName' value = '${rowData.str_name}'/>
</c:otherwise>
</c:choose>
<td bgcolor="${cellColor}"><c:
<td bgcolor="${cellColor}"><c:
<td><c:out value='${rowData.str_email
</tr>
</c:forEach>
</table>
--Awaiting a response...
<c:forEach var="rowData" items="${rPipeStatus.rows} ">
<c:forEach items="${rPipeStatus.rows} " var="current" varStatus="status" begin="0" end="${rPipeStatus.rowCoun t}">
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:other wise>
</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_email 1}"/></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...
<c:forEach items="${rPipeStatus.rows}
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}
<c:set var="cellColor">
<c:choose>
<c:when test="${status.count % 2 == 1}">red</c:when>
<c:otherwise>blue</c:other
</c:choose>
</c:set>
<tr>
<c:choose>
<c:when test="${sName == rowData.str_name}">
<td bgcolor="${cellColor}"><c:
</c:when>
<c:otherwise>
<td><c:out value="${rowData.str_name}
<c:set var="sName" value="${rowData.str_name}
</c:otherwise>
</c:choose>
<td bgcolor="${cellColor}"><c:
<td bgcolor="${cellColor}"><c:
<td bgcolor="${cellColor}"><c:
</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...
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
varStatus="status"
on your first line since this doesn't do anything... the variable "status" is taken care of for you
ASKER
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:other wise>
</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_email 1}'/> </td>
</tr>
</c:forEach>
</c:forEach>
</table>
The result in the HTML - am am getting is
<td bgcolor="${cellColor}">Com plete </td>
for some reason bgcolor="${cellColor}"> is not being set to bgcolor="red">
awaiting suggestions ..
BTW - thanks fpr helping me
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}
<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:other
</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}
</c:otherwise>
</c:choose>
<td bgcolor="${cellColor}"><c:
<td bgcolor="${cellColor}"><c:
<td><c:out value='${rowData.str_email
</tr>
</c:forEach>
</c:forEach>
</table>
The result in the HTML - am am getting is
<td bgcolor="${cellColor}">Com
for some reason bgcolor="${cellColor}"> is not being set to bgcolor="red">
awaiting suggestions ..
BTW - thanks fpr helping me
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.
<c:forEach var="rowData" items="${rPipeStatus.rows}
<c:forEach items="${rPipeStatus.rows}
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.
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
<c:forEach items="${rPipeStatus.rows}
keep varStatus="status" in there... you need it.. i'm checking on your c:set right now
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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:other wise>
</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_email 1}'/> </td>
</tr>
</c:forEach>
</table>
<br>
<c:out value='${rPipeStatus.rowCo unt}'/> 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>
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}
<c:set var="cellColor">
<c:choose>
<c:when test="${status.count % 2 == 1}">red</c:when>
<c:otherwise>blue</c:other
</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}
</c:otherwise>
</c:choose>
<td bgcolor="${cellColor}" ><c:out value='${rowData.task}'/><
<td><c:out value='${rowData.str_value
<td><c:out value='${rowData.str_email
</tr>
</c:forEach>
</table>
<br>
<c:out value='${rPipeStatus.rowCo
<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>
Make a JSP page with what I just sent you, run it, and try to see the differences
ASKER
oops I made a mistake with the points - I wanted to assign 100 points .. how can I fix it?
i don't think that you can.... why would you won't to take points away from me anyway? :(
ASKER
Aweome ... thanks a million... now I know my mistake ...
<td bgcolor="<c:out value="${cellColor}"/>">
Thanks You.
<td bgcolor="<c:out value="${cellColor}"/>">
Thanks You.
no problem
ASKER
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.rowCo unt}'/> 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}"/></t h>
</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.
so the code that I currently have just shows the row Count -
<c:out value='${rPipeStatus.rowCo
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}"/></t
</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}"/><
</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.
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.
ASKER
Here are your excellent points!
thanks for your help.
hipe to receive an answer soon.
thanks for your help.
hipe to receive an answer soon.
<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}"/></t h>
</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.
<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}"/></t
</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}"/><
</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.
BTW, thx for the points. i love to get points!
ASKER
thank for helping me.
I know i am being a little greedy ... but...
would you please help me an XML question with these points?
I know i am being a little greedy ... but...
would you please help me an XML question with these points?
ASKER
what is the syntax to do end-start ?
ASKER
this is what I did and the result is 0
<c:out value='$end-start}' />
<c:out value='$end-start}' />
ASKER
oops .. this ...
<c:out value='${end-start}' />
<c:out value='${end-start}' />
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.currentTimeMil lis());
System.out.println(start);
return start;
}
public Long getEnd() {
end = new Long(System.currentTimeMil lis());
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.QueryT ime" />
<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.differe nce}"/> 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.
package com.tbone343;
public class QueryTime {
private Long start;
private Long end;
private Long difference;
public Long getStart() {
start = new Long(System.currentTimeMil
System.out.println(start);
return start;
}
public Long getEnd() {
end = new Long(System.currentTimeMil
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("
%>
<table>
<jsp:useBean id="querytime" scope="page" class="com.tbone343.QueryT
<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.differe
</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.
ASKER
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...
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...
ASKER
Hi tbone343 ,
In the above code for getting the time -
I removed -
package com.tbone343;
and also
class="com.tbone343.QueryT ime" 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
In the above code for getting the time -
I removed -
package com.tbone343;
and also
class="com.tbone343.QueryT
I get this error -
:60: illegal start of expression
and
60: ';' expected
public class QueryTime {
how can I fix this?
awaiting suggestions
you are missing a semicolon somewhere
ASKER
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.currentTimeMil lis());
System.out.println(start);
return start;
}
public Long getEnd() {
end = new Long(System.currentTimeMil lis());
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.differe nce}"/> milliseconds
</table>
here's the code -
public class QueryTime {
private Long start;
private Long end;
private Long difference;
public Long getStart() {
start = new Long(System.currentTimeMil
System.out.println(start);
return start;
}
public Long getEnd() {
end = new Long(System.currentTimeMil
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("
%>
<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.differe
</table>
ASKER
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!
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!
use <c:set
and set two variables to status.count each time through
and set two variables to status.count each time through
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
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
ASKER
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...
'${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}
<c:set var= 'sName' value = '${rowData.str_name}'/>
</c:otherwise>
</c:choose>
awaiting suggestions...
ASKER
Actually I want to store the result in the rowspan="<c:out value='sName.Count' /> "
so the result is - example -
rowspan="3"
awaiting suggestions!
so the result is - example -
rowspan="3"
awaiting suggestions!
ASKER
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...
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...
ASKER
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>
<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.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
</c:otherwise>
</c:choose>
just look at my second post to this thread... look how i handle the variable "index" and how i increment it
ASKER
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....
<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
</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....
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
ASKER
Thanks for all your help.
thbone343 -- could you please help me with JSTL on this question ..
https://www.experts-exchange.com/questions/20719733/how-to-to-create-tree-view-using-JSP.html
thanks
thbone343 -- could you please help me with JSTL on this question ..
https://www.experts-exchange.com/questions/20719733/how-to-to-create-tree-view-using-JSP.html
thanks
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.