<p:outputPanel id="panel">
<ui:repeat value="#{dataController.display()}"
var="item" rendered="#{Bean.showtable}">
<b:row>
<b:column col-md="5">
<h:outputText value="#{item.name}" style="font-family: verdana;font-size:16px;margin-bottom:15px;"></h:outputText>
</b:column>
<b:column col-md="7">
<h:inputText style="width:200px;height:30px;margin-bottom:15px;"
autocomplete="off"></h:inputText>
</b:column>
</b:row>
</ui:repeat>
在上面的代码中,我使用 ui:repeat 在输出文本的列表中显示项目名称 输入文字,用于输入商品的值。
输入文本取决于列表中的值,即动态生成的。
我需要访问输入文本中的值并将其添加到List。
任何人都可以建议我使用ui:repeat一次显示输入文本来访问输入文本到bean / list的值吗?
我尝试创建一个空列表并再次使用ui:仅重复输入文本..尝试从输入文本访问值。但是ui:repeat不再工作..因为它已经用过一次用于显示。< / p>
我是JSF的新手。任何帮助都会受到赞赏.Thankyou。
答案 0 :(得分:2)
不要使用空列表。使用null或空值初始化它
假设我们有inputs
作为您的列表,您的 bean 应该如下所示。
@Named
@ViewScoped
public class DataController implements Serializable {
private List<String> inputs;
// getters and setters
@PostConstruct
public void init() {
inputs = new ArrayList<String>();
}
public List<Bean> getDisplay() {
List<Bean> display = new ArrayList<Bean>();
// add values to display
for (int i = inputs.size(); i < display.size(); i++) {
inputs.add("");
}
return display;
}
// for testing inputs
public void testInputs() {
for (String input : inputs) {
System.out.println(">>>>>" + input);
}
}
}
<强> XHTML 强>
<ui:repeat value="#{dataController.display()}" varStatus="idx" ...>
...
<h:inputText value="#{dataController.inputs[idx.index]}" style="width:200px;height:30px;margin-bottom:15px;" autocomplete="off"></h:inputText>
...
</ui:repeat>
<p:commandButton value="Test Inputs" action="#{dataController.testInputs}" update="@form" />
希望这有帮助。