THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
There are three different approaches to adding or updating a Components HTML attributes.
- The first approach is the simplest approach which overrides the Components "onComponentTag" method. In your WebPage:
... // this can be any Component new TextField("my-text-field", myModel){ @Override protected void onComponentTag(final ComponentTag tag){ super.onComponentTag(tag); tag.put("onmouseover", "foo();return false;"); } }; ...
- The second decoupled approach is to use a generic AbstractBehavior. In your WebPage:
... new TextField("my-text-field", myModel).add(new AbstractBehavior(){ @Override public void onComponentTag(Component component, ComponentTag tag) { tag.put("onmouseover", "foo();return false;"); } }); ...
- The second decoupled approach is to use an AttributeModifier/AttributeAppender. In your WebPage:
... new TextField("my-text-field", myModel).add(new AttributeAppender("onmouseover", new Model("foo();return false;"), ";")); ...