Jsf Primefaces 6-投票
我有以下Bean:Jsf Primefaces 6-投票,jsf,primefaces,Jsf,Primefaces,我有以下Bean: package com.linknet.beans; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; import javax.faces.model.SelectItem
package com.linknet.beans;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;
import javax.faces.model.SelectItemGroup;
import com.linknet.data.Device;
import com.linknet.data.DeviceFactory;
@ManagedBean(name = "deviceSwitcherBean")
@ViewScoped
public class DeviceSwitcherBean implements Serializable {
public DeviceSwitcherBean() {
this.now = new Date();
System.out.println("PRINT DEVICES");
this.devices = new DeviceFactory().createDevices("http://localhost:8080/DeviceCommander/resources/xml/DevliceList.xml");
this.currentDevice = this.devices.get(0);
//System.out.println(this.currentDevice.toString());
SelectItemGroup g1 = new SelectItemGroup("Devices");
ArrayList<SelectItem> items = new ArrayList<SelectItem>();
for ( Device d : this.devices ) {
items.add(new SelectItem(d,d.getName()));
}
System.out.println("PRINT 2");
g1.setSelectItems(items.toArray(new SelectItem[0]));
devs = new ArrayList<SelectItem>();
devs.add(g1);
}
public void updateDate() {
this.now = new Date();
System.out.println("lel");
}
public void deviceSwitch() {
System.out.println("Kayla");
//System.out.println(getDevice());
}
public ArrayList<Device> getDevices() {
return devices;
}
public void setDevices(ArrayList<Device> devices) {
this.devices = devices;
}
public Device getCurrentDevice() {
return currentDevice;
}
public void setCurrentDevice(Device currentDevice) {
this.currentDevice = currentDevice;
}
public Date getNow() {
return now;
}
public void setNow(Date now) {
this.now = now;
}
//private String device;
public List<SelectItem> getDevs() {
return devs;
}
public void setDevs(List<SelectItem> devs) {
this.devs = devs;
}
private List<SelectItem> devs;
private ArrayList<Device> devices;
private Device currentDevice;
private Date now;
private static final long serialVersionUID = 1L;
//private ArrayList<String> devices;
}
包com.linknet.beans;
导入java.io.Serializable;
导入java.util.ArrayList;
导入java.util.Date;
导入java.util.List;
导入javax.faces.bean.ManagedBean;
导入javax.faces.bean.ViewScoped;
导入javax.faces.model.SelectItem;
导入javax.faces.model.SelectItemGroup;
导入com.linknet.data.Device;
导入com.linknet.data.DeviceFactory;
@ManagedBean(name=“deviceSwitcherBean”)
@视域
公共类DeviceSwitcherBean实现可序列化{
公共设备交换机bean(){
this.now=新日期();
System.out.println(“打印设备”);
this.devices=new DeviceFactory().createDevices(“http://localhost:8080/DeviceCommander/resources/xml/DevliceList.xml");
this.currentDevice=this.devices.get(0);
//System.out.println(this.currentDevice.toString());
SelectItemGroup g1=新建SelectItemGroup(“设备”);
ArrayList items=新建ArrayList();
用于(设备d:此设备){
添加(新建SelectItem(d,d.getName());
}
系统输出打印项次(“打印2”);
g1.设置SelectItems(items.toArray(新建SelectItem[0]);
devs=newarraylist();
devs.add(g1);
}
公共void updateDate(){
this.now=新日期();
系统输出打印项次(“lel”);
}
公共无效设备开关(){
System.out.println(“Kayla”);
//System.out.println(getDevice());
}
公共阵列列表getDevices(){
返回装置;
}
公共无效设置设备(ArrayList设备){
这个。设备=设备;
}
公共设备getCurrentDevice(){
回流装置;
}
公共无效setCurrentDevice(设备currentDevice){
this.currentDevice=currentDevice;
}
公开日期getNow(){
现在就回来;
}
现在公开作废(现在日期){
this.now=现在;
}
//专用字符串设备;
公共列表getDevs(){
返回开发人员;
}
公共无效集合开发者(列表开发者){
this.devs=devs;
}
私人名单开发人员;
专用阵列列表设备;
专用设备;
现在是私人约会;
私有静态最终长serialVersionUID=1L;
//专用阵列列表设备;
}
我的xhtml是:
设备通讯器
问题是时间是每秒更新一次的,但是时间是从bean的构造函数更新的,并且updateDate()根本不被调用。
为什么会这样 修复BalusC文章中提到的问题 工作代码 日志输出
设备通讯器
您共享的xhtml有问题。我看不到p:poll或对updateDate的调用?是的!你是对的——我已经删除了冗余的内部元素,不再调用bean的构造函数,但问题仍然存在;侦听器没有更新@Mitsos:上的日期,因此您接受了答案,但没有帮助。。?那就别接受了答案是正确的-我的代码中有一个问题,正如拉维正确指出的那样-我有一个外壳把一切都搞糟了。
PRINT DEVICES
PRINT 2
lel
lel
lel
lel
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:p="http://primefaces.org/ui" xmlns:i="http://image">
<h:head>
<title>DeviceCommander</title>
</h:head>
<h:body>
<h:form>
<h:outputText value="#{display.date}: " />
<h:outputText id="now" value="#{deviceSwitcherBean.now}" />
<p:poll interval="1" listener="#{deviceSwitcherBean.updateDate()}"
update="now" />
</h:form>
</h:body>
</html>