success

Description: Defines the success action for an AJAX request handler.

  • JavaScript block execution
  • Partial stage refresh (from AJAX response, or partial refresh by re-rendering an inner stage (dif:component)
  • Redirect to a stage or URL (on new window if desired)
  • Rendering of HTML templates in dynamic rich JavaScript Dialogs
  • Load mask for post action execution time

JavaDoc: Click here

Body content: JSP content.

Attributes:

Name Description Data type Required Default value
executeJavaScript indicates that the content is to be treated as JavaScript to execute boolean No false
loadingMessage the loading message text String No if showLoadingMessage is true, "Loading..."
newWindow Open stage or URL in a new window Boolean No false
refreshComponentID DOM element ID to update String No -
showLoadingMessage show loading message while the action executes boolean No false
stageID Stage to redirect to String No -
stageParameters Stage parameters String No -
targetElementID DOM element ID to update String No -
url URL to redirect to String No -

Variables: The TAG can declare:

  • JavaScript content, if the parameter executeJavaScript is selected, or...
  • Plain HTML, for the cases of simples messages (default) or targetElementID

For JavaScript a variable is available. Named "response.result". This variable is a JavaScript object that contains the representation of the Java Object returned by the @OnAjax stage method, already converted from the JSON response.

If the result is a HTML template, that the equivalent "$result" substitution variable is available.

Examples:

#1: AJAX request with "Loading..." message.
Will report errors to the screen in a JavaScript Dialog window, or redirect to the next stage.

<dif:document>
    <dif:ajaxRequest ajaxEvent="ajaxEventName" bindTo="triggerelementID:click" showCallMask="true">
        <dif:success refreshComponentID="test" stageParameters="param=123" />
        <dif:failure>The request failed with the following error:<br/>$result</dif:failure>
    </dif:ajaxRequest>
</dif:document>

#2: AJAX request with a custom "Call in progress..." message.
Will report errors a specific div on the page, or refresh a partial page section (inner stage) on success. Since the success stage refresh is slow, we will show a message while it happens.

<dif:document>
    <dif:component stageID="stageThatDisplaysSomeDynamicData" />
    <div id="errorArea" style="display: none;"/>
    <dif:ajaxRequest ajaxEvent="ajaxEventName" bindTo="triggerelementID:click" serverCallMessage="Call in progress...">
        <dif:success refreshComponentID="stageThatDisplaysSomeDynamicData" stageParameters="afterUpdate=true"
                     loadingMessage="Updating data..." />
        <dif:failure targetElementID="errorArea">
            The request failed with the following error:<br/>$result
        </dif:failure>
    </dif:ajaxRequest>
</dif:document>

#3: AJAX request with no activity message (silent mode).
Will parse all error if existent, or redirect to a specific site in success.

<dif:document>
    <dif:component stageID="stageThatDisplaysSomeDynamicData" />
    <dif:ajaxRequest ajaxEvent="ajaxEventName" bindTo="triggerelementID:click" serverCallMessage="Call in progress...">
        <dif:success executeJavaScript="true">
            alert("Here we can insert whatever JS code we wish...");
            alert("The AJAX results are here: " + result);
        </dif:success>
        <dif:failure targetElementID="errorArea">
            The request failed with the following error:<br/>$result
        </dif:failure>
    </dif:ajaxRequest>
</dif:document>

See also:

Back to tag reference