Search in sources :

Example 1 with FormRenderer

use of org.santfeliu.faces.dynamicform.render.FormRenderer in project gdmatrix by gdmatrix.

the class DynamicForm method chooseBestRendererType.

// internal methods
protected String chooseBestRendererType(String rendererTypes) {
    Form form = getForm();
    String[] array = rendererTypes.split(",");
    FacesContext facesContext = getFacesContext();
    RenderKit renderKit = facesContext.getRenderKit();
    String bestRendererType = null;
    int bestSuitability = 0;
    for (String rendererType : array) {
        rendererType = rendererType.trim();
        Renderer renderer = renderKit.getRenderer(FAMILY, rendererType);
        int suitability;
        if (renderer instanceof FormRenderer) {
            FormRenderer formRenderer = (FormRenderer) renderer;
            suitability = formRenderer.getSuitability(form, facesContext);
        } else {
            // default suitability
            suitability = 1;
        }
        if (suitability > bestSuitability) {
            bestSuitability = suitability;
            bestRendererType = rendererType;
        }
    }
    return bestRendererType;
}
Also used : FacesContext(javax.faces.context.FacesContext) Form(org.santfeliu.form.Form) FormRenderer(org.santfeliu.faces.dynamicform.render.FormRenderer) RenderKit(javax.faces.render.RenderKit) FormRenderer(org.santfeliu.faces.dynamicform.render.FormRenderer) Renderer(javax.faces.render.Renderer)

Aggregations

FacesContext (javax.faces.context.FacesContext)1 RenderKit (javax.faces.render.RenderKit)1 Renderer (javax.faces.render.Renderer)1 FormRenderer (org.santfeliu.faces.dynamicform.render.FormRenderer)1 Form (org.santfeliu.form.Form)1