Designing and Implementing Composite Applications : webMethods CAF Development Help : Working with Facelets : Java Annotations in CAF and OpenCAF Applications : CAF Client-Side Annotations
CAF Client-Side Annotations
These annotations provide additional CAF-specific metadata for custom components defined with annotations:
*@ClientSideModel. If this annotation is found on a custom JSF renderer class, then the configured client-side-model will be used for the rendered component.
*@ClientSideValidator. If this annotation is found on a custom validator class, then the additional client-side validation will be applied to any input control that is bound to the validator.
Pertinent code is highlighted in bold.
Example: Client-Side Model
package caf.war.testapp 1.test1;
 
import com.webmethods.caf.faces.annotations. ClientSideModel;
import com.webmethods.caf.faces.annotations. ClientSideScript;
import com.webmethods.caf.faces.render.html.input.BaseHtmlInputRenderer;
 
/**
 * Sample that demonstrates how to declare the CAF client-side-model 
 * that should be used for the rendered component.
 */

@ClientSideModel (
    function = "CAF.TestApp1Custom.Model", //model js function
    base = "testapp1", //app containing the .js resources
    scripts = { //additional .js files to load into the page
        @ClientSideScript (
            resource = "/dyn/j/ui/js/controls/custom.js",
            library = "controls/testapp1"
        )
    }

)
public class CustomRenderer extends BaseHtmlInputRenderer {
 
    //TODO add your renderer implementation here
}
Example: Client-Side Validator
package caf.war.testapp1.test1;
 
import javax.faces.application.FacesMessage;
import javax.faces.component .UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
 
import com.webmethods.caf.common.StringTools;
import com.webmethods.caf.faces.annotations.ClientSideScript;
import com.webmethods.caf.faces.annotations.ClientSideValidator;

/**
 * Demonstrates creating a custom server-side validator from scratch.
 */
@FacesValidator(value="caf.war.testapp 1.test1.validator.custom")
// (optionally) register the equivalent client-side validator as below

@ClientSideValidator (
        function = "TestApp1.customValidate", //validate js function
        base = "testapp1", //app containing the .js resources
        scripts = { //additional .js files to load into the page
            @ClientSideScript (
                resource = "/js/validators/custom.js",
                library = "validators/testapp1"
            )
        }
    )
public class CustomValidator implements Validator {
    /* (non-Javadoc)
     * @see         javax.faces.validator.Validator#validate(javax.faces.context.
              FacesContext, javax.faces.component.UIComponent, java.lang.Object)
     */
    @Override
    public void validate(FacesContext context,
            UIComponent component,
            Object value) throws ValidatorException {
        if (!"hello".equals(value)) {
            Object o = component.getAttributes().get("label");
            if (o == null || (o instanceof String &&
                    ((String) o).length() == 0)) {
                o = component.getValueExpression("label");
            }
            String label = null;
            if (o instanceof String) {
            label = (String)o;
            }
            FacesMessage msg = null;
            if (StringTools.notEmpty(label)) {
                msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                        label + " : Value must be 'hello'", //summary
                        label + " : Value must be 'hello'"); //details
            } else {
                msg = new FacesMessage(FacesMessage.SEVERITY_ERROR,
                        "Value must be 'hello'", //summary
                        "Value must be 'hello'"); //details
            }
            throw new ValidatorException(msg);
        }
    }
}
Copyright © 2016- 2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback