Class WBeanComponent

    • Constructor Detail

      • WBeanComponent

        public WBeanComponent()
    • Method Detail

      • getBean

        public Object getBean()

        Retrieves the bean. The following are searched in order:

        • a bean set explicitly using setBean;
        • a bean cached in the scratch map;
        • a bean provided by a BeanProvider (and subsequently cached in the scratch map);
        • a bean provided by a bean-aware parent component (and subsequently cached in the scratch map).
        Specified by:
        getBean in interface BeanAware
        Returns:
        this component's bean for the given context
      • setBean

        public void setBean​(Object bean)
        Sets the bean associated with this WBeanComponent. This method of bean association is discouraged, as the bean will be stored in the user's session. A better alternative is to provide a BeanProvider and a Bean Id.
        Specified by:
        setBean in interface BeanBound
        Parameters:
        bean - the bean to associate
      • setBeanId

        public void setBeanId​(Object beanId)
        Sets the bean id associated with this WBeanComponent. This bean id will be used to obtain the bean from the associated BeanProvider whenever the bean data is required.
        Specified by:
        setBeanId in interface BeanProviderBound
        Parameters:
        beanId - the bean id to associate
        See Also:
        BeanProviderBound
      • getBeanId

        public Object getBeanId()
        Retrieves the bean id associated with this component. This method will be used by a BeanProvider to retrieve the bean.
        Specified by:
        getBeanId in interface BeanProviderBound
        Returns:
        the bean Id associated with this component
      • setBeanProperty

        public void setBeanProperty​(String propertyName)
        Sets the bean property that this component is interested in. The bean property is expressed in Jakarta PropertyUtils bean notation, with an extension of "." to indicate that the bean itself should be used.
        Specified by:
        setBeanProperty in interface BeanAware
        Parameters:
        propertyName - the bean property, in Jakarta PropertyUtils bean notation
      • getBeanProperty

        public String getBeanProperty()
        Retrieves the bean property that this component is interested in.
        Specified by:
        getBeanProperty in interface BeanAware
        Returns:
        the bean property, in Jakarta PropertyUtils bean notation
      • isSearchAncestors

        public boolean isSearchAncestors()
        Flag to indicate if a bean should be searched for up the component tree. If set true and the current component does not have a bean, then ask the next bean aware ancestor for its bean. If false and the component does not have a bean, then do not search the tree for a bean and return null.

        Setting this to false at the correct bean container level can stop a bean component going up the whole component tree looking for its bean and being given the wrong bean.

        Specified by:
        isSearchAncestors in interface BeanBound
        Returns:
        true if search ancestors for a bean, otherwise false to not search
      • setSearchAncestors

        public void setSearchAncestors​(boolean search)
        Parameters:
        search - true if search ancestors for the components bean
      • setBeanProvider

        public void setBeanProvider​(BeanProvider beanProvider)
        Sets the BeanProvider associated with this WBeanComponent. The bean provider will be called to supply the bean whenever necessary.
        Specified by:
        setBeanProvider in interface BeanProviderBound
        Parameters:
        beanProvider - the bean provider to associate
      • getBeanProvider

        public BeanProvider getBeanProvider()
        Returns:
        the associated bean provider, or null
      • getData

        public Object getData()
        Returns the data for this component. The following are searched in order:
        • a value set explicitly in the ui context using setData(Object);
        • if a bean is available; the bean's value; or
        • the value set on the shared model.
        Specified by:
        getData in interface DataBound
        Returns:
        the current value of this component for the given context
      • setData

        public void setData​(Object data)
        Sets the data that this component displays/edits. For bean aware components, this should only be called from handleRequest to set user-entered data.
        Specified by:
        setData in interface DataBound
        Parameters:
        data - the data to set
      • getBeanValue

        public Object getBeanValue()
        Retrieves the bean value. The value is (temporarily) cached in the scratch map to speed up subsequent accesses.
        Specified by:
        getBeanValue in interface BeanAware
        Returns:
        the bean value, or null if no bean value is available
      • updateBeanValue

        public void updateBeanValue()
        Updates the bean value with the value returned by getData().
      • doUpdateBeanValue

        protected void doUpdateBeanValue​(Object value)
        Updates the bean value with the new value.
        Parameters:
        value - the new value with which to update the bean
      • isUseRequestScopeScratchMap

        protected boolean isUseRequestScopeScratchMap()
        Returns:
        true if use request scope scratch map to hold bean provider results
      • removeBeanFromScratchMap

        protected void removeBeanFromScratchMap()
        Remove the bean from the scratch maps.
      • isBeanInScratchMap

        protected boolean isBeanInScratchMap​(Object beanId)
        Parameters:
        beanId - check if this bean id is in the scratch map
        Returns:
        true if current bean is in the scratch map
      • getBeanFromScratchMap

        protected Object getBeanFromScratchMap()
        Returns:
        the bean from the scratch map
      • addBeanToScratchMap

        protected void addBeanToScratchMap​(Object beanId,
                                           Object bean)
        Parameters:
        beanId - the bean id to put in the scratch map
        bean - the bean to put in the scratch map
      • getBeanScratchMap

        protected Map<Object,​Object> getBeanScratchMap()
        Returns:
        the scratch map with the correct scope.
      • isChanged

        public boolean isChanged()
        Indicates whether this component's data has changed from the default value. TODO: This needs to be added to the databound interface after the bulk of the components have been converted.
        Returns:
        true if this component's current value differs from the default value for the given context.
      • resetData

        public void resetData()
        Resets the data back to the default value, which may either be from a bean or the shared model.
      • getOrCreateComponentModel

        protected BeanAndProviderBoundComponentModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class AbstractWComponent
        Returns:
        the model for this component