You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Borut Bolčina <bo...@gmail.com> on 2009/03/07 08:57:09 UTC

Client validation occurs even when there is no t:validate

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-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Client validation occurs even when there is no t:validate

Posted by Howard Lewis Ship <hl...@gmail.com>.
Primitive types (int vs. java.lang.Integer) are always required
because there's no way to indicate that a value is not present, i.e.,
null.

On Fri, Mar 6, 2009 at 11:57 PM, Borut Bolčina <bo...@gmail.com> wrote:
> 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-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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