Ray
Ray

Reputation: 1828

Struts1 Output util.Date according with specific format in <html:text> for different Locale

I use Struts 1.

And have next bean

import java.util.Date;

public class Event {
     private String name;
     private Date date;
     // getters & setters
}

And form

public class Holiday {
    private Event event;
    // getters & setters
}

I have jsp for adding new holiday

<html:text name="holidayForm" property="event.date" altKey="date.pattern" maxlength="10" size="10" /></label>

And I cant get date or put default date as Date date = new Date(); in particular format on jsp.

How can I do this?

Upvotes: 1

Views: 1780

Answers (1)

Anthony Grist
Anthony Grist

Reputation: 38345

Rather than making your field a Date, make it a String that represents the date in the correct format. You can use the SimpleDateFormatter class to convert between the two. You could also take a look at the jQuery UI Datepicker module (Javascript, so it will run client-side) to allow your users to select a date (in the correct format), rather than typing it in themselves.

Struts 1 form bean properties are almost always Strings because the built-in type conversion is quite limited. If you map a text input directly to a Date field in your form bean class, the value is expected to be in the format YYYY-MM-DD and you'll get an Error 500: beanUtils.populate error if it doesn't match.

Upvotes: 3

Related Questions