我有一个复合组件,使用ui:repeat显示一个列表。
代码:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
</composite:interface>
<composite:implementation>
<h:panelGroup layout="block" id="panel_topic" styleClass="panel_topic">
<div class="title_topic">#{msg['tages.title']}</div>
<ui:repeat value="#{tages._texts}" var="txt">
<div class="tage">
<p:commandLink type="button" styleClass="close" aria-hidden="true"
action="#{tages.removeText}" update="panel_topic">
<f:setPropertyActionListener target="#{tages._tar}" value="#{txt}"/>
<h:outputText escape="false" value="&times;"/>
</p:commandLink>
<h:inputText id="text" styleClass="text" value="#{txt.text}"></h:inputText>
<div class="color_item" style="background-color:#{txt.color}"></div>
</div>
</ui:repeat>
<p:commandButton id="add_item" styleClass="add_item" actionListener="#{tages.addsTextss}" value="#{msg['tages.addItem']}"
update="panel_topic" >
</p:commandButton>
</h:panelGroup>
</composite:implementation>
my tages bean:
@ManagedBean(name = "tages")
@SessionScoped
public class Tages implements Serializable {
private int _size = 0;
private List<Tage> _texts = null;
private Tage _tar = null;
private String[] _colors = new String[]{"red", "blue", "pink"};
public Tages() {
}
@PostConstruct
public void init() {
_texts = new ArrayList<Tage>();
}
public void addsTextss() {
Tage _tage = new Tage();
_tage.setColor(_colors[_size]);
_tage.setId(++_size);
get_texts().add(_tage);
}
public void removeText() {
if (_size - 1 <= get_tar().getId()) {
--_size;
}
get_texts().remove(get_tar());
}
public List<Tage> get_texts() {
return _texts;
}
public void set_texts(List<Tage> _texts) {
this._texts = _texts;
}
public int get_size() {
return _size;
}
public void set_size(int _size) {
this._size = _size;
}
public Tage get_tar() {
return _tar;
}
public void set_tar(Tage _tar) {
this._tar = _tar;
}
}
my age bean:
public class Tage implements Serializable {
private int id=0;
private String text="";
private String color=null;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
}
当点击p:commandButton(add_item)不更新ui:repeat
如果用c:forEach替换ui:repeat,则更新权限,但组件不保存状态。
如何更新ui:repeat我有同样的错误之前与datatable和解决它,并解决它我自己查看下面的链接
JSF视图-在操作不更新视图时返回null