1
votes

I have a scenario where I have to invoke another bean and registered bean attributes before rendering the JSF page as JSF page have reference to bean attributes for rendering response.

I am looking for best option to implement such scenario. I tried to represent required scenario in form of pseudo-code for better understanding.

Page A --> have button "View Detail" bind with BeanOne.getDetail() -- Scope is session.

BeanOne.getDetail()

process the request - call the backend method to get detail - if (type == XYZ) then invoke BeanTwo.getTypeXYZ() and redirect as per navigation rule defined for BeanTwo.getTypeXYZ() - else if (type == RST) then invoke BeanThree.getTypeRST() and redirect as per navigation rule defined for BeanThree.getTypeRST()

BeanTwo.getTypeXYZ()

  • process the request
  • call the backend method to get detail
  • set this.attributeB = value returned from backend method.
  • navigate to Page B

BeanTwo.getTypeRST()

  • process the request
  • call the backend method to get detail
  • set this.attributeC = value returned from backend method.
  • navigate to Page C

Something like having bean method name in navigation rule

<navigation-rule>
<from-view-id>Page A</from-view-id>
<navigation-case>
<from-action>#{beanOne.getDetail}</from-action>
<from-outcome>xyz</from-outcome>
<to-view-id>#{beanTwo.getTypeXYZ}</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{beanOne.getDetail}</from-action>
<from-outcome>rst</from-outcome>
<to-view-id>#{beanTwo.getTypeRST}</to-view-id>
</navigation-case>
</navigation-rule>

1

1 Answers

0
votes

Did you try using navication-rule in faces-config.xml

<navigation-rule>
 <navigation-case>
  <from-outcome>XYZ</from-outcome>
  <to-view-id>pageB.xhtml</to-view-id>
  <redirect/>
  </navigation-case>
 <navigation-case>
  <from-outcome>RST</from-outcome>
  <to-view-id>pageC.xhtml</to-view-id>
  <redirect/>
 </navigation-case>
</navigation-rule> 

in bean

getTypeXYZ() {
   ...
   NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
   nh.handleNavigation(facesContext, null, "XYZ");
}