簡體   English   中英

如何獲取用戶刷新時更新的jsf列表

[英]how to get a jsf list updated on user refresh

我有一個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(帶有cars),而當ship.xhtml得到刷新時,myFunction2被調用並重新填充listA(帶有ships)

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

他們都包含

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

每個視圖都應具有自己的支持bean。 將bean放在請求范圍內,並在其(后)構造函數中完成工作。 然后,將在每個新的新GET請求上調用此方法。 例如

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,則應將其作為faces-config.xml<managed-property>注入到支持Bean中。 它可以在@PostConstruct方法中使用(但不能在構造器中使用!)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM