p:虽然设置了新值,但是选项列表会被缓存

时间:2016-12-21 14:07:42

标签: jsf primefaces

此时我有select all_nums.num,coalesce(p_cnt,0), coalesce(s_cnt,0), coalesce(t_cnt,0) from (select prime as num from t union select secondary from t union select third from t) all_nums left join (select prime,count(*) as p_cnt from t group by prime) p on p.prime=all_nums.num left join (select secondary,count(*) as s_cnt from t group by secondary) s on s.secondary=all_nums.num left join (select third,count(*) as t_cnt from t group by third) t on t.third=all_nums.num group by all_nums.num 使用p:picklist。每当选择新实体时,必须更新选项列表,因为属性列表会根据每个实体而变化。

但是,即使再次调用DualListModel<String>,我也会保留首先填充选项列表的值,我会使用onEntitySelect()来更改整个setPicklistAttributes()

我将DualListModel放在setter中,右边的值由sysouts设置,但几乎立即使用旧值再次调用setter,我的更改将被覆盖。

为什么会这样?我的方法是重置onEntitySelect() DualListModel内的错误吗?

onEntitySelect()

<p:picklist>:

<p:pickList id="pickList" value="#{dashboardBean.picklistAttributes}" var="attribute" itemLabel="#{attribute)}" itemValue="#{attribute}"/>

onEntitySelect():

1 个答案:

答案 0 :(得分:1)

在init方法上初始化DualListModel,该方法具有@PostConstruct注释。而不是在每个onEntitySelect中创建新的DualListModel,而是设置现有的DuaListModels源和目标。这是一个示例:

private DualListModel<Attribute> attributes;

@PostConstruct
    public void init() {

        // initialize service picklist
        List<Attribute> source = new ArrayList<Attribute>();
        List<Attribute> target = new ArrayList<Attribute>();
        attributes= new DualListModel<Attribute>(source , target );

    }

public void onEntitySelect() {
  // create your newAttributesSoruce and Target here then set to existing DualistModel
  attributes.setSource(newAttributesSource);
  attributes.setTarget(newAttributesTarget);
}