JavaServer Faces (JSF) 是一种用于构建Java Web 应用程序的标准框架(是Java Community Process 规定的JSR-127标准)。它提供了一种以组件为中心的用户界面(UI)构建方法,从而简化了Java服务器端应用程序的开发。
web.xml
这个对象位于jsf-api包中,启动了
private FacesContextFactory facesContextFactory = null;
private Lifecycle lifecycle = null;
private ServletConfig servletConfig = null;
servletConfig 按照如下顺序进行解析:
com/sun/faces/jsf-ri-runtime.xml
classpath的META-INF/faces-config.xml,如果有多个jar包,那么会依次扫描起来
/WEB-INF/faces-config.xml
上面扫描顺序固定,如果后面扫描到的文件中,包含了之前文件中已经存在的配置,那么配置会被覆盖;
在JSF的页面代码当中,通过数据绑定,我们把控件的value值,与某个后台的数据bean关联起来。
启动bean, <h:inputText value="#{user.name}"/>
完成绑定;
对action的绑定:
调用action:<h:commandButton id="regist" action="#{action.regist}" value="注册"/>
后台操作:
<navigation-case>
<from-outcome>login</from-outcome>
//方法返回值 对应的jsp页面
<to-view-id>/welcome.jsp</to-view-id>
</navigation-case>
出现:javax.faces.application.ViewExpiredException: viewId:/index.faces - View /index.faces could not be restored.
可能是session超时,重启tomcat
或者在地址栏http://localhost:8182/jsf/index.faces中去掉/index.faces
demo:
[img]http://dl2.iteye.com/upload/attachment/0106/5134/9e922d75-34fd-3aad-83d2-dc9507735ea5.png[/img]
http://download.csdn.net/detail/onway417/8493107
web.xml
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
这个对象位于jsf-api包中,启动了
private FacesContextFactory facesContextFactory = null;
private Lifecycle lifecycle = null;
private ServletConfig servletConfig = null;
servletConfig 按照如下顺序进行解析:
com/sun/faces/jsf-ri-runtime.xml
classpath的META-INF/faces-config.xml,如果有多个jar包,那么会依次扫描起来
/WEB-INF/faces-config.xml
上面扫描顺序固定,如果后面扫描到的文件中,包含了之前文件中已经存在的配置,那么配置会被覆盖;
在JSF的页面代码当中,通过数据绑定,我们把控件的value值,与某个后台的数据bean关联起来。
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>com.corejsf.UserBean</managed-bean-class>
启动bean, <h:inputText value="#{user.name}"/>
完成绑定;
对action的绑定:
<managed-bean-name> action </managed-bean-name>
<managed-bean-class> nick.Action </managed-bean-class>
<managed-bean-scope> session </managed-bean-scope> </managed-bean>
调用action:<h:commandButton id="regist" action="#{action.regist}" value="注册"/>
后台操作:
package nick;
public class Action {
public String regist() {
//与action----nick.Action {action.regist}对应
ValueBinding binding = Util.getValueBinding("#{user}");
User user = (User)binding.getValue(FacesContext.getCurrentInstance());
…
return "regist";
<navigation-case>
<from-outcome>login</from-outcome>
//方法返回值 对应的jsp页面
<to-view-id>/welcome.jsp</to-view-id>
</navigation-case>
出现:javax.faces.application.ViewExpiredException: viewId:/index.faces - View /index.faces could not be restored.
可能是session超时,重启tomcat
或者在地址栏http://localhost:8182/jsf/index.faces中去掉/index.faces
demo:
[img]http://dl2.iteye.com/upload/attachment/0106/5134/9e922d75-34fd-3aad-83d2-dc9507735ea5.png[/img]
http://download.csdn.net/detail/onway417/8493107