繁体   English   中英

无法在ui:repeat中更新inputText

[英]can't update inputText in ui:repeat

我在以下实体实体中:

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;
}
}

并在以下课程中使用Tage列表:

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;
}
}

和在jsf页面中使用tages类,如下所示:

 <h:panelGroup layout="block" id="panel_topic" styleClass="panel_topic">

        <div class="title_topic">#{msg['tages.title']}</div>

        <ui:repeat varStatus="loop" 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="&amp;times;"/>

                </p:commandLink>

                <h:inputText id="text" styleClass="text" value="#{tages._texts[loop.index].text}"></h:inputText>

                <div class="color_item" style="background-color:#{txt.color}"></div>

            </div>

        </ui:repeat>

        <p:commandButton id="add_item" styleClass="add_item" action="#{tages.addsTextss}"
                         value="#{msg['tages.addItem']}"
                         update="@(.panel_topic)">
        </p:commandButton>

    </h:panelGroup>

在运行时,当用户更改inputText上的文本未设置为bean时,则刷新页面inputText清除。

如何解决这个问题?

尝试这个,

<c:forEach var="txt" items="#{tages._texts}" varStatus="loop">

        <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="&amp;times;"/>

            </p:commandLink>

            <h:inputText id="text" styleClass="text" value="#{tages._texts[loop.index].text}"></h:inputText>

            <div class="color_item" style="background-color:#{txt.color}"></div>

        </div>

    </c:forEach>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM