You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ken <ke...@aerose.com> on 2010/07/27 20:59:12 UTC
Display GregorianCalendar Objects
This seems like it should be beyond easy yet I still find my self
asking...
I my POJO has several GregorianCalendar objects.
In my JSP what is the best way to display a simple (year, month, day)
format?
Use Java in the JSP it self? Is there a good struts 2 tag for this... I
think if the
field were editable it would be distracting.
It seems to be a display issue but I could go back to the POJO and put
formatting
logic there...
Anyways open to suggestions.
Re: Display GregorianCalendar Objects
Posted by Michal Ciasnocha <mc...@struts.cz>.
In that case you must use own converter like this:
public class DateTimeConverter extends StrutsTypeConverter {
@Override
public Object convertFromString(Map context, String[] values,
Class toClass) {
try {
return DateUtil.getConvertedDate(values[0],
DateUtil.DATE_TIME);
} catch (TypeConversionException tce) {
log.error("Exception while parsing date.", tce);
}
return null;
}
}
Method getConvertedDate() just parse inserted date as string by user.
Reeshi Agrawal wrote on 28.7.2010 15:05:
> Michal,
> I wanted the user to input his birth-date. Displaying the current date will
> be of no use for it.
>
Re: Display GregorianCalendar Objects
Posted by Reeshi Agrawal <ru...@gmail.com>.
Michal,
I wanted the user to input his birth-date. Displaying the current date will
be of no use for it.
Re: Display GregorianCalendar Objects
Posted by Ken <ke...@aerose.com>.
On Tue, 2010-07-27 at 21:45 +0200, Michal Ciasnocha wrote:
> Why don't use Struts tag s:date for date formatting?
>
> in Action:
>
> public GregorianCalendar getMyDate() {
> return new GregorianCalendar();
> }
>
> in jsp:
>
> <s:date name="myDate" format="d. M. yyyy HH:mm" />
>
> Michal
>
> > Hi all,
> > i do it like that:
> > in my POJO GregorianCalendar field,
> > on my jsp text field + jquery calendar.
> > If You want to create date in some kind of predefined format
> > You can use Conventer for GregorianCalendar for your app.
Ah, too easy... I had been using DateTimePicker and confused the two.
Well in my efforts to output the GregorianCalendar object in OGNL I had
troubles,
although it is clearly not the best way (clearly to me now that is)...
Perhaps
someone can explain:
1) Casting in OGNL, and 2) Referencing static field definitions in
OGNL...
For instance in my efforts to get the date out I wrote:
<s:property value=" '' + courseStartDate.get(1) + '-' +
{courseStartDate.get(2) + 1} + '-' + courseStartDate.get(5)"/>
Where:
courseStartDate.get(1) aught to be written
courseStartDate.get(Calendar.YEAR),
courseStartDate.get(2) aught to be written courseStartDate.get(MONTH)
courseStartDate.get(5) aught to be written
courseStartDate.get(Calendar.DATE),
maybe it works it just didn't seem to for me...
Then I had difficulties because of automatic type conversion...
The Month is 0 based so I need to add 1 to the date, so I tried...
(courseStartDate.get(2) + 1) but I think that resulted in the string "1"
being appended to the end of everything...
the closest I could get was {courseStartDate.get(2) + 1} and that prints
the correct number but inside square brackets.
So after all that Michal pointed out the obvious and I threw all this
out the window and just used the date tag but I'd still like to address
these issues.
Re: Display GregorianCalendar Objects
Posted by Michal Ciasnocha <mc...@struts.cz>.
Why don't use Struts tag s:date for date formatting?
in Action:
public GregorianCalendar getMyDate() {
return new GregorianCalendar();
}
in jsp:
<s:date name="myDate" format="d. M. yyyy HH:mm" />
Michal
> Hi all,
> i do it like that:
> in my POJO GregorianCalendar field,
> on my jsp text field + jquery calendar.
> If You want to create date in some kind of predefined format
> You can use Conventer for GregorianCalendar for your app.
>
>
> Best greetings,
> Paweł Wielgus.
>
> 2010/7/27 Reeshi Agrawal<ru...@gmail.com>:
>> Same problem with me...
>> I want (through Struts 2 tags), a way to display date as three adjacent
>> (side-by-side) drop-down menus, one each for date,month and year. Normally
>> what will happen is: the three drop-down menus will be displayed in three
>> separate consecutive rows in the HTML table generated in Struts 2. But I
>> want them to be present in a single row in the displayed HTML table. Do I
>> need to do some modification in the freeMarker templates' .ftl files? Or is
>> there another very simple thing that I am missing?
>> I know I am asking a very simp;e thing, but its bugging me from quite some
>> time...
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
Re: Display GregorianCalendar Objects
Posted by Paweł Wielgus <po...@gmail.com>.
Hi all,
i do it like that:
in my POJO GregorianCalendar field,
on my jsp text field + jquery calendar.
If You want to create date in some kind of predefined format
You can use Conventer for GregorianCalendar for your app.
Best greetings,
Paweł Wielgus.
2010/7/27 Reeshi Agrawal <ru...@gmail.com>:
> Same problem with me...
> I want (through Struts 2 tags), a way to display date as three adjacent
> (side-by-side) drop-down menus, one each for date,month and year. Normally
> what will happen is: the three drop-down menus will be displayed in three
> separate consecutive rows in the HTML table generated in Struts 2. But I
> want them to be present in a single row in the displayed HTML table. Do I
> need to do some modification in the freeMarker templates' .ftl files? Or is
> there another very simple thing that I am missing?
> I know I am asking a very simp;e thing, but its bugging me from quite some
> time...
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Display GregorianCalendar Objects
Posted by Reeshi Agrawal <ru...@gmail.com>.
Same problem with me...
I want (through Struts 2 tags), a way to display date as three adjacent
(side-by-side) drop-down menus, one each for date,month and year. Normally
what will happen is: the three drop-down menus will be displayed in three
separate consecutive rows in the HTML table generated in Struts 2. But I
want them to be present in a single row in the displayed HTML table. Do I
need to do some modification in the freeMarker templates' .ftl files? Or is
there another very simple thing that I am missing?
I know I am asking a very simp;e thing, but its bugging me from quite some
time...