[ 
https://issues.apache.org/jira/browse/WICKET-6711?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18062378#comment-18062378
 ] 

Johan Stuyts commented on WICKET-6711:
--------------------------------------

[~davesman] A bit late, but I just found behavior IDs because I was doing some 
Ajax things.

The way I see it is: the IDs do not matter in most cases, but in the case of 
Ajax on stateless pages, it is important in which order the IDs are assigned. 
If an Ajax request on a stateless page comes in, Wicket must be able to map the 
request parameters to the correct behaviors. That is why 
`AbstractDefaultAjaxBehavior` allocates an ID as soon as possible: it is 
undesirable that IDs are allocated based on a non-deterministic order of 
actions during the request cycle.

For behaviors that do not have to be found based on the contents of a request, 
the ID does not really matter. Allocating an ID early is useless in this case, 
so is skipped for stateless pages in `Behaviors`.

I do not know why allocating early for all behaviors if the page is stateful is 
useful. As the page is stateful, the IDs won't change between request, so I 
would assume the initial allocation order would not matter.

> Contradictory generating behavior id in AbstractDefaultAjaxBehavior#onBind 
> for stateless behaviors
> --------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-6711
>                 URL: https://issues.apache.org/jira/browse/WICKET-6711
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket-core
>    Affects Versions: 8.6.1
>            Reporter: David Rain
>            Priority: Major
>              Labels: ajax, behavior
>
> *Behavior* class says that behavior is not stateless if it is a request 
> listener:
> {code:java}
> public boolean getStatelessHint(Component component) {
>    if (this instanceof IRequestListener) {
>       // this behavior implements a callback interface, so it cannot be 
> stateless
>       return false;
>    }
>    return true;
> }
> {code}
> In *Behaviors* "util" class the stable ID is generated for NOT stateless 
> (i.e. stateful) behaviors:
> {code:java}
> private void internalAdd(final Behavior behavior) {
>     component.data_add(behavior);
>     if (behavior.getStatelessHint(component) == false) {
>             getBehaviorId(behavior);
>     }
> }
> {code}
> BUT in *AbstractDefaultAjaxBehavior*#onBind there is a contradictory piece of 
> code, that generates ID for stateless behaviors:
> {code:java}
> protected void onBind() {
>     final Component component = getComponent();
>     
>     component.setOutputMarkupId(true);
>     
>     if (getStatelessHint(component)) {
>             //generate behavior id
>             component.getBehaviorId(this);
>     }
> }
> {code}
> The AJAX behaviors are always IRequestListener so they are stateful by 
> default (unless the getStatelessHint is overridden).
> (?) It does not make sense to me... generate ID for stateful behaviors on the 
> one hand in Behaviors and on the other hand for stateless in 
> AbstractDefaultAjaxBehavior.
> (!) I suspect that this could be bug.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to