views:

566

answers:

1

I have a simple struts2 from:

<s:form ...>
<s:textfield name="initialTime" maxlength="5" size="5" />
</s:form>

Where the user has to enter a time in HH:mm format. In the corresponding Action, I have a property:

private Date initialTime;

along with its getter/setter.

I am getting a validation problem, as the received initialTime (i.e. 10:20) is not understood as a valid Date.

What is the good approach to retrieve times ? Should I use a private String initialTime field instead of a Date ?

Thanks.

+1  A: 

I think you'll have to change the property to a String and programatically transform it to whatever final format you want. While I may see cases where the conversion from HH:mm to a Date may make sense, I think we can agree this is not a general scenario.

./alex

alexpopescu