Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.apache.tapestry.dojo.form;
  
 
 import java.util.*;

Implementation of an html form input field that has a dynamic drop down selection list of time segments displayed in the org.apache.tapestry.IPage's java.util.Locale.
 
 public abstract class GTimePicker  extends AbstractFormWidget implements TranslatedField
 {
    
For a full day - broken up in to half hour segments.
 
     static final int TIME_SEGMENT_LENGTH = 48;

    
Core value used to place input in to.

Returns:
The current bound value, may be null.
 
     public abstract Object getValue();
 
     public abstract void setValue(Object value);
 
     public abstract boolean isDisabled();

    
 
     protected void renderFormWidget(IMarkupWriter writerIRequestCycle cycle)
     {
         String value = getTranslatedFieldSupport().format(thisgetValue());
 
         renderDelegatePrefix(writercycle);
 
         writer.beginEmpty("input");
         writer.attribute("type""text");
         writer.attribute("autocomplete""off");
         writer.attribute("name"getName());
 
         if (isDisabled())
             writer.attribute("disabled""disabled");
 
         if (value != null)
             writer.attribute("value"value);
 
         renderIdAttribute(writercycle);
         renderDelegateAttributes(writercycle);
 
         getTranslatedFieldSupport().renderContributions(thiswritercycle);
         getValidatableFieldSupport().renderContributions(thiswritercycle);
 
         renderInformalParameters(writercycle);
 
         writer.closeTag();
 
         renderDelegateSuffix(writercycle);
 
         // Build up options value list
 
         Locale locale = getPage().getLocale();
         
         GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance(getPage().getLocale());
         cal.set(., 0);
         cal.set(..);
 
         StringBuffer optStr = new StringBuffer("[");
         int selectedIndex = -1;
         
         for(int i=0, hour=0; i < i++)
         {
             if (i != 0)
             {
                 optStr.append(",");
             }
             
             if (i == 24)
             {
                 hour = 0;
                 cal.set(..);
             }
             
             cal.set(.,  hour);
             cal.set(., (i % 2 > 0) ? 30 : 0);
 
             String option = getTranslator().format(thislocalecal.getTime());
 
             optStr.append("\"").append(option).append("\"");
             
            if (selectedIndex < 0 && value != null && value.equals(option))
            {
                selectedIndex = i;
            }
            if (i % 2 > 0)
            {
                hour++;
            }
        }
        optStr.append("]");
        
        // now create widget parms
        JSONObject json = new JSONObject();
        json.put("inputNodeId"getClientId());
        json.put("optionValues"new JSONLiteral(optStr.toString()));
        if (selectedIndex > -1)
        {
            json.put("selectedIndex"selectedIndex);
        }
        Map parms = new HashMap();
        parms.put("clientId"getClientId());
        parms.put("props"json.toString());
        parms.put("widget"this);
        getScript().execute(thiscycle, TapestryUtils.getPageRenderSupport(cyclethis), parms);
    }

    
    protected void rewindFormWidget(IMarkupWriter writerIRequestCycle cycle)
    {
        String value = cycle.getParameter(getName());
        try
        {
            Object translated = getTranslatedFieldSupport().parse(thisvalue);
            getValidatableFieldSupport().validate(thiswritercycletranslated);
            setValue(translated);
        }
        catch (ValidatorException e)
        {
            getForm().getDelegate().record(e);
        }
    }

    
    public boolean isRequired()
    {
        return getValidatableFieldSupport().isRequired(this);
    }

    
Injected.
    public abstract IScript getScript();

    
Injected.
    public abstract TranslatedFieldSupport getTranslatedFieldSupport();

    
Injected.
New to GrepCode? Check out our FAQ X