use of com.github.bordertech.wcomponents.AjaxOperation in project wcomponents by BorderTech.
the class AjaxInterceptor method serviceRequest.
/**
* {@inheritDoc}
*/
@Override
public void serviceRequest(final Request request) {
String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
AjaxOperation ajaxOperation = AjaxHelper.getCurrentOperation();
if (ajaxOperation == null) {
throw new IllegalStateException("No AJAX operation available for trigger " + triggerId + ".");
}
ComponentWithContext triggerWithContext = AjaxHelper.getCurrentTriggerAndContext();
if (triggerWithContext == null) {
throw new IllegalStateException("No component/context available for AJAX trigger " + triggerId + ".");
}
UIContext uic = UIContextHolder.getCurrent();
// Reset the focus for this new request.
uic.setFocussed(null, null);
// We've hit the action phase, so we do want focus on this app.
uic.setFocusRequired(true);
// Process trigger only
if (isProcessTriggerOnly(triggerWithContext, ajaxOperation)) {
// Get user context
UIContext tuic = triggerWithContext.getContext();
UIContextHolder.pushContext(tuic);
try {
WComponent trigger = triggerWithContext.getComponent();
trigger.serviceRequest(request);
// Manually invoke laters as the InvokeLaters in the service request is not run due to the trigger
// having a "parent"
tuic.doInvokeLaters();
} finally {
UIContextHolder.popContext();
}
} else if ("GET".equals(request.getMethod())) {
// GET only supports the above scenarios
throw new IllegalStateException("GET is not supported for the AJAX trigger " + triggerId + ".");
} else {
// service the request
super.serviceRequest(request);
}
}
use of com.github.bordertech.wcomponents.AjaxOperation in project wcomponents by BorderTech.
the class AjaxPageShellInterceptor method paint.
/**
* Paints the targeted ajax regions. The format of the response is an agreement between the server and the client
* side handling our AJAX response.
*
* @param renderContext the renderContext to send the output to.
*/
@Override
public void paint(final RenderContext renderContext) {
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
XmlStringBuilder xml = webRenderContext.getWriter();
AjaxOperation operation = AjaxHelper.getCurrentOperation();
if (operation == null) {
// the request attribute that we place in the ui contenxt in the action phase can't be null
throw new SystemException("Can't paint AJAX response. Couldn't find the expected reference to the AjaxOperation.");
}
UIContext uic = UIContextHolder.getCurrent();
String focusId = uic.getFocussedId();
xml.append(XMLUtil.getXMLDeclarationWithThemeXslt(uic));
xml.appendTagOpen("ui:ajaxresponse");
xml.append(XMLUtil.STANDARD_NAMESPACES);
xml.appendOptionalAttribute("defaultFocusId", uic.isFocusRequired() && !Util.empty(focusId), focusId);
xml.appendClose();
getBackingComponent().paint(renderContext);
xml.appendEndTag("ui:ajaxresponse");
}
use of com.github.bordertech.wcomponents.AjaxOperation in project wcomponents by BorderTech.
the class AjaxSetupInterceptor method serviceRequest.
/**
* Setup the AJAX operation details.
*
* @param request the request being serviced.
*/
@Override
public void serviceRequest(final Request request) {
// Get trigger id
String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
if (triggerId == null) {
throw new SystemException("No AJAX trigger id to on request");
}
// Find the Component for this trigger
ComponentWithContext trigger = WebUtilities.getComponentById(triggerId, true);
if (trigger == null) {
throw new SystemException("No component found for AJAX trigger " + triggerId + ".");
}
WComponent triggerComponent = trigger.getComponent();
// Check for an internal AJAX request (if client has flagged it as internal)
boolean internal = request.getParameter(WServlet.AJAX_TRIGGER_INTERNAL_PARAM_NAME) != null;
AjaxOperation ajaxOperation = null;
if (internal) {
if (!(triggerComponent instanceof AjaxInternalTrigger)) {
throw new SystemException("AJAX trigger [" + triggerId + "] does not support internal actions.");
}
// Create internal operation
ajaxOperation = new AjaxOperation(triggerId);
} else {
// Check for a registered AJAX operation
ajaxOperation = AjaxHelper.getAjaxOperation(triggerId);
// TODO This is only required until all components start using the Internal param flag
if (ajaxOperation != null && "GET".equals(request.getMethod()) && triggerComponent instanceof AjaxInternalTrigger) {
// Create internal operation
ajaxOperation = new AjaxOperation(triggerId);
}
}
// If no operation registered, check if the trigger supports internal AJAX then assume it is an Internal Action
if (ajaxOperation == null && trigger.getComponent() instanceof AjaxInternalTrigger) {
// Create internal operation
ajaxOperation = new AjaxOperation(triggerId);
}
// No Valid operation
if (ajaxOperation == null) {
throw new SystemException("No AJAX operation has been registered for trigger " + triggerId + ".");
}
// Set current operation
AjaxHelper.setCurrentOperationDetails(ajaxOperation, trigger);
// Process Service Request
super.serviceRequest(request);
}
Aggregations