Possible AbstractAjaxBehavior Bug

View: New views
2 Messages — Rating Filter:   Alert me  

Possible AbstractAjaxBehavior Bug

by Hoover, William :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am using a behavior that is dynamically added/removed from a TextField
based upon another components state (in order to avoid extra round trips
to the server):

final AjaxFormComponentUpdatingBehavior afcub = ...
final TextField textField = new TextField("some-id", new Model()){
        protected final void onBeforeRender() {
                boolean hasBehavior = false;
                for (final IBehavior b : (List<IBehavior>)
component.getBehaviors()) {
                        if (b.equals(behavior)) {
                                hasBehavior = true;
                                break;
                        }
                }
                // is add flag is captured by another components
conditions to avoid server round-trips
                if (isAddFlag && !hasBehavior) {
                        add(afcub);
                } else if(!isAddFlag && hasBehavior) {
                        remove(afcub);
                }
                super.onBeforeRender();
        }
}

Using the code above I get an IllegalStateException when the
AjaxFormComponentUpdatingBehavior is added, then removed, and added
again (all based on user interaction of course). In AbstractAjaxBehavoir
there is a method that does a (component != null) check... shouldn't
that check be (component != null && !(component.equals(hostComponent)))
to avoid this type of scenario?

        public final void bind(final Component hostComponent)
        {
                if (hostComponent == null)
                {
                        throw new IllegalArgumentException("Argument
hostComponent must be not null");
                }

                if (component != null)
                {
                        throw new IllegalStateException("this kind of
handler cannot be attached to " +
                                "multiple components; it is already
attached to component " + component +
                                ", but component " + hostComponent + "
wants to be attached too");

                }

                component = hostComponent;

                // call the callback
                onBind();
        }


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Possible AbstractAjaxBehavior Bug

by igor.vaynberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i dont think the behavior has been designed with the adding/removing
in mind. feel free to open a jira issue for it. i think a much easier
way to do this is to always add it and override isenabled()

-igor

On Mon, Jul 7, 2008 at 10:35 AM, Hoover, William <whoover@...> wrote:

> I am using a behavior that is dynamically added/removed from a TextField
> based upon another components state (in order to avoid extra round trips
> to the server):
>
> final AjaxFormComponentUpdatingBehavior afcub = ...
> final TextField textField = new TextField("some-id", new Model()){
>        protected final void onBeforeRender() {
>                boolean hasBehavior = false;
>                for (final IBehavior b : (List<IBehavior>)
> component.getBehaviors()) {
>                        if (b.equals(behavior)) {
>                                hasBehavior = true;
>                                break;
>                        }
>                }
>                // is add flag is captured by another components
> conditions to avoid server round-trips
>                if (isAddFlag && !hasBehavior) {
>                        add(afcub);
>                } else if(!isAddFlag && hasBehavior) {
>                        remove(afcub);
>                }
>                super.onBeforeRender();
>        }
> }
>
> Using the code above I get an IllegalStateException when the
> AjaxFormComponentUpdatingBehavior is added, then removed, and added
> again (all based on user interaction of course). In AbstractAjaxBehavoir
> there is a method that does a (component != null) check... shouldn't
> that check be (component != null && !(component.equals(hostComponent)))
> to avoid this type of scenario?
>
>        public final void bind(final Component hostComponent)
>        {
>                if (hostComponent == null)
>                {
>                        throw new IllegalArgumentException("Argument
> hostComponent must be not null");
>                }
>
>                if (component != null)
>                {
>                        throw new IllegalStateException("this kind of
> handler cannot be attached to " +
>                                "multiple components; it is already
> attached to component " + component +
>                                ", but component " + hostComponent + "
> wants to be attached too");
>
>                }
>
>                component = hostComponent;
>
>                // call the callback
>                onBind();
>        }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...