Search in sources :

Example 1 with NamingContainer

use of javax.faces.component.NamingContainer in project empire-db by apache.

the class WebApplication method findChildComponent.

/**
 * finds a child component with the given id that is located below the given parent component
 * @param parent the parent
 * @param componentId the component id
 * @return the component or null if no component was found
 */
public static UIComponent findChildComponent(UIComponent parent, String componentId) {
    UIComponent component = null;
    if (parent.getChildCount() == 0)
        return null;
    Iterator<UIComponent> children = parent.getChildren().iterator();
    while (children.hasNext()) {
        UIComponent nextChild = children.next();
        if (nextChild instanceof NamingContainer) {
            component = nextChild.findComponent(componentId);
        }
        if (component == null) {
            component = findChildComponent(nextChild, componentId);
        }
        if (component != null) {
            break;
        }
    }
    return component;
}
Also used : NamingContainer(javax.faces.component.NamingContainer) UIComponent(javax.faces.component.UIComponent)

Example 2 with NamingContainer

use of javax.faces.component.NamingContainer in project primefaces by primefaces.

the class PrimePartialResponseWriter method startMetadataIfNecessary.

protected void startMetadataIfNecessary() throws IOException {
    if (metadataRendered) {
        return;
    }
    metadataRendered = true;
    FacesContext context = FacesContext.getCurrentInstance();
    PrimeApplicationContext applicationContext = PrimeApplicationContext.getCurrentInstance(context);
    if (applicationContext != null) {
        try {
            // catch possible ViewExpired
            UIViewRoot viewRoot = context.getViewRoot();
            if (viewRoot != null) {
                // portlet parameter namespacing
                if (viewRoot instanceof NamingContainer) {
                    String parameterNamespace = viewRoot.getContainerClientId(context);
                    if (LangUtils.isNotEmpty(parameterNamespace)) {
                        String parameterPrefix = parameterNamespace;
                        if (applicationContext.getEnvironment().isAtLeastJsf23()) {
                            // https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790
                            parameterPrefix += UINamingContainer.getSeparatorChar(context);
                        }
                        Map<String, Object> params = new HashMap<>();
                        params.put("parameterPrefix", parameterPrefix);
                        encodeCallbackParams(params);
                    }
                }
                // we also skip update=@all, as the head with all resources, will already be rendered
                if (context.isPostback() && !context.getPartialViewContext().isRenderAll() && !applicationContext.getEnvironment().isAtLeastJsf23()) {
                    List<ResourceUtils.ResourceInfo> initialResources = DynamicResourcesPhaseListener.getInitialResources(context);
                    List<ResourceUtils.ResourceInfo> currentResources = ResourceUtils.getComponentResources(context);
                    if (initialResources != null && currentResources != null && currentResources.size() > initialResources.size()) {
                        List<ResourceUtils.ResourceInfo> newResources = new ArrayList<>(currentResources);
                        newResources.removeAll(initialResources);
                        boolean updateStarted = false;
                        for (int i = 0; i < newResources.size(); i++) {
                            ResourceUtils.ResourceInfo resourceInfo = newResources.get(i);
                            if (!updateStarted) {
                                ((PartialResponseWriter) getWrapped()).startUpdate("javax.faces.Resource");
                                updateStarted = true;
                            }
                            resourceInfo.getResource().encodeAll(context);
                        }
                        if (updateStarted) {
                            ((PartialResponseWriter) getWrapped()).endUpdate();
                        }
                    }
                }
            }
        } catch (Exception e) {
            throw new AbortProcessingException(e);
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PartialResponseWriter(javax.faces.context.PartialResponseWriter) AbortProcessingException(javax.faces.event.AbortProcessingException) IOException(java.io.IOException) JSONException(org.json.JSONException) UINamingContainer(javax.faces.component.UINamingContainer) NamingContainer(javax.faces.component.NamingContainer) ResourceUtils(org.primefaces.util.ResourceUtils) AbortProcessingException(javax.faces.event.AbortProcessingException) JSONObject(org.json.JSONObject) UIViewRoot(javax.faces.component.UIViewRoot)

Example 3 with NamingContainer

use of javax.faces.component.NamingContainer in project liferay-faces-alloy by liferay.

the class InputFileRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    InputFile inputFile = (InputFile) uiComponent;
    // Determine the valid content-types and maximum file size from the validator (if specified).
    String validContentTypesString = inputFile.getContentTypes();
    JavaScriptFragment[] validContentTypes;
    if ((validContentTypesString == null) || "".equals(validContentTypesString)) {
        validContentTypes = new JavaScriptFragment[] {};
    } else {
        validContentTypes = AlloyRendererUtil.toEscapedJavaScriptStringArray(validContentTypesString.split("\\s*,\\s*"));
    }
    String clientId = inputFile.getClientId(facesContext);
    Long maxFileSize = inputFile.getMaxFileSize();
    if (maxFileSize == null) {
        maxFileSize = Long.MAX_VALUE;
    }
    // If the component should render the upload progress table, then initialize the YUI progress uploader widget.
    if (inputFile.isShowProgress()) {
        String clientVarName = getClientVarName(facesContext, inputFile);
        String clientKey = inputFile.getClientKey();
        if (clientKey == null) {
            clientKey = clientVarName;
        }
        UIViewRoot viewRoot = facesContext.getViewRoot();
        Locale locale = viewRoot.getLocale();
        String formClientId = getParentFormClientId(inputFile);
        Application application = facesContext.getApplication();
        ViewHandler viewHandler = application.getViewHandler();
        String actionURL = viewHandler.getActionURL(facesContext, viewRoot.getViewId());
        String partialActionURL = facesContext.getExternalContext().encodePartialActionURL(actionURL);
        String namingContainerId = "";
        if (viewRoot instanceof NamingContainer) {
            namingContainerId = viewRoot.getContainerClientId(facesContext);
        }
        AjaxParameters ajaxParameters = new AjaxParameters(inputFile, clientId, formClientId);
        String execute = ajaxParameters.getExecute();
        String render = ajaxParameters.getRender();
        ExternalContext externalContext = facesContext.getExternalContext();
        I18n i18n = I18nFactory.getI18nInstance(externalContext);
        String notStartedMessage = i18n.getMessage(facesContext, locale, "not-started");
        JavaScriptFragment clientComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
        encodeFunctionCall(responseWriter, "LFAI.initProgressUploader", 'A', clientComponent, validContentTypes, clientId, formClientId, namingContainerId, inputFile.isAuto(), execute, render, partialActionURL, maxFileSize, notStartedMessage);
    } else // template and write it to the response.
    if (inputFile.isShowPreview()) {
        encodeFunctionCall(responseWriter, "LFAI.initPreviewUploader", 'A', validContentTypes, clientId, maxFileSize);
    }
}
Also used : Locale(java.util.Locale) ViewHandler(javax.faces.application.ViewHandler) InputFile(com.liferay.faces.alloy.component.inputfile.InputFile) ResponseWriter(javax.faces.context.ResponseWriter) NamingContainer(javax.faces.component.NamingContainer) ExternalContext(javax.faces.context.ExternalContext) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) UIViewRoot(javax.faces.component.UIViewRoot) Application(javax.faces.application.Application) I18n(com.liferay.faces.util.i18n.I18n)

Example 4 with NamingContainer

use of javax.faces.component.NamingContainer in project liferay-faces-alloy by liferay.

the class AutoCompleteRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // If the developer has specified a server-side filtering, then
    if (isServerFilteringEnabled(uiComponent)) {
        ResponseWriter responseWriter = facesContext.getResponseWriter();
        ClientComponent clientComponent = (ClientComponent) uiComponent;
        String clientVarName = getClientVarName(facesContext, clientComponent);
        String clientKey = clientComponent.getClientKey();
        if (clientKey == null) {
            clientKey = clientVarName;
        }
        // J-
        // var clientVarName = Liferay.component('clientKey');
        // J+
        encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
        JavaScriptFragment clientVarNameJSFragment = new JavaScriptFragment(clientVarName);
        String clientId = uiComponent.getClientId(facesContext);
        String hiddenClientId = clientId + HIDDEN_SUFFIX;
        String namingContainerId = null;
        UIViewRoot viewRoot = facesContext.getViewRoot();
        if (viewRoot instanceof NamingContainer) {
            namingContainerId = viewRoot.getContainerClientId(facesContext);
        }
        // J-
        // LFAI.setAutoCompleteEventListeners(A, clientVarName, 'escapedHiddenClientId', 'clientId',
        // 'namingContainerId');
        // J+
        encodeFunctionCall(responseWriter, "LFAI.initAutoCompleteServerMode", clientVarNameJSFragment, hiddenClientId, clientId, namingContainerId);
    }
}
Also used : BufferedScriptResponseWriter(com.liferay.faces.util.render.BufferedScriptResponseWriter) ResponseWriter(javax.faces.context.ResponseWriter) NamingContainer(javax.faces.component.NamingContainer) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) ClientComponent(com.liferay.faces.util.component.ClientComponent) UIViewRoot(javax.faces.component.UIViewRoot)

Aggregations

NamingContainer (javax.faces.component.NamingContainer)4 UIViewRoot (javax.faces.component.UIViewRoot)3 JavaScriptFragment (com.liferay.faces.util.render.JavaScriptFragment)2 ResponseWriter (javax.faces.context.ResponseWriter)2 InputFile (com.liferay.faces.alloy.component.inputfile.InputFile)1 ClientComponent (com.liferay.faces.util.component.ClientComponent)1 I18n (com.liferay.faces.util.i18n.I18n)1 BufferedScriptResponseWriter (com.liferay.faces.util.render.BufferedScriptResponseWriter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Application (javax.faces.application.Application)1 ViewHandler (javax.faces.application.ViewHandler)1 UIComponent (javax.faces.component.UIComponent)1 UINamingContainer (javax.faces.component.UINamingContainer)1 ExternalContext (javax.faces.context.ExternalContext)1 FacesContext (javax.faces.context.FacesContext)1 PartialResponseWriter (javax.faces.context.PartialResponseWriter)1 AbortProcessingException (javax.faces.event.AbortProcessingException)1