-
Notifications
You must be signed in to change notification settings - Fork 18
Description
WAjaxControl has a private member int loadCount and relevant public accessors. The schema for WAjaxControl/ui:ajaxTrigger specifies an attribute @allowedUses which outputs the value of this property if it is greater than 0. Support for loadCount is only partially implemented in both sides of WComponents.
Limitation of the number of times a WAjaxTrigger is processed In addition @allowedUses/loadCount have never been implemented in WComponents Java or client code to enforce any numbers other than <= 0 (unlimited) or 1 (single use). The value of loadCount and any previous invocations of the WAjaxControl's trigger component's actionOnChange Action are not tested during the action phase (and maybe cannot be adequately tested at an abstract level). Any value greater than 0 is deemed within the client side code to indicate single use.
Proposal
I propose the following to remove this misrepresentation:
- remove the implied support for a WAjaxControl that can be fired more than once but no more than
ntimes by removing the private memberint loadCountand replacing it with a more appropriate token (perhapsboolean loadOnceso we can retain the accessorssetLoadOnceandisLoadOnce); - deprecate
setLoadCount(int)in favour ofsetLoadOnce(boolean)andint getLoadCount()in favour ofboolean isLoadOnce(); - temporarily update
setLoadCount(int)such that when int <= 0 callsetLoadOnce(false)otherwise callsetLoadOnce(true); - temporarily update
getLoadCount()to return -1 ifisLoadOnce()returns false otherwise return 1; - rename attribute
@allowedUsesto a more appropriate token (perhaps@singlebut suggestions are welcome); - update the renderer to check
isLoadOnce()as the test for@allowedUses(therefore its renamed counterpart if we do that).
Alternative
We could support loadCount and therefore it would cease to be a misrepresentation in the API. This would entail at the very least:
- client code providing full support for
@allowedUsesand de-registering an AJAX trigger after this number of invocations; - the Java API being enhanced to provide a means for a trigger's
@allowedUsesto be updated/reset in the client if a WAjaxControl/ui:ajaxTrigger is updated/replaced in an AJAX response so that the consuming application is able to decide if the load count is reset or inherited from the previous trigger lifecycle; - The action phase for WComponents provides a default implementation which keeps a count of the number of times a WAjaxControl has been invoked and stops actioning when loadCount is reached;
- A default implementation is provided to re-populate target components in their previous state when the condition in 3 above is reached preventing further action (this is a belt-and-braces in case the count goes wrong in the client code).
I am not keen on taking this approach because we have never had a reasonable use-case where a particular WAjaxControl's trigger is required to be fired more than once but no more than n times. If this is ever required then the WAjaxControl/ui:ajaxTrigger could be set to be single use and then replaced in the subsequent target load as currently any ui:ajaxTrigger loaded will replace the ajax trigger in the trigger manager.
@jonathanaustin, @ricksbrown opinions?