This post explains how to launch a task using a URL within the User Interface Generator. It also explains how to load parameters that are passed in a query string in the URL into a command bean.
This feature relies on the user being logged in to work so is often used alongside a single-sign-on implementation of the application security as outlined in the previous blog post.
Launching a Task
To demonstrate how to launch a task I have created this very simple task and deployed it onto an application server with the URL http://localhost:9080/ExampleWeb.
The URL to launch the task will then be "http://localhost:9080/ExampleWeb/faces/TaskLauncher?taskName=Update Person".
A change was made in MDM 9.0.2 that meant that the task name used here had to be qualified by its model container. There is a note in the readme for MDM 9.0.2 which has been copied below for convenience:
Models may have multiple <
Qualified task names include the names of all of the element's owners, separated by a double colon "::". For example, a <
In another example, "Create Task" has been placed in the "User Tasks" package. This would result in a fully qualified name of "Example Model::User Tasks::Create Task".
To find the qualified name of a <
Existing command beans that create TaskLink objects must be manually migrated to use this new format, as must any URLs that use the Task Launcher function.
It is also possible to pass extra parameters into the URL, for instance if we want to launch the task and load a specific person based on their ID we could use the URL "http://localhost:9080/ExampleWeb/faces/TaskLauncher?taskName=Update Person&id=1234". The application that is generated is a regular JSF application so to get the parameter out you can use the standard JSF mechanism. In this example I changed the doExecute method of the "ViewPerson" command bean to contain:
String idParam = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id");
// Now find the person
int id = Integer.parseInt(idParam);
Person person = getPerson(id);
Where the getPerson method takes in an ID of a person and retrieves their record from the database.
Don't forget that the task could also be launched from the navigation menu as well as from a URL so you will need more null checking that the simple example includes! Also, if the URL points to a task that does not exist then the application will go to the error page stating that the TaskLauncher file cannot be found so it is important to make sure the URL is created correctly.