Strange behavior on views

Hello all,

I’m having a problem on my CAF project.
I have this CAF project with a portlet named App. In this portlet I have five views (Default, Menu, SearchPolicy, InsertPolicy and BookTrip)

The navigation order is Default view, then you click in a button and go to Menu view, then you can choose which page to go (SearchPolicy, InsertPolicy and BookTrip).

On this three pages I have a async button that search/insert data on a database, but when I click, the action goes to database but the browser returns to Default view.

Why this is happening?


Can you confirm that you don’t have a navigation-rule defined in your faces-config.xml file that would do that navigation?

If there is no navigation-rule involved, then can you confirm that your action handler method returns null to signal that you want to stay on the same view?

JSF version 2.x introduced an “implicit navigation” concept that reduces the typical navigation-related code in the faces-config.xml file. Essentially, if no matching navigation case is found after checking all available navigation rules that were declared in the faces-config.xml file, the navigation handler checks to see whether the action outcome corresponds to a view id. If a view matching the action outcome is found, an implicit navigation to the matching view occurs.

So the end result is that your action handler can navigate directly to another page without you having to mess with any navigation-rule elements in the faces-config.xml file.

For example, these two action handler methods demonstrate how an action handler can affect the implicit navigation:

public String doActionThatStaysOnSamePage() {
    //TODO: do your action logic here

    //return null to stay on the same page
    return null;

public String doActionThatSwitchesToPage2() {
    //TODO: do your action logic here

    //return the viewId of the page to switch to
    return "/yourportlet/page2.view";

CAF upgraded to JavaServer Faces (JSF) version 2.2 a while back. With JSF version 2.x or later, if you haven’t defined an explicit in faces-config.xml for the outcome string, then the outcome string returned from an action handler method is expected to be null or the viewId of the page to switch to. You would want to return null if you want to stay on the same page, or the target viewId if you want the action to switch to a different view. Please see section 7.4.2 of the JSF 2.x specification if you want more details about the default navigation handler algorithm.

1 Like

Hello Eric Norman,
I’m not using navigation rule for these actions, but I saw that the actions return was setted OUTCOME_OK, so I changed to null and now these actions didn’t change the view.

Thanks for help!!