Is this the situation where Mixin could be of good use?

On Thu, Mar 20, 2008 at 5:55 AM, Adam Zimowski <[EMAIL PROTECTED]> wrote:
> I need to save some additional state into textfield, something similar
>  to form context.  I would have simply done:
>
>  public class TextFieldWithMap extends TextField {
>
>         @Parameter(defaultPrefix="prop")
>         private Map<String, Object> _dataMap;
>
>
>         public void setDataMap(Map<String, Object> aDataMap) {
>                 _dataMap = aDataMap;
>         }
>
>         public Object getDataValue(String aKey) {
>                 try { return _dataMap.get(aKey); }
>                 catch(NullPointerException npe) { return null; }
>         }
>  }
>
>  but TextField is a final class. Instead, I had to duplicate Tapestry
>  code and extend AbstractTextField:
>
>  public class TextFieldWithMap extends AbstractTextField {
>
>         @Parameter(defaultPrefix="prop")
>         private Map<String, Object> _dataMap;
>
>
>  // This is very UGLY (copied from TextField)
>         @Override
>         protected final void writeFieldTag(MarkupWriter aWriter, String 
> aValue) {
>                 aWriter.element(
>                                 "input","type", "text","name",
>                                 getControlName(),"id", getClientId(),
>                                 "value", aValue,"size", getWidth());
>         }
>
>  // This too, is very UGLY (copied from TextField)
>     final void afterRender(MarkupWriter writer) {
>         writer.end();
>     }
>
>         public void setDataMap(Map<String, Object> aDataMap) {
>                 _dataMap = aDataMap;
>         }
>
>         public Object getDataValue(String aKey) {
>                 try { return _dataMap.get(aKey); }
>                 catch(NullPointerException npe) { return null; }
>         }
>  }
>
>  My TextFieldWithMap component works as expected, I'm only asking what
>  are the reasons for TextField being a final class, and is my way of
>  building TextFieldWithMap typical "Tapestry 5" approach or should I do
>  it differently.
>
>  -adam
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to