【发布时间】:2015-03-18 12:01:49
【问题描述】:
我当前的 JSF 版本是 2.1,我想找到一个简短的解决方案,将用户键入的 Strings 放入单个 List。在托管 bean 中:
@ManagedBean
@SessionScoped
public class MyBean{
private List<String> values;
public void List<Integer> getIdentifiers(){
List<Integer> lst = new ArrayList<Integer>();
//...
return lst;
}
//GET, SET, OTHER STUFF
}
和标记:
<c:forEach items="#{myBean.identifiers}" var="id">
<h:inputText value="__WHAT?__" id="input#{id}" />
</c:forEach>
我需要将用户输入的每个值放入 inputTexts 到 values List<String> 中。我该怎么做或者有可能吗?
UPD:我需要完全使用 <c:forEach> 循环来执行此操作,因为我可能应该添加一些其他输入字段,例如 rich:calendar,它们将呈现如下:
<c:forEach items="#{myBean.identifiers}" var="id">
<c:choose>
<c:when test="__calendar_needed__">
<rich:calendar />
</c:when>
<c:when test="__input_needed__">
<h:inputText value="__WHAT?__" id="input#{id}" />
</c:when>
</c:choose>
</c:forEach>
【问题讨论】: