Quick update... I logged the following spec issue to track this:
https://javaserverfaces-spec-public.dev.java.net/issues/show_bug.cgi?id=747
Andy
Andy Schwartz wrote:
Gang -
One of our unit tests here at Oracle tripped up over a small change in
behavior between JSF 1.2 and JSF 2. The unit test contains an action
method that returns an empty string, eg:
<h:commandButton action="#{foo.doSomething}"/>
public String doSomthing()
{
// Do something here
return "";
}
When running against JSF 1.2, the empty string outcome would result in
the test case remaining on the same page, as there is no navigation
case that matches this outcome. In JSF2, implicit navigation kicks in.
In particular, the following statement from section 7.4.2 is applied:
> If viewIdToTest does not begin with “/”, take the current viewId and
> look for the last “/”. If not found, prepend a “/” and continue.
> Otherwise remove all characters in viewId after, but not including,
> “/”, then append viewIdToTest and let the result be viewIdToTest.
In our case, we have the following values:
- Current viewId: "region/refresh".
- viewIdToTest: ""
The resulting view id after applying the above logic is "region/".
This ends up being treated as an implicit view id. In our particular
test case, there is no view associated with this view id. Instead of
remaining on the same page, we now attempt to navigate to a view that
does not exist.
Our test case made the assumption that returning the empty string from
the outcome would result in the same behavior as returning null. This
was true in JSF 1.2, but no longer appears to be true in JSF2. We have
tweaked this unit test to return null so that our tests are now
passing, but I wanted to follow up to find out whether this small
difference in behavior between "" and null outcomes is intentional. It
seems to me that these should behave the same. It would be easy enough
for us to add a sentence to the spec that states that empty string
outcomes should not be treated as implicit view ids. Does anyone here
know of a reason why we shouldn't spec this?
FWIW, my feeling is that, while returning null is a reasonable
workaround, there is no way that our unit test is not the only code
out there that is returning empty action outcomes and expecting to
stay on the same page. I would like to see this behavior preserved not
so that we can revert our unit test to its previous behavior (I am
fine with our fix), but because the current behavior may break other
users as they upgrade to JSF2.
Thoughts?
Andy