1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

issue accessing Date object from within a scriptlet embedded in JSP

Discussion in 'JSP' started by damo.gets, Sep 23, 2008.

  1. damo.gets

    damo.gets New Member

    Joined:
    Sep 23, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    programmer/system administrator
    Location:
    bismarck, nd
    Home Page:
    True to bad style, I'm writing a piece of JSP right now where there's a bit of actual code scriptlet embedded with <% ... %> tags now.

    In the jsp above that scriptlet I'm working with 2 objects of java.util.Date, called inDate and outDate. When I'm trying to access the different objects er values or whatever within them, I'm using standard inDate.minutes and etc. to attempt to do tests on them. Is there something special that I need to know about accessing this kind of object from within an embedded scriptlet? I'm getting a server log error of
    An error occurred at line: 169 in the jsp file: /reports.jsp
    inDate.hours cannot be resolved or is not a field


    When I access that section now; debugging code above the scriptlet has proven that inDate & outDate are getting their proper values in the JSP code, though.

    Here's a little bit of the code; I'm pretty sure this issue is just something that I don't understand about either the scope of these objects (declared at the top of the same JSP page) or how much access an embedded scriptlet has to variables declared in JSP:
    Code:
                    <fmt:parseDate var="inDate" value="${punch.starttime}"
    pattern="yyyy-MM-dd HH:mm:ss" />
                    <fmt:parseDate var="outDate" value="${punch.endtime}" pattern="yyyy-
    MM-dd HH:mm:ss" />
    
                    <%
                      int totalMinutes = 0, units = 0;
                      if (inDate.hours != outDate.hours)
                        totalMinutes = (outDate.hours - inDate.hours) * 60;
                      totalMinutes += (outDate.minutes - inDate.minutes);
    
                      if ((totalMinutes >= 8) && (totalMinutes <= 22))
                            units = 1;
                      else if (totalMinutes >= 23) {
                            units = 1;
                            totalMinutes -= 22;
                            do {
                                units += 1;
                                totalMinutes -= 15;
                            } while (totalMinutes > 0);
                      }
                    %>
    I would be very grateful if anybody could help point me in the right direction on this issue.
     

Share This Page