You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Jack Lauman <jl...@nwcascades.com> on 2004/05/08 19:26:33 UTC

JSTL Formatting Question

I'm using the following jsp page to display tide tables.  How can I 
separate the days using the retrieved date field so the date only
appears on the first line of the result set and only appears again when 
the date changes.  There are usually 6-7 lines of data for each day.

I'd like to achieve something that looks like this:

2004-05-08  	2:57  	AM  	7.27 feet  	Low Tide
		5:38 	AM 			Sunrise
	 	6:44 	AM 	8.45 feet 	High Tide
	 	2:43 	PM 	-2.81 feet 	Low Tide
	 	8:37 	PM 			Sunset
	 	10:55 	PM 	9.98 feet 	High Tide

2004-05-09 	4:13 	AM 	7.28 feet 	Low Tide
	 	5:36 	AM 			Sunrise

The page can be seen here:
http://hood.nwcascades.com/tides/tidetest.jsp


<--- code snip --->

<fmt:setLocale value='en-US'/>

<%-- Connect to MySQL using JBoss DataSource JNDI name --%>

<sql:setDataSource
     var="bbvtides"
     dataSource="jdbc/BirchBayVillageDS"/>

     <sql:query dataSource="${bbvtides}" var="result">
	SELECT date, time, am_pm, height, cond
	FROM cherry_point_tides
	WHERE date BETWEEN CURDATE() and CURDATE() + INTERVAL 2 DAY
     </sql:query>

<%-- Display the tide table --%>

<fmt:formatDate value='${now}' pattern="'Tide Table for 'EEEE', 'MMMM 
d', 'yyyy"/><br>
Cherry Point, Birch Bay, Washington State<br>
48.8633&#176; N, 122.7583&#176; W - All times <fmt:formatDate 
value='${now}' pattern="zzzz' ('zz')'"/>
<p><table border="1">
     <tr>
	<th>Date</th>
	<th>Time</th>
	<th>am/pm</th>
	<th>Height</th>
	<th>Condition</th>
     </tr>

     <c:forEach var="row" items="${result.rows}">
     <tr>
	<td><c:out value="${row.Date}"/></td>
	<td><c:out value="${row.Time}"/></td>
	<td><c:out value="${row.Am_Pm}"/></td>
	<td><c:out value="${row.Height}"/></td>
	<td><c:out value="${row.Cond}"/></td>
     <tr>
     </c:forEach>
</table>

<--- end code snip --->


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: JSTL Formatting Question

Posted by Jack Lauman <jl...@nwcascades.com>.
Steve:

I tired the following using 'displaytag'.  I don't get any errors
but I don't get any results either.  Got any idea what might be
wrong in this code?

First try, JSTL only:    http://hood.nwcascades.com/tides/tidetest.jsp
Second try (this code):  http://hood.nwcascades.com/tides/tidetest1.jsp

Thanks,

Jack

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>

<jsp:useBean id="now" class="java.util.Date"/>

<%-- Set the default locale to en-US.
      NOTE: French may be added at a later date.
      Parse the date request parameter into
      java.util.Date objects and store them in
      scoped variables in the page scope --%>

<fmt:setLocale value='en-US'/>

<%-- Connect to MySQL using JBoss DataSource JNDI name --%>

<sql:setDataSource
     var="bbvtides"
     dataSource="jdbc/BirchBayVillageDS"/>

     <sql:query dataSource="${bbvtides}" var="result">
	SELECT date, time, am_pm, height, cond
	FROM cherry_point_tides
	WHERE date BETWEEN CURDATE() and CURDATE() + INTERVAL 2 DAY
     </sql:query>

<%-- Display the tide table --%>

<fmt:formatDate value='${now}' pattern="'Tide Table for 'EEEE', 'MMMM 
d', 'yyyy"/><br>
Cherry Point, Birch Bay, Washington State<br>
48.8633&#176; N, 122.7583&#176; W - All times <fmt:formatDate 
value='${now}' pattern="zzzz' ('zz')'"/>
<display:table name="cptides">
     <display:column property="date" title="Date" group="1"/>
     <display:column property="time" title="Time"/>
     <display:column property="am_pm" title="am/pm"/>
     <display:column property="height" title="Height"/>
     <display:column property="cond" title="Condition"/>
</display:table>


Jack Lauman wrote:

> I'll check it out.
> 
> Thanks,
> 
> Jack
> 
> Steve Raeburn wrote:
> 
>> You might also be able to use the <forCategories> tag from the taglibs
>> sandbox.
>> http://jakarta.apache.org/taglibs/sandbox/doc/iterators-doc/intro.html
>>
>> Steve
>>
>>
>>
>>> -----Original Message-----
>>> From: Jack Lauman [mailto:jlauman@nwcascades.com]
>>> Sent: May 8, 2004 3:59 PM
>>> To: Tag Libraries Users List
>>> Subject: Re: JSTL Formatting Question
>>>
>>>
>>> Nice.. but it produces html that won't work in older browsers.
>>>
>>> Thanks,
>>>
>>> Jack
>>>
>>> Steve Raeburn wrote:
>>>
>>>
>>>> Take a look at DisplayTag
>>>> (http://www.displaytag.org/example-grouping.jsp). It does
>>>
>>>
>>> grouping and
>>>
>>>> lots of other very cool things with tables.
>>>>
>>>> Steve
>>>>
>>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: JSTL Formatting Question

Posted by Jack Lauman <jl...@nwcascades.com>.
I'll check it out.

Thanks,

Jack

Steve Raeburn wrote:

> You might also be able to use the <forCategories> tag from the taglibs
> sandbox.
> http://jakarta.apache.org/taglibs/sandbox/doc/iterators-doc/intro.html
> 
> Steve
> 
> 
> 
>>-----Original Message-----
>>From: Jack Lauman [mailto:jlauman@nwcascades.com]
>>Sent: May 8, 2004 3:59 PM
>>To: Tag Libraries Users List
>>Subject: Re: JSTL Formatting Question
>>
>>
>>Nice.. but it produces html that won't work in older browsers.
>>
>>Thanks,
>>
>>Jack
>>
>>Steve Raeburn wrote:
>>
>>
>>>Take a look at DisplayTag
>>>(http://www.displaytag.org/example-grouping.jsp). It does
>>
>>grouping and
>>
>>>lots of other very cool things with tables.
>>>
>>>Steve
>>>
>>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>>
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


RE: JSTL Formatting Question

Posted by Steve Raeburn <sr...@apache.org>.
You might also be able to use the <forCategories> tag from the taglibs
sandbox.
http://jakarta.apache.org/taglibs/sandbox/doc/iterators-doc/intro.html

Steve


> -----Original Message-----
> From: Jack Lauman [mailto:jlauman@nwcascades.com]
> Sent: May 8, 2004 3:59 PM
> To: Tag Libraries Users List
> Subject: Re: JSTL Formatting Question
>
>
> Nice.. but it produces html that won't work in older browsers.
>
> Thanks,
>
> Jack
>
> Steve Raeburn wrote:
>
> > Take a look at DisplayTag
> > (http://www.displaytag.org/example-grouping.jsp). It does
> grouping and
> > lots of other very cool things with tables.
> >
> > Steve
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


RE: JSTL Formatting Question

Posted by Steve Raeburn <sr...@apache.org>.
The html works just fine in older browsers (e.g. Netscape 4.7).

What I think you're referring to is that the demo page is styled using
CSS and the author has *deliberately* designed the page to degrade
gracefully to a very plain styling on older browsers (i.e. no styling at
all).

To enable styling for NS4, all I did was change one line in the HTML
file:

  From: <link rel="stylesheet" href="css/screen.css" type="text/css"
media="screen, print" />
  To:   <link rel="stylesheet" href="css/screen.css" type="text/css" />

So now even NS4 can use the stylesheet. I provided a much simpler
stylesheet so NS4 won't choke, but there are ways to provide alternate
stylesheets for different browsers. See http://www.ninsky.com/dt/ for
the working example.

The thing is that this is all to do with stylesheets and nothing to do
with DisplayTag.

BTW. Nobody uses NS4 anymore ;-)
http://www.google.com/press/zeitgeist.html. Stats for your site may
vary, but do look closely at your figures before you expend much effort
on catering for older browsers.

If all else fails, it's open source, so you can tweak the html to your
satisfaction.

Steve


> -----Original Message-----
> From: Jack Lauman [mailto:jlauman@nwcascades.com]
> Sent: May 8, 2004 3:59 PM
> To: Tag Libraries Users List
> Subject: Re: JSTL Formatting Question
>
>
> Nice.. but it produces html that won't work in older browsers.
>
> Thanks,
>
> Jack
>
> Steve Raeburn wrote:
>
> > Take a look at DisplayTag
> > (http://www.displaytag.org/example-grouping.jsp). It does
> grouping and
> > lots of other very cool things with tables.
> >
> > Steve
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Re: JSTL Formatting Question

Posted by Jack Lauman <jl...@nwcascades.com>.
Nice.. but it produces html that won't work in older browsers.

Thanks,

Jack

Steve Raeburn wrote:

> Take a look at DisplayTag
> (http://www.displaytag.org/example-grouping.jsp). It does grouping and
> lots of other very cool things with tables.
> 
> Steve
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


RE: JSTL Formatting Question

Posted by Steve Raeburn <sr...@apache.org>.
Take a look at DisplayTag
(http://www.displaytag.org/example-grouping.jsp). It does grouping and
lots of other very cool things with tables.

Steve

> -----Original Message-----
> From: Jack Lauman [mailto:jlauman@nwcascades.com]
> Sent: May 8, 2004 10:27 AM
> To: Tag Libraries Users List
> Subject: JSTL Formatting Question
>
>
> I'm using the following jsp page to display tide tables.  How can I
> separate the days using the retrieved date field so the date only
> appears on the first line of the result set and only appears
> again when
> the date changes.  There are usually 6-7 lines of data for each day.
>
> I'd like to achieve something that looks like this:
>
> 2004-05-08  	2:57  	AM  	7.27 feet  	Low Tide
> 		5:38 	AM 			Sunrise
> 	 	6:44 	AM 	8.45 feet 	High Tide
> 	 	2:43 	PM 	-2.81 feet 	Low Tide
> 	 	8:37 	PM 			Sunset
> 	 	10:55 	PM 	9.98 feet 	High Tide
>
> 2004-05-09 	4:13 	AM 	7.28 feet 	Low Tide
> 	 	5:36 	AM 			Sunrise
>
> The page can be seen here:
> http://hood.nwcascades.com/tides/tidetest.jsp
>
>
> <--- code snip --->
>
> <fmt:setLocale value='en-US'/>
>
> <%-- Connect to MySQL using JBoss DataSource JNDI name --%>
>
> <sql:setDataSource
>      var="bbvtides"
>      dataSource="jdbc/BirchBayVillageDS"/>
>
>      <sql:query dataSource="${bbvtides}" var="result">
> 	SELECT date, time, am_pm, height, cond
> 	FROM cherry_point_tides
> 	WHERE date BETWEEN CURDATE() and CURDATE() + INTERVAL 2 DAY
>      </sql:query>
>
> <%-- Display the tide table --%>
>
> <fmt:formatDate value='${now}' pattern="'Tide Table for 'EEEE', 'MMMM
> d', 'yyyy"/><br>
> Cherry Point, Birch Bay, Washington State<br>
> 48.8633&#176; N, 122.7583&#176; W - All times <fmt:formatDate
> value='${now}' pattern="zzzz' ('zz')'"/>
> <p><table border="1">
>      <tr>
> 	<th>Date</th>
> 	<th>Time</th>
> 	<th>am/pm</th>
> 	<th>Height</th>
> 	<th>Condition</th>
>      </tr>
>
>      <c:forEach var="row" items="${result.rows}">
>      <tr>
> 	<td><c:out value="${row.Date}"/></td>
> 	<td><c:out value="${row.Time}"/></td>
> 	<td><c:out value="${row.Am_Pm}"/></td>
> 	<td><c:out value="${row.Height}"/></td>
> 	<td><c:out value="${row.Cond}"/></td>
>      <tr>
>      </c:forEach>
> </table>
>
> <--- end code snip --->
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


RE: JSTL Formatting Question

Posted by Steve Raeburn <sr...@apache.org>.
Take a look at DisplayTag
(http://www.displaytag.org/example-grouping.jsp). It does grouping and
lots of other very cool things with tables.

Steve

> -----Original Message-----
> From: Jack Lauman [mailto:jlauman@nwcascades.com]
> Sent: May 8, 2004 10:27 AM
> To: Tag Libraries Users List
> Subject: JSTL Formatting Question
>
>
> I'm using the following jsp page to display tide tables.  How can I
> separate the days using the retrieved date field so the date only
> appears on the first line of the result set and only appears
> again when
> the date changes.  There are usually 6-7 lines of data for each day.
>
> I'd like to achieve something that looks like this:
>
> 2004-05-08  	2:57  	AM  	7.27 feet  	Low Tide
> 		5:38 	AM 			Sunrise
> 	 	6:44 	AM 	8.45 feet 	High Tide
> 	 	2:43 	PM 	-2.81 feet 	Low Tide
> 	 	8:37 	PM 			Sunset
> 	 	10:55 	PM 	9.98 feet 	High Tide
>
> 2004-05-09 	4:13 	AM 	7.28 feet 	Low Tide
> 	 	5:36 	AM 			Sunrise
>
> The page can be seen here:
> http://hood.nwcascades.com/tides/tidetest.jsp
>
>
> <--- code snip --->
>
> <fmt:setLocale value='en-US'/>
>
> <%-- Connect to MySQL using JBoss DataSource JNDI name --%>
>
> <sql:setDataSource
>      var="bbvtides"
>      dataSource="jdbc/BirchBayVillageDS"/>
>
>      <sql:query dataSource="${bbvtides}" var="result">
> 	SELECT date, time, am_pm, height, cond
> 	FROM cherry_point_tides
> 	WHERE date BETWEEN CURDATE() and CURDATE() + INTERVAL 2 DAY
>      </sql:query>
>
> <%-- Display the tide table --%>
>
> <fmt:formatDate value='${now}' pattern="'Tide Table for 'EEEE', 'MMMM
> d', 'yyyy"/><br>
> Cherry Point, Birch Bay, Washington State<br>
> 48.8633&#176; N, 122.7583&#176; W - All times <fmt:formatDate
> value='${now}' pattern="zzzz' ('zz')'"/>
> <p><table border="1">
>      <tr>
> 	<th>Date</th>
> 	<th>Time</th>
> 	<th>am/pm</th>
> 	<th>Height</th>
> 	<th>Condition</th>
>      </tr>
>
>      <c:forEach var="row" items="${result.rows}">
>      <tr>
> 	<td><c:out value="${row.Date}"/></td>
> 	<td><c:out value="${row.Time}"/></td>
> 	<td><c:out value="${row.Am_Pm}"/></td>
> 	<td><c:out value="${row.Height}"/></td>
> 	<td><c:out value="${row.Cond}"/></td>
>      <tr>
>      </c:forEach>
> </table>
>
> <--- end code snip --->
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org