⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uicomponenttag.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            {                component.getAttributes().put(FORMER_FACET_NAMES_SET_ATTR, _facetsAdded);            }        }        else        {            if (_facetsAdded != null)            {                component.getAttributes().put(FORMER_FACET_NAMES_SET_ATTR, _facetsAdded);            }        }    }    protected void encodeBegin()            throws IOException    {        _componentInstance.encodeBegin(getFacesContext());    }    protected void encodeChildren()            throws IOException    {        _componentInstance.encodeChildren(getFacesContext());    }    protected void encodeEnd()            throws IOException    {        _componentInstance.encodeEnd(getFacesContext());    }    protected UIComponent findComponent(FacesContext context)            throws JspException    {        if (_componentInstance != null) return _componentInstance;        UIComponentTag parentTag = getParentUIComponentTag(pageContext);        if (parentTag == null)        {            //This is the root            _componentInstance = context.getViewRoot();            setProperties(_componentInstance);            return _componentInstance;        }        UIComponent parent = parentTag.getComponentInstance();        //TODO: what if parent == null?        if (parent == null) throw new IllegalStateException("parent is null?");        String facetName = getFacetName();        if (facetName != null)        {            //Facet            String id = getOrCreateUniqueId(context);            _componentInstance = parent.getFacet(facetName);            if (_componentInstance == null)            {                _componentInstance = createComponentInstance(context, id);                setProperties(_componentInstance);                parent.getFacets().put(facetName, _componentInstance);            }            addFacetNameToParentTag(parentTag, facetName);            return _componentInstance;        }        else        {            //Child            String id = getOrCreateUniqueId(context);            _componentInstance = parent.findComponent(id);            if (_componentInstance == null)            {                _componentInstance = createComponentInstance(context, id);                setProperties(_componentInstance);                int index = getAddedChildrenCount(parentTag);                List children = parent.getChildren();                if (index <= children.size())                {                    children.add(index, _componentInstance);                }                else                {                    throw new FacesException("cannot add component with id '" +                            _componentInstance.getId() + "' and path : "                            +getPathToComponent(_componentInstance)+" to its parent component. This might be a problem due to duplicate ids.");                }            }            addChildIdToParentTag(parentTag, id);            return _componentInstance;        }    }    private String getOrCreateUniqueId(FacesContext context)    {        String id = getId();        if (id != null)        {            return id;        }        else        {            return context.getViewRoot().createUniqueId();        }    }    private UIComponent createComponentInstance(FacesContext context, String id)    {        String componentType = getComponentType();        if (componentType == null)        {            throw new NullPointerException("componentType");        }        if (_binding != null)        {            Application application = context.getApplication();            ValueBinding componentBinding = application.createValueBinding(_binding);            UIComponent component = application.createComponent(componentBinding,                                                                context,                                                                componentType);            component.setId(id);            component.setValueBinding("binding", componentBinding);            recurseFacetsAndChildrenForId(context, component.getFacetsAndChildren(), id + "_", 0);            _created = true;            return component;        }        else        {            UIComponent component = context.getApplication().createComponent(componentType);            component.setId(id);            _created = true;            return component;        }    }    /**     * Recurse all facets and children and assign them an unique ID if necessary.     * We must *not* use UIViewRoot#createUniqueId here, because this would affect the     * order of the created ids upon rerendering the page!     */     private int recurseFacetsAndChildrenForId(FacesContext context,                                              Iterator facetsAndChildren,                                              String idPrefix,                                              int cnt)    {        while (facetsAndChildren.hasNext())        {            UIComponent comp = (UIComponent)facetsAndChildren.next();            if (comp.getId() == null)            {                ++cnt;                comp.setId(idPrefix + cnt);            }            cnt = recurseFacetsAndChildrenForId(context, comp.getFacetsAndChildren(), idPrefix, cnt);        }        return cnt;    }    private void addChildIdToParentTag(UIComponentTag parentTag, String id)    {        if (parentTag._childrenAdded == null)        {            parentTag._childrenAdded = new HashSet();        }        parentTag._childrenAdded.add(id);    }    private void addFacetNameToParentTag(UIComponentTag parentTag, String facetName)    {        if (parentTag._facetsAdded == null)        {            parentTag._facetsAdded = new HashSet();        }        parentTag._facetsAdded.add(facetName);    }                                 private int getAddedChildrenCount(UIComponentTag parentTag)    {        return parentTag._childrenAdded != null ?               parentTag._childrenAdded.size() :               0;    }    protected int getDoStartValue()            throws JspException    {        return Tag.EVAL_BODY_INCLUDE;    }    protected int getDoEndValue()            throws JspException    {        return Tag.EVAL_PAGE;    }    protected FacesContext getFacesContext()    {        if (_facesContext == null)        {            _facesContext = FacesContext.getCurrentInstance();        }        return _facesContext;    }    private boolean isFacet()    {        return _parent != null && _parent instanceof FacetTag;    }    protected String getFacetName()    {        return isFacet() ? ((FacetTag)_parent).getName() : null;    }    protected boolean isSuppressed()    {        if (_suppressed == null)        {            if (isFacet())            {                // facets are always rendered by their parents --> suppressed                return (_suppressed = Boolean.TRUE).booleanValue();            }            UIComponent component = getComponentInstance();            // Does any parent render its children?            // (We must determine this first, before calling any isRendered method            //  because rendered properties might reference a data var of a nesting UIData,            //  which is not set at this time, and would cause a VariableResolver error!)            UIComponent parent = component.getParent();            while (parent != null)            {                if (parent.getRendersChildren())                {                    //Yes, parent found, that renders children --> suppressed                    return (_suppressed = Boolean.TRUE).booleanValue();                }                parent = parent.getParent();            }            // does component or any parent has a false rendered attribute?            while (component != null)            {                if (!component.isRendered())                {                    //Yes, component or any parent must not be rendered --> suppressed                    return (_suppressed = Boolean.TRUE).booleanValue();                }                component = component.getParent();            }            // else --> not suppressed            _suppressed = Boolean.FALSE;        }        return _suppressed.booleanValue();    }    protected void setProperties(UIComponent component)    {        if (getRendererType() != null)        {            _componentInstance.setRendererType(getRendererType());        }        if (_rendered != null)        {            if (isValueReference(_rendered))            {                ValueBinding vb = getFacesContext().getApplication().createValueBinding(_rendered);                component.setValueBinding("rendered", vb);            } else            {                boolean b = Boolean.valueOf(_rendered).booleanValue();                component.setRendered(b);            }        }    }    protected void setupResponseWriter()    {        FacesContext facesContext = getFacesContext();        _writer = facesContext.getResponseWriter();        if (_writer == null)        {            RenderKitFactory renderFactory = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);            RenderKit renderKit = renderFactory.getRenderKit(facesContext,                                                             facesContext.getViewRoot().getRenderKitId());                        _writer = renderKit.createResponseWriter(new _PageContextOutWriter(pageContext),                                                     pageContext.getRequest().getContentType(), //TODO: is this the correct content type?                                                     pageContext.getRequest().getCharacterEncoding());            facesContext.setResponseWriter(_writer);        }    }    public static String getPathToComponent(UIComponent component)    {        StringBuffer buf = new StringBuffer();        if(component == null)        {            buf.append("{Component-Path : ");            buf.append("[null]}");            return buf.toString();        }        getPathToComponent(component,buf);        buf.insert(0,"{Component-Path : ");        buf.append("}");        return buf.toString();    }    private static void getPathToComponent(UIComponent component, StringBuffer buf)    {        if(component == null)            return;        StringBuffer intBuf = new StringBuffer();        intBuf.append("[Class: ");        intBuf.append(component.getClass().getName());        if(component instanceof UIViewRoot)        {            intBuf.append(",ViewId: ");            intBuf.append(((UIViewRoot) component).getViewId());        }        else        {            intBuf.append(",Id: ");            intBuf.append(component.getId());        }        intBuf.append("]");        buf.insert(0,intBuf);        if(component!=null)        {            getPathToComponent(component.getParent(),buf);        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -