Navigation from a Principal Picker Dialog

I’m using the Principal Picker Dialog generated automatically by Desiger to route the task to another user.

I want the application to show the Inbox Result portlet after the user selects the principals in the Picker Dialog (clicking the Apply button provided by the dialog).

I tryied to implement a navigation rule in the faces-config.xml like this one below:

This is the view containing the Picker Dialog:
RespProblemHandlingTaskView/default.view

This is the action invoked by the Picker Dialog:
#RespProblemHandlingTaskViewDefaultviewView.assignToPrincipals}

This is the Inbox Result view:
/RespProblemHandlingInboxResults/default.view

without any result, after the user clicks the apply button the application is still in the view containing the task detail.

You can not use navigation rules to redirect from one portlet to another. In this case from TaskDetails portlet to Task Inbox results. Moreover. These portlets are located on the different pages in MWS.

Instead you need to fully redirect to inbox results page from your assignUsers action. I believe an url of the inbox results page is passed to details portlet as “returnUrl” preference, so you can redirect using this code:

getFacesContext().getExternalContext().redirect(returnUrl).

Also please take a look at the implementation of complete() method in the TaskDetails page bean - it does redirect to inbox upon task completion.

Alex

I tryied to use redirect with the following code:

String url = getRespProblemHandlingTaskView().getFinishUrl();
if (url != null && url.length() > 0) {
getFacesContext().getExternalContext().redirect(url);
}

But I got the following exception:
java.lang.IllegalStateException: [POP.007.0060] The sendRedirect method can not be invoked after any of the following methods of the ActionResponse interface has been called: setPortletMode, setWindowState, setRenderParameter, setRenderParameters

The same code works OK when attached to other actions for controls like command buttons. It seems to me that something works different for the Principal Picker Dialog

BTW, where can I get more information on these topics ?

Thanks again
Edgardo Burin

The apply button in the Principal Picker Dialog is an “Async Command Button” control so you can not redirect from it’s action handler. Async command controls use AJAX requests so they can not directly change the page you are viewing.

There are a few ways to solve the use case. Probably the easiest solution would be to place a script control inside the panel that gets refreshed by the apply action. The script control would do a client-side redirect to the target.

For example, add this to your page bean java code:

	//this field holds a script
	private String customScriptCode = null;
	
	/**
	 * @return the customScriptCode
	 */
	public String getCustomScriptCode() {
		return customScriptCode;
	}

	/**
	 * @param customScriptCode the customScriptCode to set
	 */
	public void setCustomScriptCode(String customScriptCode) {
		this.customScriptCode = customScriptCode;
	}
	
	/* (non-Javadoc)
	 * @see com.webmethods.caf.faces.bean.BaseViewBean#afterRenderResponse()
	 */
	@Override
	protected void afterRenderResponse() {
		super.afterRenderResponse();
		
		//clear out the custom script so it doesn't get rendered on subsequent render requests
		setCustomScriptCode(null);
	}
	
	public String yourActionHandler() {
		String targetURL = "http://your_url_here";
		String scriptCode = MessageFormat.format("window.location.href=''{0}''", targetURL);
		setCustomScriptCode(scriptCode);
		return OUTCOME_OK;
	}

…and then place a ‘Script Block’ control inside the panel that gets refreshed that is bound to the custom script code field.

Another, maybe simpler, technique for custom javascript code after an async command completes is discussed in this thread: Javascript function callback after async command call

It’ true that the “Apply” button is asynchronous, the problem is that the id is generated by Designer and not documented :(. Nevertheless, after some investigation checking the source page in the browser, I found that the relative id assigned to the control is “applyButton”.

I tested inserting a script block in the page containing a value:

CAF.model(’#{activePageBean.clientIds[‘applyButton’]}’).addActionCompleteListener(
function (commandID) { alert(commandID); }
);

and it works.
Thanks
Edgardo