Class WAjaxControl

  • All Implemented Interfaces:
    WComponent, WebComponent, Serializable

    public class WAjaxControl
    extends AbstractWComponent

    The WAjaxControl links an AJAX trigger component with one or more AJAX target components. Creating an AJAX trigger will result in an AJAX request being made on the 'onChange' event of the trigger element. The implication of this is that an AJAX trigger component should have an Action attached (usually via setActionOnChanged).

    During an AJAX request the whole UI tree is serviced in the action phase but only the 'target' components of this control will be painted in the response.

    Since:
    1.0.0
    Author:
    Christina Harris, Mark Reeves
    See Also:
    Serialized Form
    • Constructor Detail

      • WAjaxControl

        public WAjaxControl​(AjaxTrigger trigger)
        Create a WAjaxControl with a specified trigger component.
        Parameters:
        trigger - the WComponent that will fire the AJAX request on change
      • WAjaxControl

        public WAjaxControl​(AjaxTrigger trigger,
                            AjaxTarget target)
        Create a WAjaxControl with specified trigger and target components.
        Parameters:
        trigger - the WComponent that will fire the AJAX request on change
        target - the WComponent to be re-painted as a result of the AJAX request
      • WAjaxControl

        public WAjaxControl​(AjaxTrigger trigger,
                            AjaxTarget[] targets)
        Create a WAjaxControl with specified trigger component and an array of target components.
        Parameters:
        trigger - the WComponent that will fire the AJAX request on change
        targets - the WComponents to be re-painted in the AJAX response
      • WAjaxControl

        public WAjaxControl​(AjaxTrigger trigger,
                            List<? extends AjaxTarget> targets)
        Create a WAjaxControl with specified trigger component and a List of target components.
        Parameters:
        trigger - the WComponent that will fire the AJAX request on change
        targets - the WComponents to be re-painted in the AJAX responses
    • Method Detail

      • getTrigger

        public AjaxTrigger getTrigger()
        Get the component that will trigger the client to make the AJAX request.
        Returns:
        the AJAX trigger
      • addTargets

        public void addTargets​(AjaxTarget[] targets)
        Add an array of target components that should be targets for this AJAX request.
        Parameters:
        targets - the components to be repainted in the AJAX response
      • addTargets

        public void addTargets​(List<? extends AjaxTarget> targets)
        Add a list of target components that should be targets for this AJAX request.
        Parameters:
        targets - the components that will be repainted for the AJAX request
      • addTarget

        public void addTarget​(AjaxTarget target)
        Add a single target WComponent to this AJAX control.
        Parameters:
        target - a WComponent to be repainted
      • setLoadOnce

        public void setLoadOnce​(boolean loadOnce)
        Flag to indicate the the AJAX trigger should be fired once only.
        Parameters:
        loadOnce - if true the target AJAX trigger only once for each load of a page
      • isLoadOnce

        public boolean isLoadOnce()
        Returns:
        true if the trigger should be fired once only for each load of a page
      • setLoadCount

        public void setLoadCount​(int loadCount)
        Deprecated.
        Set whether the trigger may fire once or an unlimited number of times. Any value > 0 will result in a trigger which can only fire once per page. See #495.
        Parameters:
        loadCount - The trigger count for this AJAX control.
      • getLoadCount

        public int getLoadCount()
        Deprecated.
        1.2.0 use isLoadOnce().
        Get the indicator of whether a trigger may fire once or an unlimited number of times. If loadCount > 0 the WAjaxControl may only fire once per page load. See #495.
        Returns:
        1 if the trigger may only load once, otherwise -1
      • getTargets

        public List<AjaxTarget> getTargets()

        Get the target WComponents that will be repainted as a consequence of the AJAX request.

        When the AJAX request is triggered only the target component(s) will be re-painted. An empty list is returned if no targets have been defined.

        Returns:
        the target regions that are repainted in the AJAX response
      • getTargetsArray

        public WComponent[] getTargetsArray()

        Get the target WComponents as an array.

        When the AJAX request is triggered only the target component(s) will be re-painted. If no targets have been registered then an empty array is returned.

        Returns:
        an array of AJAX target components
      • getDelay

        public int getDelay()
        Get the delay period, in milliseconds, between the WAjaxControl being rendered in the view and it being automatically triggered. A WAjaxControl with a delay > 0 will result in a request being made without a change to any AjaxTrigger component.
        Returns:
        the delay after page load before AJAX control triggered
      • setDelay

        public void setDelay​(int delay)

        Set a delay period, in milliseconds, between the WAjaxControl being rendered in the view and it being automatically triggered. A WAjaxControl with a delay > 0 will result in a request being made without a change to any AjaxTrigger component.

        The use of a delay may be useful for setting up a trigger which polls for changes in a part of a UI. See WAjaxPollingRegion.

        If the trigger is part of a polling region (therefore it is itself updated and potentially re-triggers itself possibly many times) then the delay must not be less than 334.

        Parameters:
        delay - the delay after page load before AJAX control triggered
      • preparePaintComponent

        protected void preparePaintComponent​(Request request)
        Override preparePaintComponent in order to register the components for the current request.
        Overrides:
        preparePaintComponent in class AbstractWComponent
        Parameters:
        request - the request being responded to
      • toString

        public String toString()
        Description copied from class: AbstractWComponent
        Creates a String representation of this component; usually for debugging purposes.
        Overrides:
        toString in class AbstractWComponent
        Returns:
        a String representation of this component
      • getOrCreateComponentModel

        protected WAjaxControl.AjaxControlModel getOrCreateComponentModel()
        Description copied from class: AbstractWComponent
        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:
        an AjaxControlModel; for type safety only