Hi,

I am building a date input component with three select input fields
(day, month, year). Actually I am modifying the code from Alexander's
book. The goal is that the initial value of all three select
components are empty if the date parameter is not provided. Although
none of the t:select(s) has t:validate="required"

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
        <t:select t:value="day" t:model="dayModel" t:encoder="encoder"
t:disabled="disabled" class="drop40" t:blankOption="always"/>
        <t:select t:value="month" t:model="monthModel" t:disabled="disabled"
class="drop80" t:blankOption="always"/>
        <t:select t:value="year" t:model="yearModel" t:encoder="encoder"
t:disabled="disabled" class="drop55" t:blankOption="always"/>
</html>

the html generated includes this piece of javascript at the bottom:

<!--
Tapestry.DEBUG_ENABLED = true;
Tapestry.onDOMLoaded(function() {
Tapestry.init({"validate":[["select_1",[["required","You must provide
a value for Select 1."]]],["select",[["required","You must provide a
value for Select."]]]]});
});
// -->

...so when I submit the form I get two error bubbles - one for day,
and one for year.

Any clues?


This is part of the custom component class:

public class DayMonthYearDateInput implements Field {

...
    @Parameter(required = true)
    private Date date;

    private Calendar c = Calendar.getInstance();

    @SetupRender
    void setupCalendar() {
        logger.info("setupCalendar() : " + date);
        if (date!= null) {
            c.setTime(date);
        }
    }

    public SelectModel getDayModel() {
        return new IntegerSelectModel(1, 31);
    }

    public SelectModel getYearModel() {
        return new IntegerSelectModel(1960, 2010);
    }

    public SelectModel getMonthModel() {
        return new EnumSelectModel(Month.class, messages);
    }

    public ValueEncoder getEncoder() {
        return new IntegerValueEncoder();
    }

    public int getDay() {
        logger.info("getDay() : " + c.get(Calendar.DATE));
        return (date==null)?0:c.get(Calendar.DATE);
    }

    public void setDay(int day) {
        c.set(Calendar.DATE, day);
    }

    public Month getMonth() {
        logger.info("getMonth() : " + Month.values()[c.get(Calendar.MONTH)]);
        return (date==null)?null:Month.values()[c.get(Calendar.MONTH)];
    }

    public void setMonth(Month month) {
        c.set(Calendar.MONTH, month.getOrder());
    }

    public int getYear() {
        logger.info("getYear() : " + c.get(Calendar.YEAR));
        return (date==null)?0:c.get(Calendar.YEAR);
    }

}


Thanks,
Borut

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to