Madhav Bhargava wrote:
Thanks Mike,
So what i understand is that if only <from-action> is given, then
irrespective of the outcome the control will go to the view id
specified. For instance the folllowing rule is define din the faces
config file:
<navigation-rule>
<from-view-id>/bingo.jsp</from-view-id>
<navigation-case>
<from-action>#{sombean.someAction}</from-action>
<to-view-id>/tringo.jsp</to-view-id>
</navigation-case>
</navigation-rule>
Does the above rule mean that if someAction method is executed then
irrespective of the outcome the control will always go to tringo.jsp? If
my interpretation is correct then can you think of any place where this
might be used?
Yes, I think your description is correct.
And yes it does seem rather pointless. I don't think from-action is
really expected to be used alone; instead (from-action, from-outcome)
can be used as a pair (or from-view-id, from-action, from-outcome), as
you describe below.
Now consider a second example:
<navigation-rule>
<from-view-id>/bingo.jsp</from-view-id>
<navigation-case>
<from-action>#{sombean.someAction}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/tringo.jsp</to-view-id>
</navigation-case>
</navigation-rule>
Does it mean that only if the output after executing someAction is
success only then the control will go to tringo.jsp?
If that is the case then why not just give the <from-outcome>, why is
the combination of both the tags is required?
So that the same view can have a different button bound to
"#{somebean.otherAction}" and the return strings from those methods can
be configured independently.
The methods someAction and otherAction therefore do not have to be
written with knowledge of what navigation strings the other method
returns. I guess this could be useful when there are potentially many
different actions in a single view, or where the actions point to
different managed beans.
However it makes things fragile IMO. Changing the action expression (eg
changing the name of the method) means changing the navigation config
which doesn't seem nice to me. I think (from-view-id, from-outcome) is
the best combination to use in most cases. Yes it requires a little more
coordination between the action methods to ensure that their return
values are consistent but as from-view-id is used the set of actions to
coordinate is reasonably small.
Consider a third case:
<navigation-rule>
<from-view-id>/bingo.jsp</from-view-id>
<navigation-case>
<from-action>#{sombean.someAction}</from-action>
<to-view-id>/tringo.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>success</from-action>
<to-view-id>/tringo123.jsp</to-view-id>
</navigation-case>
</navigation-rule>
Now if someAction method is executed and the outcome is success then
where will the control go? Will it go to tringo.jsp as defined by the
first navigation-case or will it go to tringo123.jsp as defined in the
second navigation case as both the cases are satisfied?
Don't know. I guess the spec will say.
Cheers,
Simon