tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-tapestry/framework/src/net/sf/tapestry/form DatePicker.jwc DatePicker.java DatePicker.html DatePicker.script
Date Mon, 03 Mar 2003 20:21:55 GMT
hlship      2003/03/03 12:21:55

  Modified:    framework/src/net/sf/tapestry/form DatePicker.jwc
                        DatePicker.java
  Removed:     framework/src/net/sf/tapestry/form DatePicker.html
                        DatePicker.script
  Log:
  Streamline DatePicker component.
  
  Revision  Changes    Path
  1.10      +7 -27     jakarta-tapestry/framework/src/net/sf/tapestry/form/DatePicker.jwc
  
  Index: DatePicker.jwc
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/net/sf/tapestry/form/DatePicker.jwc,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- DatePicker.jwc	7 Feb 2003 04:27:02 -0000	1.9
  +++ DatePicker.jwc	3 Mar 2003 20:21:55 -0000	1.10
  @@ -4,35 +4,15 @@
     "-//Apache Software Foundation//Tapestry Specification 1.4//EN" 
     "http://jakarta.apache.org/tapestry/dtd/Tapestry_1_4.dtd">
   
  -<component-specification class="net.sf.tapestry.form.DatePicker" allow-informal-parameters="no">
  +<component-specification
  +	class="net.sf.tapestry.form.DatePicker"
  +	allow-informal-parameters="no" 
  +	allow-body="no">
   
  -  <parameter name="value" direction="custom" type="java.util.Date" required="yes"/>
  +  <parameter name="value" direction="form" type="java.util.Date" required="yes"/>
     <parameter name="format" direction="in" type="java.lang.String" required="no"/>
     <parameter name="disabled" direction="in" type="boolean" required="no"/>
  -  
  -  <component id="dateTextField" type="TextField">
  -       	<binding name="value" expression="text"/>
  -        <binding name="maxlength" expression="format.length()"/>        
  -        <binding name="size" expression="format.length()"/>        
  -       	<binding name="disabled" expression="disabled"/>
  -  </component>
   
  -  <component id="dateHidden" type="Hidden">
  -       	<binding name="value" expression="timeMillis"/>
  -       	<binding name="encode" expression="false"/>
  -  </component>
  -
  -  <component id="formatHidden" type="Hidden">
  -       	<binding name="value" expression="format"/>
  -       	<binding name="encode" expression="false"/>
  -  </component>
  -
  -  <component id="popupButton" type="Button">
  -       	<binding name="disabled" expression="disabled"/>
  -  </component>
  -
  -  <component id="datePickerScript" type="Script">
  -        <static-binding name="script">/net/sf/tapestry/form/DatePicker.script</static-binding>
  -  </component>
  +  <private-asset name="script" resource-path="DatePicker.js"/>
           
   </component-specification>
  
  
  
  1.11      +88 -67    jakarta-tapestry/framework/src/net/sf/tapestry/form/DatePicker.java
  
  Index: DatePicker.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tapestry/framework/src/net/sf/tapestry/form/DatePicker.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- DatePicker.java	13 Jan 2003 03:33:19 -0000	1.10
  +++ DatePicker.java	3 Mar 2003 20:21:55 -0000	1.11
  @@ -54,12 +54,18 @@
    */
   package net.sf.tapestry.form;
   
  -import java.util.Date;
  +import java.text.DateFormat;
   import java.text.ParseException;
   import java.text.SimpleDateFormat;
  +import java.util.Date;
   
  -import net.sf.tapestry.BaseComponent;
  -import net.sf.tapestry.IBinding;
  +import net.sf.tapestry.IAsset;
  +import net.sf.tapestry.IForm;
  +import net.sf.tapestry.IMarkupWriter;
  +import net.sf.tapestry.IRequestCycle;
  +import net.sf.tapestry.RequestCycleException;
  +import net.sf.tapestry.Tapestry;
  +import net.sf.tapestry.html.Body;
   
   /**
    * Provides a Form <tt>java.util.Date</tt> field component for selecting dates.
  @@ -73,92 +79,107 @@
    * 
    **/
   
  -public class DatePicker extends BaseComponent
  +public abstract class DatePicker extends AbstractFormComponent
   {
  -    private IBinding _valueBinding;
  -    private SimpleDateFormat _dateFormat = new SimpleDateFormat("dd MMM yyyy");
  -    private boolean _disabled;
  +    private String _name;
   
  -    public String getFormat()
  -    {
  -        return _dateFormat.toPattern();
  -    }
  +    public abstract String getFormat();
   
  -    public void setFormat(String format)
  -    {
  -        _dateFormat = new SimpleDateFormat(format);
  -    }
  +    public abstract Date getValue();
   
  -    public String getTimeMillis()
  +    public abstract void setValue(Date value);
  +
  +    public abstract boolean isDisabled();
  +
  +    protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
  +        throws RequestCycleException
       {
  -        Date date = getValue();
  +        IForm form = getForm(cycle);
   
  -        if (date == null)
  -            return "";
  +        _name = form.getElementId(this);
   
  -        return Long.toString(date.getTime());
  -    }
  +        String format = getFormat();
   
  -    public void setTimeMillis(String value)
  -    {
  -    }
  +        if (format == null)
  +            format = "dd MMM yyyy";
   
  -    public String getText()
  -    {
  -        Date date = getValue();
  +        DateFormat formatter = new SimpleDateFormat(format);
   
  -        if (date == null)
  -            return "";
  +        boolean disabled = isDisabled();
   
  -        return _dateFormat.format(date);
  -    }
  +        if (!cycle.isRewinding())
  +        {
  +            Body body = Body.get(cycle);
   
  -    public void setText(String text)
  -    {
  -        if (text.length() >= 6)
  +            IAsset script = getAsset("script");
  +
  +            body.includeScript(script.buildURL(cycle));
  +
  +            Date value = getValue();
  +
  +            writer.beginEmpty("input");
  +            writer.attribute("type", "text");
  +            writer.attribute("name", _name);
  +            writer.attribute("maxlength", format.length());
  +            writer.attribute("size", format.length());
  +
  +            if (value != null)
  +                writer.attribute("value", formatter.format(value));
  +
  +            if (disabled)
  +                writer.attribute("disabled", "disabled");
  +
  +            writer.beginEmpty("input");
  +            writer.attribute("type", "hidden");
  +            writer.attribute("name", _name + "$millis");
  +
  +            if (value == null)
  +                writer.attribute("value", "");
  +            else
  +                writer.attribute("value", Long.toString(value.getTime()));
  +
  +            writer.beginEmpty("input");
  +            writer.attribute("type", "hidden");
  +            writer.attribute("name", _name + "$format");
  +            writer.attribute("value", format);
  +
  +            writer.beginEmpty("input");
  +            writer.attribute("type", "button");
  +            writer.attribute("name", _name + "$button");
  +
  +            if (disabled)
  +                writer.attribute("disabled", "disabled");
  +
  +            writer.attribute("value", "V");
  +            writer.attribute("onClick", "javascript:goCalendar(this);");
  +        }
  +
  +        if (form.isRewinding())
           {
  +            if (disabled)
  +                return;
  +
  +            String textValue = cycle.getRequestContext().getParameter(_name);
  +
  +            if (Tapestry.isNull(textValue))
  +                return;
  +
               try
               {
  -                setValue(_dateFormat.parse(text));
  +                Date value = formatter.parse(textValue);
  +
  +                setValue(value);
               }
  -            catch (ParseException pe)
  +            catch (ParseException ex)
               {
  -                setValue(null);
               }
           }
  -        else
  -        {
  -            setValue(null);
  -        }
  -    }
   
  -    public Date getValue()
  -    {
  -        return (Date) _valueBinding.getObject();
  -    }
  -
  -    public void setValue(Date value)
  -    {
  -        _valueBinding.setObject(value);
       }
   
  -    public IBinding getValueBinding()
  +    public String getName()
       {
  -        return _valueBinding;
  +        return _name;
       }
   
  -    public void setValueBinding(IBinding value)
  -    {
  -        _valueBinding = value;
  -    }
  -
  -    public boolean isDisabled()
  -    {
  -        return _disabled;
  -    }
  -
  -    public void setDisabled(boolean disabled)
  -    {
  -        _disabled = disabled;
  -    }        
   }
  
  
  

Mime
View raw message