Sunday, March 24, 2013

ADF - Restrict Navigation Based on a Condition

There is a supplier table. If the status of the supplier row is DRAFT, then only will the user be able to see the details of it by clicking on the commandlink.

In this case, set the Action as null, because here we will be setting the navigation manually.

Here we have fetched the value of Status using the propertyListener
From: #{row.Status}
To: #{requestScope.Status}
Type: action

Created a parameter p_status

This is the method that we have defined in the ActionListener property of the commandlink:

    public void moveToDetailPageBasedOnStatus(ActionEvent actionEvent) {
        // Add event code here...
        DCBindingContainer bc = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        Map map = bc.getParametersMap();
        String status = ((DCParameter)map.get("p_status")).getValue().toString();
        System.out.println("status: " + status);
        if (status.equals("DRAFT")) {
            FacesContext context = FacesContext.getCurrentInstance();
            context.getApplication().getNavigationHandler().handleNavigation(context, null, "create");
        } else {
            FacesContext context = FacesContext.getCurrentInstance();
            FacesMessage message =
                new FacesMessage(FacesMessage.SEVERITY_INFO, "", "User can see the details of an Issue in DRAFT Status only.");
            context.addMessage(null, message);
This is the diagram of the taskflow.
Just remember one point: ActionListener is executed before Action event.

No comments:

Post a Comment