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

📄 uitreedata.java

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**     * Returns a previously cached {@link TreeModel}, if any, or sets the cache variable to either the     * current value (if its a {@link TreeModel}) or to a new instance of {@link TreeModel} (if it's a     * {@link TreeNode}) with the provided value object as the root node.     *     * @return TreeModel     */    private TreeModel getDataModel()    {        if (_model != null)        {            return _model;        }        Object value = getValue();        if (value != null)        {            if (value instanceof TreeModel)            {                _model = (TreeModel) value;            } else if (value instanceof TreeNode)            {                _model = new TreeModel((TreeNode) value);            }        }        return _model;    }    private void processNodes(FacesContext context, int processAction, String parentId, int childLevel)    {        UIComponent facet = null;        setNodeId(parentId != null ? parentId + NamingContainer.SEPARATOR_CHAR + childLevel : "0");        TreeNode node = getNode();        facet = getFacet(node.getType());        if (facet == null)        {            throw new IllegalArgumentException("Unable to locate facet with the name: " + node.getType());        }        switch (processAction)        {            case PROCESS_DECODES:                facet.processDecodes(context);                break;            case PROCESS_VALIDATORS:                facet.processValidators(context);                break;            case PROCESS_UPDATES:                facet.processUpdates(context);                break;        }        processChildNodes(context, node, processAction);    }    /**     * Process the child nodes of the supplied parent @{link TreeNode}.  This method is protected so that     * it can be overriden by a subclass that may want to control how child nodes are processed.     *     * @param context       FacesContext     * @param parentNode    The parent node whose children are to be processed     * @param processAction An <code>int</code> representing the type of action to process     */    protected void processChildNodes(FacesContext context, TreeNode parentNode, int processAction)    {        int kidId = 0;        String currId = getNodeId();        List children = parentNode.getChildren();        for (int i = 0; i < children.size(); i++)        {            processNodes(context, processAction, currId, kidId++);        }    }    /**     * To support using input components for the nodes (e.g., input fields, checkboxes, and selection     * lists) while still only using one set of components for all nodes, the state held by the components     * for the current node must be saved for a new node is selected.     */    private void saveDescendantState()    {        FacesContext context = getFacesContext();        Iterator i = getFacets().values().iterator();        while (i.hasNext())        {            UIComponent facet = (UIComponent) i.next();            saveDescendantState(facet, context);        }    }    /**     * Overloaded helper method for the no argument version of this method.     *     * @param component The component whose state needs to be saved     * @param context   FacesContext     */    private void saveDescendantState(UIComponent component, FacesContext context)    {        if (component instanceof EditableValueHolder)        {            EditableValueHolder input = (EditableValueHolder) component;            String clientId = component.getClientId(context);            SavedState state = (SavedState) _saved.get(clientId);            if (state == null)            {                state = new SavedState();                _saved.put(clientId, state);            }            state.setValue(input.getLocalValue());            state.setValid(input.isValid());            state.setSubmittedValue(input.getSubmittedValue());            state.setLocalValueSet(input.isLocalValueSet());        }        List kids = component.getChildren();        for (int i = 0; i < kids.size(); i++)        {            saveDescendantState((UIComponent) kids.get(i), context);        }    }    /**     * Used to configure a new node with the state stored previously.     */    private void restoreDescendantState()    {        FacesContext context = getFacesContext();        Iterator i = getFacets().values().iterator();        while (i.hasNext())        {            UIComponent facet = (UIComponent) i.next();            restoreDescendantState(facet, context);        }    }    /**     * Overloaded helper method for the no argument version of this method.     *     * @param component The component whose state needs to be restored     * @param context   FacesContext     */    private void restoreDescendantState(UIComponent component, FacesContext context)    {        String id = component.getId();        component.setId(id); // forces the cilent id to be reset        if (component instanceof EditableValueHolder)        {            EditableValueHolder input = (EditableValueHolder) component;            String clientId = component.getClientId(context);            SavedState state = (SavedState) _saved.get(clientId);            if (state == null)            {                state = new SavedState();            }            input.setValue(state.getValue());            input.setValid(state.isValid());            input.setSubmittedValue(state.getSubmittedValue());            input.setLocalValueSet(state.isLocalValueSet());        }        List kids = component.getChildren();        for (int i = 0; i < kids.size(); i++)        {            restoreDescendantState((UIComponent)kids.get(i), context);        }    }    /**     * A regular bean with accessor methods for all state variables.     *     * @author Sean Schofield     * @author Hans Bergsten (Some code taken from an example in his O'Reilly JavaServer Faces book. Copied with permission)     * @version $Revision: 1.5 $ $Date: 2005/02/26 00:26:00 $     */    private static class SavedState implements Serializable    {        private Object submittedValue;        private boolean valid = true;        private Object value;        private boolean localValueSet;        Object getSubmittedValue()        {            return submittedValue;        }        void setSubmittedValue(Object submittedValue)        {            this.submittedValue = submittedValue;        }        boolean isValid()        {            return valid;        }        void setValid(boolean valid)        {            this.valid = valid;        }        Object getValue()        {            return value;        }        void setValue(Object value)        {            this.value = value;        }        boolean isLocalValueSet()        {            return localValueSet;        }        void setLocalValueSet(boolean localValueSet)        {            this.localValueSet = localValueSet;        }    }    /**     * Inner class used to wrap the original events produced by child components in the tree.     * This will allow the tree to find the appropriate component later when its time to     * broadcast the events to registered listeners.  Code is based on a similar private     * class for UIData.     */    private static class FacesEventWrapper extends FacesEvent    {        private FacesEvent _wrappedFacesEvent;        private String _nodeId;        public FacesEventWrapper(FacesEvent facesEvent, String nodeId, UIComponent component)        {            super(component);            _wrappedFacesEvent = facesEvent;            _nodeId = nodeId;        }        public PhaseId getPhaseId()        {            return _wrappedFacesEvent.getPhaseId();        }        public void setPhaseId(PhaseId phaseId)        {            _wrappedFacesEvent.setPhaseId(phaseId);        }        public void queue()        {            _wrappedFacesEvent.queue();        }        public String toString()        {            return _wrappedFacesEvent.toString();        }        public boolean isAppropriateListener(FacesListener faceslistener)        {            // this event type is only intended for wrapping a real event            return false;        }        public void processListener(FacesListener faceslistener)        {            throw new UnsupportedOperationException("This event type is only intended for wrapping a real event");        }        public FacesEvent getFacesEvent()        {            return _wrappedFacesEvent;        }        public String getNodeId()        {            return _nodeId;        }    }    /**     * Returns true if there is an error message queued for at least one of the nodes.     *     * @param context FacesContext     * @return whether an error message is present     */    private boolean keepSaved(FacesContext context)    {        Iterator clientIds = _saved.keySet().iterator();        while (clientIds.hasNext())        {            String clientId = (String) clientIds.next();            Iterator messages = context.getMessages(clientId);            while (messages.hasNext())            {                FacesMessage message = (FacesMessage) messages.next();                if (message.getSeverity().compareTo(FacesMessage.SEVERITY_ERROR) >= 0)                {                    return true;                }            }        }        return false;    }}

⌨️ 快捷键说明

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