我有一个jsf 1.2命令链接
<h:commandLink id="cars" action="${swapViewHandler.myFunction1}">
<h:commandLink id="ships" action="${swapViewHandler.myFunction2}">
myFunction1使用汽车填充swapViewHandler.listA并导航至cars.xhtml
<navigation-rule>
<navigation-case>
<from-outcome>cars</from-outcome>
<to-view-id>cars.xhtml</to-view-id>
<redirect />
</navigation-case>
myFunction2使用船只填充相同的swapViewHandler.listA 导航到ships.xhtml
<navigation-rule>
<navigation-case>
<from-outcome>ships</from-outcome>
<to-view-id>hips.xhtml</to-view-id>
<redirect />
</navigation-case>
我需要处理用户刷新(F5),以便在刷新时发生 cars.xhtml myFunction1被调用并重新填充listA(带汽车) 当ships.xhtml被刷新时,myFunction2被调用并重新填充listA(带有船只)
cars.xhtml和ships.xhtml具有相同的backingbean(swapviewhandler)
他们都包含
<c:forEach id="tablePicList" items="${swapViewHandler.listA}" var="entity" varStatus ="status">
答案 0 :(得分:1)
每个视图都应该有自己的支持bean。将bean放在请求范围内,并在其(post)构造函数中完成工作。然后将在每个新的GET请求上调用此方法。 E.g。
public class CarHandler {
private List<Car> cars;
@EJB
private CarService carService;
@PostConstruct
public void init() {
cars = carService.list();
}
// ...
}
不要忘记将命令链接更改为正常输出链接。它还会为您提供额外的SEO点,因为它显然涉及纯页面到页面导航和可收藏/可刷新的GET请求。
<h:outputLink value="cars.jsf">cars</h:outputLink>
<h:outputLink value="ships.jsf">ships</h:outputLink>
如果列表依赖于某些请求参数或会话范围的托管bean,那么您应该将其作为<managed-property>
中的faces-config.xml
注入到支持bean中。它将在@PostConstruct
方法中可用(但构造函数中的不是。)。