Thanks for your help in advance.
I have a view (jspx page and backing bean) that is used in two different use
cases. The view (viewA) is navigated to when the user clicks on either of two
Menu items - call them MenuItem A and MenuItem B. If MenuItem A was pressed,
viewA is displayed and when the user is done, viewB is displayed next.
However, if MenuItem B is pressed, viewA is displayed and then viewC is
displayed next.
Currently, I have one jspx page and a single backing bean for viewA and both
MenuItems navigate to the same from-outcome. My first question is how can I
determine which MenuItem was clicked in the backing bean? One thought is to
have two different from-outcomes and map them to two to-view-ids that are
differentiated by a query parameter. The query parameter would then be checked
in a scriptlet (Yuck.) in the page that could put an attribute in some
scope(session or request) that indicated which menuItem was pressed. The other
idea that I have is to copy the jspx page to another name and then do a global
search and replace of the references to the backing bean and change it to a
slightly different name (ie. backingB). I could then refactor my backing bean
into parent and child classes where the parent class would handle one of the
uses cases and the child would handle the other use case. The child backing
class would have a few methods that would have some additional logic and then
invoke the parents method.
The downside I see to the firsst approach is that it involves the use of a
scriptlet in the jspx file and conditional logic that checks for the presence
of a session or request attribute in the backing bean.
The disandvantage of the second approache is that I would then need to
maintain two jspx pages that are identical except for the backingBean names in
the JSF EL expressions. I don't see that having the two backing beans as much
as a problem because it alleviates having a lot of conditional logic in the
bean (ie.
String flag = (String) request.getSession().getAttribute("menuItemA_flag");
if (flag != null) {
// handle menuItemA case
} else {
// handle menuItemB case
}
// more common code
....
if (flag != null) {
// handle menuItemA case
} else {
// handle menuItemB case
}
If anyone else has faced a similar problem, I would be interested in knowing
how you handled it.
Thanks,
Richard
--