* Parameter action=close is set by js function closeDialog()
* for AJAX request simulating this action.
*/
String action = (String)context.getExternalContext().getRequestParameterMap().get("action");
DialogContext dcontext = DialogContextManager.getInstance(context).getContext(dialogId);
String posReferenceId = (String)context.getExternalContext().getRequestParameterMap().get("posReferenceId");
((UIDialogWindow)component).setPosExternalReferenceId(posReferenceId);
ActionSource actionSource = (ActionSource) component;
/*
* Specific navigation for open/close dialogs
* includes prefixes to outcomes. We need to
* intercept computed outcome to extract the prefix
* and provide JSF with outcome stripped of it.
*/
MethodBinding binding = actionSource.getAction();
if(!(binding instanceof DialogMethodBinding)) {
actionSource.setAction(new DialogMethodBinding(binding, (ActionPrefixHolder)component));
}
DialogOpenEvent dialogEvent = new DialogOpenEvent(component);
if(!"close".equals(action) && !"closeall".equals(action)) {
/*
* Button has been pressed.
* Child dialog is to be open.
* We need to send a standard ActionEvent to
* let JSF to pass all the lifecycle up to
* the end of invoke application phase where
* we will interfere and change the navigation logic.
*/
DialogContext parentContext = DialogContextManager.getInstance(context).getActiveContext();
DialogContextManager.getInstance(context).setActiveRequest(dialogId);
if(parentContext != null && parentContext != dcontext) parentContext.addChildContext(dcontext);
dcontext.setLocked(false);
Object type = component.getAttributes().get("type");
if (null == type || ! "reset".equalsIgnoreCase((String)type) ) {
/// String mode = ((UIDialogAction)component).getMode();
ActionEvent event;
event = new ActionEvent(component);
component.queueEvent(event);
if(component instanceof ViewIdHolder) {
component.queueEvent( new AjaxEvent(component));
// ((UIDialogWindow)component).initViewId();
// AjaxContext.getCurrentInstance(context).setViewIdHolder((ViewIdHolder)component);
// return;
}
} else {
component.queueEvent( new AjaxEvent(component));
}
} else {
/*
* Child dialog has just been closed.
* It simulates action of this component
* by AJAX request from js function closeDialog()
* Parameter 'targetViewId' is id of view
* that would be shown in dialog window if it had not
* to be closed. Now it is saved in event
* to be substituted for view root of this window.
*/
String targetViewId = (String)context.getExternalContext().getRequestParameterMap().get("targetViewId");
if(targetViewId != null) {
dialogEvent.setSourceViewId(targetViewId);
}
DialogContext parentContext = dcontext.getParentContext();
dcontext.deactivate();
if(parentContext != null) {
DialogContextManager.getInstance(context).setActiveRequest(parentContext.getDialogId());
} else if("closeall".equals(action)) {
DialogContextManager.getInstance(context).setActiveRequest(null);
} else {
DialogContextManager.getInstance(context).setActiveRequest(null);
}