joi, 11 iunie 2015

[OmniFaces utilities 2.0] Write component attribute of the given name as given HTML attribute name associated with given component property name


[OmniFaces utilities] The writeAttribute() method writes component attribute of the given name, if it's not empty, as given HTML attribute name associated with given component property name.

Method:
Usage:

Use the below Renderers#writeAttribute() whenever you need to render the attribute of a component (if it's not empty) for which you can provide:

·         the ResponseWriter instance
·         the associated UI component (usually the parent component)
·         the component attribute name whose value should be written
·         the HTML attribute name to be written
·         the associated component property name

Below you can see two examples:

import org.omnifaces.util.Renderers;
...
@Override
public void encodeBegin(FacesContext context) throws IOException {
 ResponseWriter writer = context.getResponseWriter();
 ...  
 Renderers.writeAttribute(writer, this, "value", "src", "value");
 Renderers.writeAttribute(writer, getParent(), "styleClass", "class", "styleClass");
}

Niciun comentariu:

Trimiteți un comentariu