【发布时间】:2014-01-14 12:31:24
【问题描述】:
我需要构建一个包含问题的测验应用程序(每个问题有 2 个可能的答案)我在数据库中存储了一些问题。选择答案并单击“下一步”后,您将看到下一个问题。 我有一个代表每个问题的 bean,它被称为 Item,并且具有以下属性: 问题,ansA,ansB; 我有一个豆子:
@ManagedBean
@ViewScoped
public class Bean {
private List<Item> items = new ArrayList<Item>();
private List<Item> helper = new ArrayList<Item>();
private String myValue;
int indexHelp = 0;
public String next() {
items.clear();
items.add(helper.get(indexHelp));
indexHelp++;
System.out.println("chose: " + myValue);
return "ok";
}
列表助手已与数据库中的问题一起存储
jsf 文件:
<h:form>
<h:dataTable value="#{bean.items}" var="item">
<h:selectOneRadio value="#{bean.myValue}">
<h:column>
<f:selectItem itemLabel="#{item.question}" />
</h:column>
<h:column>
<f:selectItem itemValue="1" itemLabel="#{item.ansA}" />
</h:column>
<h:column>
<f:selectItem itemValue="2" itemLabel="#{item.ansB}" />
</h:column>
</h:selectOneRadio>
</h:dataTable>
<h:commandButton value="Next" action="#{bean.next}" />
</h:form>
问题是当我运行项目时,它没有显示单选按钮、问题或答案。 谢谢!!
【问题讨论】:
-
好吧,我以为我知道你想要什么,但你的描述和你的代码矛盾。你说你只想显示一个问题,那你为什么要遍历一个列表呢?
标签: java jsf javabeans selectoneradio