Hi,

i like to do a bit of refactor on the AbstractDefaultAjaxBehavior class
because i find the api very messy and what to implement or what to call is
very hard to understand

First what we have now:


AbstractAjaxBehavior had 2 methods:
getCallBackUrl() and  getCallBackUrl(boolean)

thats all fine, now i move to the subclass

AbstractDefaultAjaxBehavior does have a getCallbackScript() and
getCallbackScript(boolean)
which is sort of the same thing as getCallBackUrl() but they encapsulate it
until now its still good but.

besides that we have in AbstractDefaultAjaxBehavior:

protected CharSequence getCallbackScript(final CharSequence partialCall,
final CharSequence onSuccessScript, final CharSequence onFailureScript)
and
protected CharSequence getCallbackScript(final CharSequence
partialCall,final CharSequence onSuccessScript, final CharSequence
onFailureScript,final CharSequence precondition)


and thats a bit funny,what does have the boolean one in common with the
other 2??
and what method do i have to implement to get a precondition in the right
place?
what do i need to call then afterwards.

i think this would be much better:

this stays the same:
protected CharSequence getCallbackScript()
{
     return getCallbackScript(false);
}

this:
protected CharSequence getCallbackScript(boolean onlyTargetActivePage)
{
       return getCallbackScript("wicketAjaxGet('"+
getCallbackUrl(onlyTargetActivePage) + "'", null, null);
}

should become:
protected CharSequence getCallbackScript(boolean onlyTargetActivePage)
{
return getCallbackScript("wicketAjaxGet('"+
getCallbackUrl(onlyTargetActivePage) + "'", getSuccessScript(),
getFailureScript(),getPreconditonScript());
}

 This one can be removed then:
protected CharSequence getCallbackScript(final CharSequence
partialCall,final CharSequence onSuccessScript, final CharSequence
onFailureScript)

 And this one can (doesn't have to be but i guess api wise it is a bit
better) be made final
protected CharSequence getCallbackScript(final CharSequence
partialCall,final CharSequence onSuccessScript, final CharSequence
onFailureScript, final CharSequence precondition)
and i would like to rename it to generateCallBackScript(xxxx)
because it is not really in line with the 2 other once (no param and boolean
param)

and we add 4 extra methods:
getSuccessScript(), getFailureScript(),getPreconditonScript()
that by default just return null;

Then if you want a successscript or precondition script you just implement
those  getters.

johan

Reply via email to