gpt4 book ai didi

collections - p :collector vs custom wrapper class? 的用例是什么

转载 作者:行者123 更新时间:2023-12-04 07:18:31 24 4
gpt4 key购买 nike

我不知道 p:collector .我创建了这个自定义抽象类:

abstract public class Wrapper<T> {
protected Integer number;
protected List<T> list;
protected Class<T> klass;

public Wrapper() {
this.setList(new ArrayList<T>());
}

public void setListNumber(Integer number) {
Class<T> klass = this.getKlass();
List<T> list = this.getList();
ListUtil.setSize((ArrayList<T>) list, number, klass);
}

public void add() {
List<T> list = this.getList();
Class<T> klass = this.getKlass();
try {
list.add(klass.newInstance());
}
catch (InstantiationException e) {
throw new InstantiationUncheckedException(e);
}
catch (IllegalAccessException e) {
throw new IllegalAccessUncheckedException(e);
}
}

public void remove(int i) {
List<T> list = this.getList();
list.remove(i);
}



public Integer getNumber() {
return number;
}

public void setNumber(Integer number) {
this.number = number;
}

public List<T> getList() {
return list;
}

public void setList(List<T> list) {
this.list = list;
}

public Class<T> getKlass() {
return klass;
}

public void setKlass(Class<T> klass) {
this.klass = klass;
}
}
我通常这样使用它:
public class Things extends Wrapper<Thing> {
public Things() {
super();
this.setKlass(Thing.class);
}

@Override
public String toString() {
return "Things [number=" + number + ", list=" + list + "]";
}
}
并在 View 中,例如:
<ui:repeat varStatus="status" var="thing" value="#{bean.things.list}">

<p:commandButton 
value="Add"
action="#{bean.things.add()}"
immediate="true"
/>

<p:commandButton
value="❌"
action="#{bean.licenze.remove(status.index)}"
immediate="true"
/>
p:collector收集器可以用更少的代码做得更好吗?

最佳答案

p:collectorremoved in PrimeFaces 11deprecated in 10 之后,所以如果你想升级,最好不要使用它。

关于collections - p :collector vs custom wrapper class? 的用例是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68647914/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com