Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
...

// 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;");
	}
};

...

You can also add to existing tag attributes using the onComponentTag:

Code Block

Image img = new Image("my-img-id") {
	@Override
	protected void onComponentTag(ComponentTag tag) {
		// illustrates how to prevent an image from caching by adding a random value to the src attribute
		super.onComponentTag(tag);
		String src = (String) tag.getAttributes().get("src");
		src = src + "&rand=" + Math.random();
		tag.getAttributes().put("src", src);
	}
};

A decoupled approach is to use a generic AbstractBehavior. In your WebPage:

...