No idea, but I'm currently using joda dates with the
dropdowndatepicker/timepickers with a similar contribution and things
are working fine. (of course I might have technical advantages, and I
did have to refactor those components some to allow the joda date
objects to be bound instead of just java,util.Date )

On 3/25/07, Doychi <[EMAIL PROTECTED]> wrote:
Hi All,

I'm having some problems with JPA and translators.

I have been able to set up a number of pages for CRUD, but in one class
I am using Joda's Time and Date library (specifically the DateTime
class).  Now it came as no surprise that this class can't be used
directly from the HTML form and I would have to write a bit of code to
sort this out.  So when I came to the page to create the Event Session
(session) I thought no problems I'll use a rtanslator, but I have been
unable to get the translator to work.

The problem appears to be that the translator doesn't get called, which
I can prove by using the debugger and placing a break point in both the
formatObject and parseText.  As you can see below I call
ognl:session.startDate, which populates the form field with
2007-03-25T00:00:00.000+11:00, which is what I would expect for
DateTime.toString().

Can any one tell me why the translator may not be executed for
presentation (and possibly on submission)?

Thanks,

Below I have included some information from the relevant files:

------ HTML -------
<tr>
        <td><label jwcid="@FieldLabel" field="component:startDate">Start
        Date:</label></td>
        <td><input jwcid="[EMAIL PROTECTED]" displayName="Start Date:"
            value="ognl:session.startDate" validators="validators:required"
            translators="translator:dateTime" /></td><!--
,pattern=dd/MM/yyyy -->
    </tr>
------ HTML -------

------- hivemodule.xml ---------
<?xml version="1.0"?>
<module id="au.org.pheno.f1" version="0.0.1">
    <!-- Validators and Translators -->
    <contribution configuration-id="tapestry.form.translator.Translators">
        <bean name="dateTime"
class="au.org.pheno.tapestry.translator.JodaDateTime" />
    </contribution>
</module>
------- hivemodule.xml ---------

------- JodaDateTime.java (translator) --------
public class JodaDateTime extends AbstractTranslator {

    private static final DateTimeFormatter DATE_TIME_PATTERN =
DateTimeFormat
            .forPattern("dd/MM/YYYY");

    /**
     * @see
org.apache.tapestry.form.translator.AbstractTranslator#formatObject(org.apache.tapestry.form.IFormComponent,
     *      Locale, java.lang.Object)
     */
    protected String formatObject(IFormComponent field, Locale locale,
            Object object) {

        ReadableDateTime dateTime = null;
        String date = null;
        if (object == null) {
            dateTime = new DateTime();
        } else {
            dateTime = (DateTime) object;
        }

        date = DATE_TIME_PATTERN.print(dateTime);

        return date;
    }

    /**
     * @see
org.apache.tapestry.form.translator.AbstractTranslator#parseText(org.apache.tapestry.form.IFormComponent,
     *      ValidationMessages, java.lang.String)
     */
    protected Object parseText(IFormComponent field,
            ValidationMessages messages, String text) throws
ValidatorException {
        DateTime dateTime = null;

        try {
            dateTime = DATE_TIME_PATTERN.parseDateTime(text);
        } catch (IllegalArgumentException e) {
            throw new ValidatorException(e.getMessage());
        }

        return dateTime;
    }

    protected ValidationConstraint getConstraint() {
        System.err.println("Validating JodaDateTime");
        return ValidationConstraint.DATE_FORMAT;
    }

  public JodaDateTime() {
        super();
        // _pattern = defaultPattern();
    }

    // Needed until HIVEMIND-134 fix is available
    public JodaDateTime(String initializer) {
        super();
        PropertyUtils.configureProperties(this, initializer);
    }
}
------- JodaDateTime.java (translator) --------


--
Doychi
[EMAIL PROTECTED]



---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 000727-1, 03/23/2007
Tested on: 3/25/2007 5:44:42 PM
avast! - copyright (c) 1988-2007 ALWIL Software.
http://www.avast.com



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




--
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

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

Reply via email to