2011-08-23 32 views
1

我有一個JSF 1.2命令鏈接如何獲得更新的用戶列表JSF刷新

<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(與汽車) 和ship.xhtml被刷新時myFunction2被調用並重新填充listA(帶有船舶)

cars.xhtml和ships.xhtml具有相同的backingbean(swapviewhandler)

,它們都含有

<c:forEach id="tablePicList" items="${swapViewHandler.listA}" var="entity" varStatus ="status"> 

回答

1

每個視圖應該有自己的支持bean。將bean放入請求範圍,並在其(構建函數)中執行該作業。這將在每個新的GET請求中被調用。例如。

public class CarHandler { 

    private List<Car> cars; 

    @EJB 
    private CarService carService; 

    @PostConstruct 
    public void init() { 
     cars = carService.list(); 
    } 

    // ... 
} 

不要忘記將命令鏈接更改爲普通輸出鏈接。它也會給你額外的搜索引擎優化點,因爲它顯然涉及純粹的頁面到頁面導航和書籤/可刷新的GET請求。

<h:outputLink value="cars.jsf">cars</h:outputLink> 
<h:outputLink value="ships.jsf">ships</h:outputLink> 

如果列表是依賴於某些請求參數或會話範圍內管理的bean,那麼你應該注入,在後臺bean作爲faces-config.xml一個<managed-property>。它將在@PostConstruct方法中可用(但在構造函數中爲而不是!)。