Class Behavior

    • Constructor Detail

      • Behavior

        public Behavior()
        Constructor
    • Method Detail

      • beforeRender

        public void beforeRender​(Component component)
        Called when a component is about to render.
        Parameters:
        component - the component that has this behavior coupled
      • afterRender

        public void afterRender​(Component component)
        Called when a component that has this behavior coupled was rendered.
        Parameters:
        component - the component that has this behavior coupled
      • bind

        public void bind​(Component component)
        Bind this handler to the given component. This method is called by the host component immediately after this behavior is added to it. This method is useful if you need to do initialization based on the component it is attached and you can't wait to do it at render time. Keep in mind that if you decide to keep a reference to the host component, it is not thread safe anymore, and should thus only be used in situations where you do not reuse the behavior for multiple components.
        Parameters:
        component - the component to bind to
      • unbind

        public void unbind​(Component component)
        Notifies the behavior it is removed from the specified component
        Parameters:
        component - the component this behavior is unbound from
      • detach

        public void detach​(Component component)
        Allows the behavior to detach any state it has attached during request processing.
        Parameters:
        component - the component that initiates the detachment of this behavior
      • getStatelessHint

        public boolean getStatelessHint​(Component component)
        This method returns false if the behavior generates a callback url (for example ajax behaviors)
        Parameters:
        component - the component that has this behavior coupled.
        Returns:
        boolean true or false.
      • isEnabled

        public boolean isEnabled​(Component component)
        Called when a components is rendering and wants to render this behavior. If false is returned this behavior will be ignored.
        Parameters:
        component - the component that has this behavior coupled
        Returns:
        true if this behavior must be executed/rendered
      • onComponentTag

        public void onComponentTag​(Component component,
                                   ComponentTag tag)
        Called any time a component that has this behavior registered is rendering the component tag.
        Parameters:
        component - the component that renders this tag currently
        tag - the tag that is rendered
      • isTemporary

        public boolean isTemporary​(Component component)
        Specifies whether or not this behavior is temporary. Temporary behaviors are removed at the end of request and never reattached. Such behaviors are useful for modifying component rendering only when it renders next. Usecases include javascript effects, initial clientside dom setup, etc.
        Parameters:
        component -
        Returns:
        true if this behavior is temporary
      • canCallListener

        public boolean canCallListener​(Component component)
        Checks whether or not an IRequestListener can be invoked on this behavior. For further information please read the javadoc on Component.canCallListener(), this method has the same semantics. WARNING: Read the javadoc of Component.canCallListener() for important security-related information.
        Parameters:
        component - component this behavior is attached to
        Returns:
        true iff the listener method can be invoked
      • onConfigure

        public void onConfigure​(Component component)
        Called immediately after the onConfigure method in a component. Since this is before the rendering cycle has begun, the behavior can modify the configuration of the component (i.e. setVisible(false))
        Parameters:
        component - the component being configured
      • onRemove

        public void onRemove​(Component component)
        Called to notify that the component is being removed from its parent
        Parameters:
        component - the removed component
      • onTag

        public static Behavior onTag​(org.danekja.java.util.function.serializable.SerializableBiConsumer<Component,​ComponentTag> onTagConsumer)
        Creates a Behavior that uses the given SerializableConsumer consumer to do something with the component's tag.

        Usage:
        component.add(onTag(tag -> tag.put(key, value)));

        Parameters:
        onTagConsumer - the SerializableConsumer that accepts the ComponentTag
        Returns:
        The created behavior
      • onAttribute

        public static Behavior onAttribute​(String name,
                                           org.danekja.java.util.function.serializable.SerializableFunction<String,​CharSequence> onAttribute)
        Creates a Behavior that uses the given SerializableFunction function to do something with a component's attribute.

        Usage:
        component.add(onAttribute("class", currentValue -> condition(currentValue) ? "positive" : "negative"));

        Parameters:
        name - the name of the attribute to manipulate
        onAttribute - the SerializableFunction that accepts the old value of the attribute and returns a new value
        Returns:
        The created behavior