Hi Bruce,

BruceLee wrote:
I digged days, tried to search on this forum, got some good info for my
question, but still puzzles. We use 1.9.4 with WebWork.

We want default conversion from string on JSP to Date in model using Appfuse
DateConverter. I want to use fixed format yyyy-MM-dd. Then I set
ApplicationResource.properties:
data.format=yyyy-MM-dd.
^^^ is this what you actually have? The file should be "ApplicationResources.properties" (note the 's' on the end of the filename) and the key should be "date.format" not "data.format" which is what you have. I suspect the above may just be typos, in which case, see below for more info on working out what's wrong.
In JSP I have something like
        <input name="agent.beginDate" type="text" value="" size="10"
id="beginDate">

In model Agent.java
...
private Date beginDate;
    public void setBeginDate(Date beginDate) {
        this.beginDate = beginDate;
    }

However, the web page doesn't accept yyyy-MM-dd like 2007-01-01; only
accepts MM/dd/yyyy which is my web server's locale date format.

We also tried to add a file WEB-INF/classes/xwork-conversion.properties:
java.util.Date=DateConverter
//or java.util.Date=com.myorg.util.DateConverter
But it didn't help.
Your one of AppFuse jars will contain org.appfuse.util.Dateconverter which is responsible for default date conversions. You can see its source here:

http://fisheye4.cenqua.com/browse/appfuse/trunk/src/service/org/appfuse/util/DateConverter.java?r=1174

Looking at this, you'll see it uses a pattern returned by org.appfuse.util.DateUtil.getDatePattern() to convert dates. The source for DateUtil is here:

http://fisheye4.cenqua.com/browse/appfuse/trunk/src/service/org/appfuse/util/DateUtil.java?r=1730

There you can see that it tries to load this pattern from your *locale-specific* resource bundle (looking for the key "date.format" and if it doesn't find that file, it loads the default, which is the US default "MM/dd/yyyy".

Your attempt to use your own converter seems to be OK, though I note that in the snippet from your "xwork-conversion.properties" file, you commented out the "//or java.util.date=com.myorg.uti.DateConverter" with a Java comment which won't work in a properties file (use # instead). Did you test your DateConverter class? When I wrote my first converter, it took a number of iterations to get it right. I was not getting any errors, just the wrong conversion. Then I wrote some unit tests for my DateConverter class (I know, I know, I should have done that first - I learned the hard way) and discovered it wasn't working properly.

So, the date pattern in your resource bundle (check which locale your webserver is using) should work, provided you've modified the right resource bundle file and used the correct key. I'd chase down that path before I went trying to write my own converter to do a simple date pattern.

HTH,

Rob Hills
Waikiki,  Western Australia

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to