Results 1 to 1 of 1
  1. #1
    jlund is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

    Default Display nodes depending on date

    Hi All,

    I am trying to navigate through an xml file using jstl, and display content depending on the date:

    Java Code:
    <session>
        <sessname>Something</sessname>
        <dates>
            <date>01/01/2010</date>
            <times>
                <starttime>09:00</starttime>
                <endtime>18:00</endtime>
            </times>
        </dates>
        <sessname>Something Else</sessname>
        <dates>
            <date>04/02/2010</date>
            <times>
                <starttime>09:30</starttime>
                <endtime>17:00</endtime>
            </times>
        </dates>
    </session>
    If the session date falls between a particular date period, I want to display the session information as follows:

    <h2>Something</h2>

    01/01/2010

    09:00 - 18:00

    And my code at the moment is:

    Java Code:
    <x:forEach var="venueSessions" select="$venue/session">	
    	<% 
            dates = ""; 
            sessName = (String)pageContext.getAttribute("sessionName");
        %>
        <x:forEach var="eventDates" select="$venueSessions/dates">
            <%-- add each date and time to string dates:
                01/01/2009
                09:00 - 17:00                                                       
                02/01/2009
                09:30 - 17:00 
             --%>
            <x:forEach var="eachEventDate" select="$eventDates/date">
                <c:set var="eventDate" scope="page">
                    <x:out select="$eachEventDate" />
                </c:set>
                    
                <%													
                    String eventDate = (String)pageContext.getAttribute("eventDate");
                    if (toDate == null || toDate.equals("")) {
                        toDate = "01/01/9999";
                    }
                    fromDate = "01/03/2010";
                    Date fromDateConverted;
                    
                    if (fromDate == null || fromDate.equals("")) {
                        fromDateConverted = ddMMyyyy.parse(ddMMyyyy.format(new java.util.Date())); 
                        //fromDateConverted = dateFormat.parse(fromDate);
                    } else {
                        fromDateConverted = dateFormat.parse(fromDate);
                    }
                    
                    Date eventDateConverted = dateFormat.parse(eventDate);
                    
                    Date toDateConverted = dateFormat.parse(toDate);
                    if ( (fromDateConverted.before(eventDateConverted) || fromDateConverted.equals(eventDateConverted)) && (toDateConverted.after(eventDateConverted) || toDateConverted.equals(eventDateConverted))) {
                        dates += eventDate + "<br />";	
                    }
                %>
            </x:forEach>  
                          
        </x:forEach>
        <%
            if(dates != "")
            {
                //if 'dates' has text then there is a valid session for this date
                sess += "<em>" + sessName + "</em><br />";
                sess += dates;
            }                                                     
        %>                                                
    </x:forEach>
    <%
        if(sess != "")
        {
            venueDetails += (String)pageContext.getAttribute("venueName") + "<br />";
        }
    %>
    Any ideas on how to do this would be much appreciated!!

    John
    Last edited by jlund; 12-18-2009 at 11:49 AM. Reason: More accurate title

Similar Threads

  1. How to get value of specific child node
    By sito42 in forum New To Java
    Replies: 1
    Last Post: 07-13-2009, 12:00 PM
  2. Printing Information in a node
    By Tenn in forum New To Java
    Replies: 4
    Last Post: 04-30-2009, 05:43 AM
  3. XML Node.getNodeValue Problem
    By mindscape777 in forum XML
    Replies: 1
    Last Post: 01-11-2009, 02:22 PM
  4. How to disabled a node.
    By smartsubroto in forum New To Java
    Replies: 32
    Last Post: 07-01-2008, 07:30 AM
  5. Node selection in jtree
    By Preethi in forum AWT / Swing
    Replies: 4
    Last Post: 06-19-2008, 11:25 PM

Tags for this Thread

Posting Permissions

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