Ajax view updates doesn't work properly in custom components with dedicated java class

给你一囗甜甜゛ 提交于 2019-12-07 09:33:31

I discovered where the problem is. I thought that when a component gets updated it was entirely reprocessed, but it doesn't happen in some occasions. For some reason, it seems that when ui:repeat is used, JSF tries to retard the component reset.

A solution is to explicitly recalculate the list when getList() is called:

It was like this before:

  public ArrayList<String> getList() {
    if (null == list) generateList();
      return list;
    }
  }

If I remove the verification for null it works.

In my opinion that's what was happening: when the component was updated the list still had the values calculated before, it was not null and no recalculation was done. In the time between one request and another, the component was getting reconstructed. With the component reseted, list was equal to null and the recalculation was done on getList(), making the view always one request late.


EDIT: A much better solution is to use f:event in the component's view instead of recalculating the list on every get.

<f:metadata>
  <f:event type="preRenderComponent" listener="#{cc.generateList}" />
</f:metadata>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!