📄 component.java
字号:
if (!behavior.isTemporary()) { addStateChange(new AddedBehaviorChange(behavior)); } // Give handler the opportunity to bind this component behavior.bind(this); return this; } private void addBehavior(final IBehavior behavior) { data_add(behavior); } private List getBehaviorsImpl() { if (data != null) { // if the model is set, we must skip it final int startIndex = getFlag(FLAG_MODEL_SET) ? 1 : 0; int length = data_length(); if (length > startIndex) { final ArrayList result = new ArrayList(); for (int i = startIndex; i < length; ++i) { Object o = data_get(i); if (o instanceof IBehavior) { result.add(o); } } return result; } } return null; } /** * Called on very component after the page is rendered. It will call onAfterRender for it self * and its children. */ public final void afterRender() { // if the component has been previously attached via attach() // detach it now try { setFlag(FLAG_AFTER_RENDERING, true); onAfterRender(); getApplication().notifyComponentOnAfterRenderListeners(this); if (getFlag(FLAG_AFTER_RENDERING)) { throw new IllegalStateException(Component.class.getName() + " has not been properly detached. Something in the hierarchy of " + getClass().getName() + " has not called super.onAfterRender() in the override of onAfterRender() method"); } // always detach children because components can be attached // independently of their parents onAfterRenderChildren(); } finally { // this flag must always be set to false. setFlag(FLAG_RENDERING, false); } } private final void internalBeforeRender() { if ((isVisible() || callOnBeforeRenderIfNotVisible()) && !getFlag(FLAG_RENDERING) && !getFlag(FLAG_PREPARED_FOR_RENDER)) { setFlag(FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED, false); onBeforeRender(); getApplication().notifyComponentOnBeforeRenderListeners(this); if (!getFlag(FLAG_BEFORE_RENDERING_SUPER_CALL_VERIFIED)) { throw new IllegalStateException(Component.class.getName() + " has not been properly rendered. Something in the hierarchy of " + getClass().getName() + " has not called super.onBeforeRender() in the override of onBeforeRender() method"); } } } /** * We need to postpone calling beforeRender() on components that implement IFeedback, to be sure * that all other component's beforeRender() has been already called, so that IFeedbacks can * collect all feedback messages. This is the key under list of postponed IFeedback is stored to * request cycle metadata. The List is then iterated over in {@link #prepareForRender()} after * calling {@link #beforeRender()}, to initialize postponed components. */ private static final MetaDataKey FEEDBACK_LIST = new MetaDataKey(List.class) { private static final long serialVersionUID = 1L; }; /** * Called for every component when the page is getting to be rendered. it will call * onBeforeRender for this component and all the child components */ public final void beforeRender() { if (!(this instanceof IFeedback)) { internalBeforeRender(); } else { // this component is a feedback. Feedback must be initialized last, so that // they can collect messages from other components List feedbacks = (List)getRequestCycle().getMetaData(FEEDBACK_LIST); if (feedbacks == null) { feedbacks = new ArrayList(); getRequestCycle().setMetaData(FEEDBACK_LIST, (Serializable)feedbacks); } feedbacks.add(this); } } /** * Redirects to any intercept page previously specified by a call to redirectToInterceptPage. * * @return True if an original destination was redirected to * @see Component#redirectToInterceptPage(Page) */ public final boolean continueToOriginalDestination() { return getPage().getPageMap().continueToOriginalDestination(); } /** * Registers a debug feedback message for this component * * @param message * The feedback message */ public final void debug(final String message) { Session.get().getFeedbackMessages().debug(this, message); Session.get().dirty(); } /** * Detaches the component. This is called at the end of the request for all the pages that are * touched in that request. */ public final void detach() { // if the component has been previously attached via attach() // detach it now setFlag(FLAG_DETACHING, true); onDetach(); if (getFlag(FLAG_DETACHING)) { throw new IllegalStateException(Component.class.getName() + " has not been properly detached. Something in the hierarchy of " + getClass().getName() + " has not called super.onDetach() in the override of onDetach() method"); } setFlag(FLAG_ATTACHED, false); // always detach models because they can be attached without the // component. eg component has a compoundpropertymodel and one of its // children component's getmodelobject is called detachModels(); // always detach children because components can be attached // independently of their parents detachChildren(); // reset the model to null when the current model is a IWrapModel and // the model that created it/wrapped in it is a IComponentInheritedModel // The model will be created next time. if (getFlag(FLAG_INHERITABLE_MODEL)) { setModelImpl(null); setFlag(FLAG_INHERITABLE_MODEL, false); } } /** * THIS IS WICKET INTERNAL ONLY. DO NOT USE IT. * * Traverses all behaviors and calls detachModel() on them. This is needed to cleanup behavior * after render. This method is necessary for {@link AjaxRequestTarget} to be able to cleanup * component's behaviors after header contribution has been done (which is separated from * component render). */ public final void detachBehaviors() { List behaviors = getBehaviorsImpl(); if (behaviors != null) { for (Iterator i = behaviors.iterator(); i.hasNext();) { IBehavior behavior = (IBehavior)i.next(); // Always detach models, 'accepted' or not. Otherwise, if they // are accepted during render, but not here - something can go // undetached, and calling isEnabled can also lead to nasty side // effects. See for instance Timo's comment on // http://issues.apache.org/jira/browse/WICKET-673 behavior.detach(this); if (behavior.isTemporary()) { removeBehavior(behavior); } } } } /** * Detaches all models */ public void detachModels() { // Detach any detachable model from this component detachModel(); // detach any behaviors detachBehaviors(); } /** * Registers an error feedback message for this component * * @param message * The feedback message */ public final void error(final Serializable message) { Session.get().getFeedbackMessages().error(this, message); Session.get().dirty(); } /** * Registers an fatal error feedback message for this component * * @param message * The feedback message */ public final void fatal(final String message) { Session.get().getFeedbackMessages().fatal(this, message); Session.get().dirty(); } /** * Finds the first container parent of this component of the given class. * * @param c * MarkupContainer class to search for * @return First container parent that is an instance of the given class, or null if none can be * found */ public final MarkupContainer findParent(final Class c) { // Start with immediate parent MarkupContainer current = parent; // Walk up containment hierarchy while (current != null) { // Is current an instance of this class? if (c.isInstance(current)) { return current; } // Check parent current = current.getParent(); } // Failed to find component return null; } /** * @return The nearest markup container with associated markup */ public final MarkupContainer findParentWithAssociatedMarkup() { MarkupContainer container = parent; while (container != null) { if (container.hasAssociatedMarkup()) { return container; } container = container.getParent(); } // This should never happen since Page always has associated markup throw new WicketRuntimeException("Unable to find parent with associated markup"); } /** * Gets interface to application that this component is a part of. * * @return The application associated with the session that this component is in. * @see Application */ public final Application getApplication() { return Application.get(); } /** * Gets the currently coupled {@link IBehavior}s as a unmodifiable list. Returns an empty list * rather than null if there are no behaviors coupled to this component. * * @return The currently coupled behaviors as a unmodifiable list */ public final List/* <IBehavior> */getBehaviors() { return getBehaviors(null); } /** * @return A path of the form [page-class-name].[page-relative-path] * @see Component#getPageRelativePath() */ public final String getClassRelativePath() { return getClass().getName() + PATH_SEPARATOR + getPageRelativePath(); } /** * @return component border assigned to this component, or null if none */ public final IComponentBorder getComponentBorder() { return (IComponentBorder)getMetaData(BORDER_KEY); } /** * @return nothing, will always throw an exception. Use {@link #getConverter(Class)} instead. * @deprecated To be removed. Please use/ override {@link #getConverter(Class)} instead. */ public final IConverter getConverter() { throw new UnsupportedOperationException("use #getConverter(Class) instead"); } /** * Gets the converter that should be used by this component. * * @param type * The type to convert to * * @return The converter that should be used by this component */ public IConverter getConverter(Class/* <?> */type) { return getApplication().getConverterLocator().getConverter(type); } /** * Gets whether model strings should be escaped. * * @return Returns whether model strings should be escaped */ public final boolean getEscapeModelStrings() { return getFlag(FLAG_ESCAPE_MODEL_STRINGS); } /** * @return Any feedback message for this component */ public final FeedbackMessage getFeedbackMessage() { return Session.get().getFeedbackMessages().messageForComponent(this); } /** * Gets the id of this component. * * @return The id of this component */ public String getId() { return id; } /** * @return Innermost model for this component */ public final IModel getInnermostModel() { return getInnermostModel(getModel()); } /** * Gets the locale for this component. By default, it searches its parents for a locale. If no * parents (it's a recursive search) returns a locale, it gets one from the session. * * @return The locale to be used for this component * @see Session#getLocale() */ public Locale getLocale() { Locale locale = null; if (parent != null) { locale = parent.getLocale(); } return (locale != null) ? locale : getSession().getLocale(); } /** * Convenience method to provide easy access to the localizer object within any component. * * @return The localizer object */ public final Localizer getLocalizer() { return getApplication().getResourceSettings().getLocalizer(); } /** * THIS IS WICKET INTERNAL ONLY. DO NOT USE IT. * * Get a copy of the markup's attributes which are associated with the component. * <p> * Modifications to the map returned don't change the tags attributes. It is just a copy. * <p> * Note: The component must have been added (directly or indirectly) to a container with an * associated markup file (Page, Panel or Border). * * @return markup attributes */ public final ValueMap getMarkupAttributes() { MarkupStream markupStream = locateMarkupStream(); ValueMap attrs = new ValueMap(markupStream.getTag().getAttributes()); attrs.makeImmutable(); return attrs; } final Object getMarkupIdImpl() { if (generatedMarkupId != -1) { return new Integer(generatedMarkupId); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -