I want to automatically set the labels attributes for the UIInput components in my pages, to the HtmlOutputLabel components I already put, like the PrimeFaces developer did: http://cagataycivici.wordpress.com/2011/02/11/label-provider-for-jsf-input-components/ Only he did it using System Events, a feature available only in JSF-2.0, and my application is in JSF 1.2.
Is it possible to do it using JSF-1.2, with maybe a Phase Listener? What would be the drawbacks?
Thanks in advance!
UPDATE: This is what my attempt with a Phase Listener looks until now:
@Override
public void beforePhase(PhaseEvent event) {
System.out.println("REGISTERING Label Provider");
FacesContext context = event.getFacesContext();
List<UIComponent> components = context.getViewRoot().getChildren();
for (UIComponent uiComponent : components) {
if (uiComponent instanceof HtmlOutputLabel) {
HtmlOutputLabel outputLabel = (HtmlOutputLabel) uiComponent;
System.out.println("CONFIGURING LABEL: " + outputLabel.getId());
UIComponent target = outputLabel.findComponent(outputLabel
.getFor());
if (target != null) {
target.getAttributes().put("label", outputLabel.getValue());
}
}
}
}
@Override
public PhaseId getPhaseId() {
// Only listen during the render response phase.
return PhaseId.RENDER_RESPONSE;
}
When I access the view, it never prints the section "CONFIGURING LABEL". What would be the right test to verify if a uiComponent is a HtmlOutputLabel? Or what am I doing wrong?