Jsf 2 创建连接Bean和Facelets的ICEfaces应用程序示例
我是开发web应用程序的新手,我安装了ICEfaces插件。我发现要学习如何使用它,第一个示例在我的IDE中不起作用 这是本教程的最后一部分,介绍了如何在webapp中使用dateTimeEntry。 因此,我按照说明进行操作,因此我的index.xhtml如下所示:Jsf 2 创建连接Bean和Facelets的ICEfaces应用程序示例,jsf-2,javabeans,facelets,icefaces,Jsf 2,Javabeans,Facelets,Icefaces,我是开发web应用程序的新手,我安装了ICEfaces插件。我发现要学习如何使用它,第一个示例在我的IDE中不起作用 这是本教程的最后一部分,介绍了如何在webapp中使用dateTimeEntry。 因此,我按照说明进行操作,因此我的index.xhtml如下所示: <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht
<?xml version='1.0' encoding='UTF-8' ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:icecore="http://www.icefaces.org/icefaces/core"
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns:ice="http://www.icesoft.com/icefaces/component">
<h:body>
<form>
<ace:dateTimeEntry id="dateTimeEntryId"
value="#{yourBean.selectDateProperty}" timeZone="Canada/Mountain"
pattern="MMM/dd/yyyy" style="width: 729px; " renderAsPopup="true">
</ace:dateTimeEntry><br />
</form>
</h:body>
</html>
package org.icefaces.view;
import java.io.Serializable;
import java.util.Date;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.icefaces.ace.event.DateSelectEvent;
@ManagedBean(name= "yourBean")
@ViewScoped
public class YourBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5058131064162864510L;
private Date selectDateProperty = new Date(System.currentTimeMillis());
public Date getSelectDateProperty() {
return selectDateProperty;
}
public void setSelectDateProperty(Date selectDateProperty) {
this.selectDateProperty = selectDateProperty;
}
public void dateSelectListener(DateSelectEvent event) {
setSelectDateProperty(event.getDate());
}
}
项目的结构如下所示:
<?xml version='1.0' encoding='UTF-8' ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:icecore="http://www.icefaces.org/icefaces/core"
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns:ice="http://www.icesoft.com/icefaces/component">
<h:body>
<form>
<ace:dateTimeEntry id="dateTimeEntryId"
value="#{yourBean.selectDateProperty}" timeZone="Canada/Mountain"
pattern="MMM/dd/yyyy" style="width: 729px; " renderAsPopup="true">
</ace:dateTimeEntry><br />
</form>
</h:body>
</html>
package org.icefaces.view;
import java.io.Serializable;
import java.util.Date;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.icefaces.ace.event.DateSelectEvent;
@ManagedBean(name= "yourBean")
@ViewScoped
public class YourBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5058131064162864510L;
private Date selectDateProperty = new Date(System.currentTimeMillis());
public Date getSelectDateProperty() {
return selectDateProperty;
}
public void setSelectDateProperty(Date selectDateProperty) {
this.selectDateProperty = selectDateProperty;
}
public void dateSelectListener(DateSelectEvent event) {
setSelectDateProperty(event.getDate());
}
}
关键是,在本教程中没有给出保存JavaBean的位置。因此,我认为它必须保存在java资源目录中,但我不确定,因为该应用程序无法工作。我只是得到一个空白屏幕。我认为服务器及其配置是有效的,因为我可以删除一些Img或按钮,并在浏览器中查看结果。所以我想我并没有真正理解JavaBean是如何与xhtml文件连接的。我认为它可以与ManagedBean-attribute一起使用,但我不确定这一点。我发现,javabeans和xhtml文件中变量的连接必须以以下形式在faces-config.xml中创建:
<managed-bean>
<managed-bean-name> [bean-name-of-java-class] </managed-bean-name>
<managed-bean-class> [fullpath-to-java-file] </managed-bean-class>
<managed-bean-scope>[scope]</managed-bean-scope>
</managed-bean>
[java类的bean名称]
[java文件的完整路径]
[范围]
您可以在此处找到完整的示例代码列表
我发现,我必须在浏览器中调用.jsf文件以使文本字段可见。但它仍然没有日历的功能。