Hi All,
I am just about to check in the new ComponentTagAttributeModifier class. Having overcome a number of structural problems I finally found a really clean way to implement it, so I went ahead and did so. This class is a direct replacement for HtmlTagModifier and all of its sub-classes (CascadingStyleSheet, Bold and Italic) and is intended to support both component tag modification and dynamic localization of component attributes through a single mechanism. I have removed references to HtmlTagModifier and its sub-classes from all of the code and all of the examples. However I have only deprecated the classes at the moment - I will remove them in a few days when everyone has confirmed they are happy with the new approach. The new class is supplied with a full unit test case and a test application built using the mock application framework. Detailed javadoc explains how to use it.
Just to refresh a previous discussion: HtmlTagModifier and its subclasses are a poor solution to the problem of changing the attributes of a tag because they also alter the component hierarchy at the same time. The ability to change attribute values should be a responsibility of the Component class (and its subclasses) in much the same way that Components can change their body content. ComponentTagAttributeModifier achieves this objective and at the same time brings much more power to the component model.
The only downside to the implementation is that the methods to add and apply attribute modifiers had to be added to Component rather than HtmlComponent as it is the Component class that currently deals with rendering the ComponentTag elements. I would prefer all of this functionality to be a responsibility of HtmlComponent, but I have left this refactoring to another day because I need to think it through in more detail.
Examples of using the new ComponentTagAttributeModifier include:
Label label = new Label("label", new Model("Label Text"));
label.addAttributeModifier(new ComponentTagAttributeModifier("class", new Model("overriddenStyle")));
Image image = new Image("myImage", imageModel);
Image.addAtttibuteModifier(new ComponentTagAttributeModifier("alt", new StringResourceModel(imageModel.getTextKey(), image, null)));
The component tag attribute modifier can be set up to alter existing markup tags or introduce additional tags where the HTML developer has not put them in the markup.
One thing I am aware of is that ComponentTagAttributeModifier is quite a long name. However, there will be other attribute modifiers coming in the future to support the other localization requirements (e.g. MarkupTagAttributeModifier).
Have fun,
Chris
Chris Turner
Enterprise Multimedia Applications
Nortel Networks
Maidenhead Office Park, Westacott Way,
Maidenhead, Berkshire, UK SL6 3QH
Tel: 01628 437250 (ESN: 560-7250)
Email: [EMAIL PROTECTED]
