It is currently Fri May 18, 2012 4:02 pm


Post a new topicPost a reply Page 1 of 1   [ 3 posts ]
Author Message
 Post subject: embedded scriptlet not able to access Date object
PostPosted: Tue Sep 23, 2008 1:14 pm 

Joined: Thu Sep 11, 2008 3:26 pm
Posts: 11
Location: Bismarck, ND
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.

Damon Getsman
-=-=-=-
ITRx http://www.itrx-nd.com/
Programmer/System Administrator
-=-=-=-

_________________
-=-=-=-
ITRx http://www.itrx-nd.com/
Systems Administrator/Programmer
-=-=-=-


Top
 Profile Send private message  
 
 Post subject: Re: embedded scriptlet not able to access Date object
PostPosted: Tue Sep 23, 2008 2:11 pm 

Joined: Thu Sep 11, 2008 3:26 pm
Posts: 11
Location: Bismarck, ND
Duhh, don't mind me. I was trying to access the members of that object the same way that I did in JSP.

Depreciated getHours, getMinutes, etc, worked just fine. Can anybody tell me the non-depreciated way to do this? The Calendar object stuff on the java.sun.com website confused me a bit.

_________________
-=-=-=-
ITRx http://www.itrx-nd.com/
Systems Administrator/Programmer
-=-=-=-


Top
 Profile Send private message  
 
 Post subject: Re: embedded scriptlet not able to access Date object
PostPosted: Tue Oct 14, 2008 9:58 am 
Site Admin

Joined: Sat Aug 02, 2008 8:00 am
Posts: 147
Hi,

It is pretty easy to use the Calendar object

you just instantiate an object from the Calendar class using
Calendar cal=Calendar.getInstance();
then you can get the hour as follows;
int hour=cal.get(Calendar.HOUR);
int monthDay=cal.get(Calendar.DAY_OF_MONTH );

Note that the calendar is created with the current date and time by default
if you want to set the calendar to a specific date and time use
cal.setTime(Date mySpecificDate);

I hope that was helpful and please tell me if you have any queries

_________________

Muhammad Safwat Fuad
The Java Code Admin
Java Technical Lead.
Mobile: +2010-2942-538
Email:mtv134@yahoo.com


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 3 posts ]


Who is online

Registered users: europhory, Illerma


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
twilightBB Style by Daniel St. Jules of Gamexe.net

[
SEO MOD © 2007 StarTrekGuide ]