Hmmm.... but this way requires I have a markup, doesn't it? All I want is to "decorate" existing text field to carry attached map which can be populated with arbitrary bits of data. This isn't even a change to how the component works visually. Plus, assuming that this works, I'm loosing all the method of TextField component such as getClientId() getLabel() etc. I could generate delegates, but then I'm loosing JavaDoc for those methods.
A natural way as I see this would be to extend TextField class, but again it's final. Another interesting thing is that on Tapestry 5 website, specifically here: http://tapestry.apache.org/tapestry5/tapestry-core/guide/mixins.html under "Implementation Mixins" section, there is example where AutocompleteField extends TextField. -adam On Thu, Mar 20, 2008 at 6:13 AM, Kristian Marinkovic <[EMAIL PROTECTED]> wrote: > 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] > > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]