我想在我的JSF页面上定期打印出一个字符串数组,但我无法实现这一点。 JSF只是一次打印出整个数组,而不是定期打印出来。
这是我的XHTML代码:
<h:form>
<h:outputText id="eventener" value="#{eventBean.names}" />
<p:poll interval="2" listener="#{eventBean.names}" update="eventener" />
</h:form>
这是我的豆子:
@ManagedBean
@ViewScoped
public class EventBean implements Serializable {
private List<String> names;
@PostConstruct
public void namesInterval() {
names = Arrays.asList("Steve is late for work", "Segun is coming back next week", "Tope is a beautiful girl");
}
public List<String> getNames() {
return names;
}
}
答案 0 :(得分:0)
我不知道你想做什么。您想一次打印阵列中的每个项目吗?当您更新(添加项目)阵列时?
您没有随时更新阵列,民意调查正在按计划进行。在侦听器属性上,您可以每2秒设置一次,例如从外部源刷新阵列。如果你每2秒尝试从数组中打印一个项目,你可以试试这样的东西
<h:form>
<h:outputText id="eventener" value="#{eventBean.item}" />
<p:poll interval="2" listener="#{eventBean.pollListener}" update="eventener" />
</h:form>
<强>豆强>
@ManagedBean
@ViewScoped
public class EventBean implements Serializable {
private List<String> names;
private String item;
private int count;
@PostConstruct
public void namesInterval() {
names = Arrays.asList("Steve is late for work", "Segun is coming back next week", "Tope is a beautiful girl");
count = 0;
}
public List<String> getNames() {
return names;
}
public String getItem(){
return item;
}
public void pollListener(){
//you can use an iterator too
if (count >= names.size())
{
count = 0;
}
item = names.get(count);
count++;
}
}