You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Scott Eade <se...@backstagetech.com.au> on 2001/06/28 03:06:28 UTC

Intake with Dates and booleans

Has anyone used intake with field types other than String
and the basic integer types?

In particular I am interested in boolean and Date fields.
Is there a way I can map a boolean to a checkbox and 
a Date to something a bit nicer than a standard text input
box (perhaps three selects)?

Can intake validate the date values?

Also, what are the onError and validator attributes of 
the field element for (as found in the DTD)?

Thanks,

Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Intake with Dates and booleans

Posted by Scott Eade <se...@backstagetech.com.au>.
From: "Jon Stevens" <jo...@latchkey.com>
> How about improving this class to do what you need:
> 
> jakarta-turbine/src/java/org/apache/turbine/util/DateSelector.java
> 
> That way, all you need to do is make it available in the Context as a
> PullTool and it will generate all the HTML (and Intake stuff) for what you
> need.
> 
> Or, if you don't like that, write a VelocityMacro that does essentially the
> same thing...
> 
> thanks,
> 
> -jon

Jon,

That looks quite useful.  

To pursue this right now I would have to ask "Where do I start?"
which is a bit too much like not putting in my fair share of thought
into the process.

I'll probably have a go at making this work once I am a little more 
familiar with turbine generally and a bit further along on my project 
(rapidly approaching deadline ;-]).

Thanks,

Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Intake with Dates and booleans

Posted by Jon Stevens <jo...@latchkey.com>.
on 6/28/01 6:46 AM, "Scott Eade" <se...@backstagetech.com.au> wrote:

> I have worked up an interim solution whereby I add a pair of
> wrapper methods around the date in the peer class thus:

How about improving this class to do what you need:

jakarta-turbine/src/java/org/apache/turbine/util/DateSelector.java

That way, all you need to do is make it available in the Context as a
PullTool and it will generate all the HTML (and Intake stuff) for what you
need.

Or, if you don't like that, write a VelocityMacro that does essentially the
same thing...

thanks,

-jon

-- 
If you come from a Perl or PHP background, JSP is a way to take
your pain to new levels. --Anonymous
<http://jakarta.apache.org/velocity/ymtd/ymtd.html>


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Intake with Dates and booleans

Posted by Scott Eade <se...@backstagetech.com.au>.
> There is boolean type        
> 
> Example
> 
> <field name="Active" key="active" type="boolean"/>
> 
> Here is a macro that adds a hidden value that intake will use in the
> event the box is unchecked.  It would be used similar to
> #booleanCheckbox($intake.Attribute.mapTo($attribute).Active)
> 
> #macro ( booleanCheckbox $booleanField )
>    <input type="checkbox" name="$booleanField.Key" value="true"
>         #if ($booleanField.Value) checked #end />
>    <input type="hidden" name="$booleanField.ValueIfAbsent"
>         value="false" />
> #end

Thanks - that was very helpful.

> Date types still need to be added.  Please help with this if you have
> the need.

I have worked up an interim solution whereby I add a pair of 
wrapper methods around the date in the peer class thus:

    public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance();

    public String getStartDateString()
    {
        return CmesConstants.DATE_FORMAT.format(getStartDate());
    }

    public void setStartDateString(String dateString)
    {
        try {
            setStartDate(CmesConstants.DATE_FORMAT.parse(dateString));
        }
        catch (ParseException ex) {
            Log.error("setStartDate(): Unable to parse dateString: " + dateString);
        }
    }

In my intake file I use the wrapper instead of the real attribute thus:

  <field name="StartDate" key="sdate" type="String" mapToProperty="StartDateString">
    <rule name="required" value="true">Please enter a start date.</rule>
    <rule name="mask" value="^[0-3]?\d/[01]?\d/[29][09]\d\d$">Please enter a sensible date ("dd/mm/yyyy").</rule>
  </field>

Note that the date format I am using here is that suitable
for Australia.  The mask allows for dates from 2000 through
2099 as well as the date 31/12/9999 which is my maximum 
date.

While not perfect, this solution should be adequate for my 
current application.  I am not confident enough yet to dive
in and have a go at writing a proper date validator.  It looks
like Ian might be on to this already.

> john mcnally

Thanks John,

Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Intake with Dates and booleans

Posted by Kasper Nielsen <ne...@kav.dk>.
----- Original Message -----
From: "Ian Lim" <ma...@ematic.com>
To: <tu...@jakarta.apache.org>
Sent: Thursday, June 28, 2001 8:43 AM
Subject: Re: Intake with Dates and booleans


> Hi
>
> Managed to start trying out intake on yesterday.
>
> Seems an interesting way to validate the inputs which my project has a lot
> to do :)
>
> Would there be any validator written for date values for intake ?
>
> I am thinking of writing one based on an inheritance from StringField.
>
> Any comments on this approach ?

yes,

If you a making a generic solution, remember that different contries has
different ways of writing the same date

ddmmyyyy
dd-mm-yyyy
ddmmyy
mmddyyyy
mmddyy
yyyymmdd
yyyyddmm

......
otherwise choose a name like USDateValidator


- Kasper

> Regards
> Ian Lim
>




---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Intake with Dates and booleans

Posted by Ian Lim <ma...@ematic.com>.
Hi

Mine would be a simpler version to help me to tide over
for my project first :P

The idea is to expose a rule eg
<rule name="date-format" value="dd/MM/yyyy">a message</rule>
and perhaps
<rule name="mask" value="regular expression for a valid date string">a
message</rule>

For my date field, is actually creating a selector based on javascript,
so I'm not going to take care of that for the time being.

Maybe when that is done, I will pass the source code over for improvement ?

Regards
Ian Lim


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Intake with Dates and booleans

Posted by Scott Eade <se...@backstagetech.com.au>.
From: "Ian Lim" <ma...@ematic.com>
> Hi
> 
> Managed to start trying out intake on yesterday.
> 
> Seems an interesting way to validate the inputs which my project has a lot
> to do :)
> 
> Would there be any validator written for date values for intake ?
> 
> I am thinking of writing one based on an inheritance from StringField.
> 
> Any comments on this approach ?
> 
> Regards
> Ian Lim

You would also need a validator based on DefaultValidator (as
per John's response to my original message).

The following are the obvious difficulties:

1. i18n - allowing for different formats for different locales.
2. date, time or date-time - the user may want to select from
one of these (or even components of these).
3. Input format - dates are a pain to enter in forms.  Often
it is nicest to present a date as a series of three selects.
How would this map back to a single intake field?
4. Actual date validation - what should happen when an
invalid date is presented, for example Feb 30?

Cheers,

Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Intake with Dates and booleans

Posted by Ian Lim <ma...@ematic.com>.
Hi

Managed to start trying out intake on yesterday.

Seems an interesting way to validate the inputs which my project has a lot
to do :)

Would there be any validator written for date values for intake ?

I am thinking of writing one based on an inheritance from StringField.

Any comments on this approach ?

Regards
Ian Lim

----- Original Message -----
From: "John McNally" <jm...@collab.net>
To: <tu...@jakarta.apache.org>
Sent: Thursday, June 28, 2001 9:39 AM
Subject: Re: Intake with Dates and booleans


> Scott Eade wrote:
> >
> > Has anyone used intake with field types other than String
> > and the basic integer types?
> >
> > In particular I am interested in boolean and Date fields.
> > Is there a way I can map a boolean to a checkbox and
> > a Date to something a bit nicer than a standard text input
> > box (perhaps three selects)?
> >
> > Can intake validate the date values?



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: Intake with Dates and booleans

Posted by John McNally <jm...@collab.net>.
Scott Eade wrote:
> 
> Has anyone used intake with field types other than String
> and the basic integer types?
> 
> In particular I am interested in boolean and Date fields.
> Is there a way I can map a boolean to a checkbox and
> a Date to something a bit nicer than a standard text input
> box (perhaps three selects)?
> 
> Can intake validate the date values?
> 


There is boolean type        

Example

<field name="Active" key="active" type="boolean"/>

Here is a macro that adds a hidden value that intake will use in the
event the box is unchecked.  It would be used similar to
#booleanCheckbox($intake.Attribute.mapTo($attribute).Active)

#macro ( booleanCheckbox $booleanField )
   <input type="checkbox" name="$booleanField.Key" value="true"
        #if ($booleanField.Value) checked #end />
   <input type="hidden" name="$booleanField.ValueIfAbsent"
        value="false" />
#end


Date types still need to be added.  Please help with this if you have
the need.



> Also, what are the onError and validator attributes of
> the field element for (as found in the DTD)?
> 


onError should be removed I think, I will make sure it is not used.
validator is used to override the default validator for a field type. 
For example the String type currently has the DefaultValidator as its
default which provides such things as maxLength and regexp mask rules. 
Let's say you have an EmailValidator that is more efficient than a mask
rule and would like to use that, you would specify the classname in the
validator attribute.


john mcnally

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org