【问题标题】:how to get a jsf list updated on user refresh如何在用户刷新时更新 jsf 列表
【发布时间】:2011-11-02 05:40:21
【问题描述】:

我有一个 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 使用船舶和 导航到 ship.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(带有船舶)

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

它们都包含

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

【问题讨论】:

    标签: java jsf refresh


    【解决方案1】:

    每个视图都应该有自己的支持 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,那么您应该将其作为 &lt;managed-property&gt; 注入到支持 bean 中 faces-config.xml。它将在 @PostConstruct 方法中可用(但在构造函数中不!)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-23
      • 2023-01-25
      • 1970-01-01
      相关资源
      最近更新 更多