0

I'm modernizing a JSF web application I took over from someone who retired and is not available for questions.

Current job is to simplify a h:dataTable. Each record has a commandLink to go to the corresponding details page.

Old version: action method openDetail(), determined the selected record by binding of the dataTable and looping trough the records to get the row.

New version: action method is now openDetail(Long id) and of course I added the parameter to the command link as well.

My action method is called with the correct parameter, I verified this by adding some log output. But the navigation-rule is not effective anymore. Although the action method returns the correct outcome, it stays on the page with the table.

The navigation-rule in faces-config.xml looks like this:

  <navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
      <from-action>#{myBean.openDetail}</from-action>
      <from-outcome>success</from-outcome>
      <to-view-id>/mysks/detail.xhtml</to-view-id>
      <redirect/>
    </navigation-case>
  </navigation-rule>

Do I need to adapt the navigation-rule ? Does JSF make a difference for overloaded action methods ?

1 Answers1

1

The <from-action> has to exactly match the literal string as defined in action attribute.

So if it currently looks like this:

<h:commandButton ... action="#{myBean.openDetail(detail.id)}">`

Then the <from-action> must be exactly that literal string:

<from-action>#{myBean.openDetail(detail.id)}</from-action>

However, the whole navigation rule system has not proven to be really useful in JSF and has become de-facto deprecated since release of JSF 2.0 in 2009 which introduced the new support for immediately returning the <to-view-id> as return value, called "implicit navigation". Essentially, XML-based navigation rules are really a "leftover" of the jurassic JSF 1.x and you'd best just get rid of them.

So if you simply adjust the openDetail() method from

public String openDetail(Long id) {
    // ...
    return "success";
}

to

public String openDetail(Long id) {
    // ...
    return "/mysks/detail.xhtml?faces-redirect=true";
}

then you can get rid of the entire <navigation-rule> bloat from the faces-config.xml.

See also:

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • This web application is over 10 years old, and it was originally implemented in JSF 1.1. I hope I'll get approved some budget for modernizing the navigation as well. On the other hand ... I liked the concept of a centralized navigation configuration as opposed to the "implicit navigation" I just learned about, where the to-view-id's are scattered across the whole web app. Makes it harder to maintain IMO. – user9964388 Feb 24 '21 at 15:02