Search in sources :

Example 6 with Renderer

use of javax.faces.render.Renderer in project primefaces by primefaces.

the class UIData method getClientId.

@Override
public String getClientId(FacesContext context) {
    if (clientId != null) {
        return clientId;
    }
    String id = getId();
    if (id == null) {
        UniqueIdVendor parentUniqueIdVendor = ComponentTraversalUtils.closestUniqueIdVendor(this);
        if (parentUniqueIdVendor == null) {
            UIViewRoot viewRoot = context.getViewRoot();
            if (viewRoot != null) {
                id = viewRoot.createUniqueId();
            } else {
                throw new FacesException("Cannot create clientId for " + getClass().getCanonicalName());
            }
        } else {
            id = parentUniqueIdVendor.createUniqueId(context, null);
        }
        setId(id);
    }
    UIComponent namingContainer = ComponentTraversalUtils.closestNamingContainer(this);
    if (namingContainer != null) {
        String containerClientId = namingContainer.getContainerClientId(context);
        if (containerClientId != null) {
            StringBuilder sb = SharedStringBuilder.get(context, SB_ID, containerClientId.length() + 10);
            clientId = sb.append(containerClientId).append(UINamingContainer.getSeparatorChar(context)).append(id).toString();
        } else {
            clientId = id;
        }
    } else {
        clientId = id;
    }
    Renderer renderer = getRenderer(context);
    if (renderer != null) {
        clientId = renderer.convertClientId(context, clientId);
    }
    return clientId;
}
Also used : SharedStringBuilder(org.primefaces.util.SharedStringBuilder) Renderer(javax.faces.render.Renderer) FacesException(javax.faces.FacesException)

Example 7 with Renderer

use of javax.faces.render.Renderer in project primefaces by primefaces.

the class UIRepeat method process.

public void process(FacesContext faces, PhaseId phase) {
    // stop if not rendered
    if (!this.isRendered())
        return;
    PrimeEnvironment environment = PrimeApplicationContext.getCurrentInstance(faces).getEnvironment();
    if (environment.isMojarra()) {
        LOGGER.log(Level.WARNING, "Mojarra versions 2.3.18, 3.0.3, and 4.0+ do not require p:repeat, " + "please upgrade and switch to ui:repeat.");
    } else {
        LOGGER.log(Level.WARNING, "Apache MyFaces does not require p:repeat, please switch to ui:repeat.");
    }
    // clear datamodel
    this.resetDataModel();
    // We must clear the child state if we just entered the Render Phase, and there are no error messages
    if (PhaseId.RENDER_RESPONSE.equals(phase) && !hasErrorMessages(faces)) {
        this.clearChildState();
    }
    // reset index
    this.captureOrigValue(faces);
    this.setIndex(faces, -1);
    try {
        // has children
        if (this.getChildCount() > 0) {
            Iterator itr;
            UIComponent c;
            Integer begin = this.getBegin();
            Integer step = this.getStep();
            Integer end = this.getEnd();
            Integer offset = this.getOffset();
            if (null != offset && offset > 0) {
                begin = offset;
            }
            Integer size = this.getSize();
            if (null != size) {
                end = size;
            }
            // grab renderer
            String rendererType = getRendererType();
            Renderer renderer = null;
            if (rendererType != null) {
                renderer = getRenderer(faces);
            }
            int rowCount = getDataModel().getRowCount();
            int i = ((begin != null) ? begin : 0);
            int e = ((end != null) ? end : rowCount);
            int s = ((step != null) ? step : 1);
            validateIterationControlValues(rowCount, i, e);
            if (null != size && size > 0) {
                e = size - 1;
            }
            this.setIndex(faces, i);
            this.updateIterationStatus(faces, new IterationStatus(true, (i + s > e || rowCount == 1), i, begin, end, step));
            while (i <= e && this.isIndexAvailable()) {
                if (PhaseId.RENDER_RESPONSE.equals(phase) && renderer != null) {
                    renderer.encodeChildren(faces, this);
                } else {
                    itr = this.getChildren().iterator();
                    while (itr.hasNext()) {
                        c = (UIComponent) itr.next();
                        if (PhaseId.APPLY_REQUEST_VALUES.equals(phase)) {
                            c.processDecodes(faces);
                        } else if (PhaseId.PROCESS_VALIDATIONS.equals(phase)) {
                            c.processValidators(faces);
                        } else if (PhaseId.UPDATE_MODEL_VALUES.equals(phase)) {
                            c.processUpdates(faces);
                        } else if (PhaseId.RENDER_RESPONSE.equals(phase)) {
                            c.encodeAll(faces);
                        }
                    }
                }
                i += s;
                this.setIndex(faces, i);
                this.updateIterationStatus(faces, new IterationStatus(false, i + s >= e, i, begin, end, step));
            }
        }
    } catch (IOException e) {
        throw new FacesException(e);
    } finally {
        this.setIndex(faces, -1);
        this.restoreOrigValue(faces);
    }
    /*
         * Once rendering is done we need to make sure the child components
         * are not still having client ids that use an index.
         */
    if (PhaseId.RENDER_RESPONSE.equals(phase)) {
        resetClientIds(this);
    }
}
Also used : UIComponent(javax.faces.component.UIComponent) Renderer(javax.faces.render.Renderer) PrimeEnvironment(org.primefaces.config.PrimeEnvironment) IOException(java.io.IOException) IterationStatus(org.primefaces.component.api.IterationStatus) FacesException(javax.faces.FacesException)

Example 8 with Renderer

use of javax.faces.render.Renderer in project primefaces by primefaces.

the class SelectOneMenu method queueEvent.

@Override
public void queueEvent(FacesEvent event) {
    if (event instanceof AjaxBehaviorEvent) {
        FacesContext context = getFacesContext();
        AjaxBehaviorEvent behaviorEvent = (AjaxBehaviorEvent) event;
        Map<String, String> params = context.getExternalContext().getRequestParameterMap();
        String eventName = params.get(Constants.RequestParams.PARTIAL_BEHAVIOR_EVENT_PARAM);
        if ("itemSelect".equals(eventName)) {
            Renderer renderer = ComponentUtils.getUnwrappedRenderer(context, "javax.faces.SelectOne", "javax.faces.Menu");
            Object item = renderer.getConvertedValue(context, this, getSubmittedValue());
            SelectEvent selectEvent = new SelectEvent(this, behaviorEvent.getBehavior(), item);
            selectEvent.setPhaseId(event.getPhaseId());
            super.queueEvent(selectEvent);
        } else {
            super.queueEvent(event);
        }
    } else {
        super.queueEvent(event);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) Renderer(javax.faces.render.Renderer) AjaxBehaviorEvent(javax.faces.event.AjaxBehaviorEvent) SelectEvent(org.primefaces.event.SelectEvent)

Example 9 with Renderer

use of javax.faces.render.Renderer in project gdmatrix by gdmatrix.

the class FCKFaceEditor method encodeEnd.

/**
 * Moved to encode end so that the inline java script will run after the textArea was rendered before this script is run
 * @param context
 * @throws IOException
 */
public void encodeEnd(FacesContext context) throws IOException {
    String editorRenderer = DEFAULT_RENDERER_TYPE;
    try {
        UserPreferences userPreferences = UserSessionBean.getCurrentInstance().getUserPreferences();
        editorRenderer = userPreferences.getPreference("ckEditor");
    } catch (Exception ex) {
    }
    if (editorRenderer == null)
        editorRenderer = DEFAULT_RENDERER_TYPE;
    RenderKit renderKit = context.getRenderKit();
    Renderer renderer = renderKit.getRenderer(getFamily(), editorRenderer);
    if (renderer != null)
        renderer.encodeEnd(context, this);
    else
        getRenderer(context).encodeEnd(context, this);
}
Also used : UserPreferences(org.santfeliu.web.UserPreferences) RenderKit(javax.faces.render.RenderKit) Renderer(javax.faces.render.Renderer) IOException(java.io.IOException)

Example 10 with Renderer

use of javax.faces.render.Renderer 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

Renderer (javax.faces.render.Renderer)18 UIComponent (javax.faces.component.UIComponent)7 RenderKit (javax.faces.render.RenderKit)7 FacesContext (javax.faces.context.FacesContext)6 ResponseWriter (javax.faces.context.ResponseWriter)4 IOException (java.io.IOException)3 FacesException (javax.faces.FacesException)3 ExternalContext (javax.faces.context.ExternalContext)2 AjaxBehaviorEvent (javax.faces.event.AjaxBehaviorEvent)2 Test (org.junit.Test)2 SelectEvent (org.primefaces.event.SelectEvent)2 ResourceComponent (com.liferay.faces.bridge.component.internal.ResourceComponent)1 FileUploadRendererPortletImpl (com.liferay.faces.bridge.renderkit.bridge.internal.FileUploadRendererPortletImpl)1 InlineScript (com.liferay.faces.bridge.renderkit.html_basic.internal.InlineScript)1 HeadRendererICEfacesImpl (com.liferay.faces.bridge.renderkit.icefaces.internal.HeadRendererICEfacesImpl)1 FormRendererPrimeFacesImpl (com.liferay.faces.bridge.renderkit.primefaces.internal.FormRendererPrimeFacesImpl)1 HeadRendererPrimeFacesImpl (com.liferay.faces.bridge.renderkit.primefaces.internal.HeadRendererPrimeFacesImpl)1 FileUploadRendererRichFacesImpl (com.liferay.faces.bridge.renderkit.richfaces.internal.FileUploadRendererRichFacesImpl)1 Product (com.liferay.faces.util.product.Product)1 ProductFactory (com.liferay.faces.util.product.ProductFactory)1