there is a new way in tapestry (i think since 5.0.11) to inherit 
from (core) components. all you need to do is let your 
component have a reference to the component it wants to 
extend. futhermore the inheritInformalParameters of the 
@Component annotation has to be set to true...


public class MyTextField() {
   @Component(inheritInformalParameters=true,...)
   private TextField field;

}

g,
kris




"Adam Zimowski" <[EMAIL PROTECTED]> 
20.03.2008 11:58
Bitte antworten an
"Tapestry users" <users@tapestry.apache.org>


An
"Tapestry users" <users@tapestry.apache.org>
Kopie

Thema
Re: [T5] Why is TextField a final class?







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