锘??xml version="1.0" encoding="utf-8" standalone="yes"?> · 澶嶅埗 ajax4jsf.jar and oscache-2.2.jar 鍒扮▼搴忕殑 WEB-INF/lib 鏂囦歡澶逛笅. 鍦ㄨ繖閲屾垜浠湪鐖舵爣絳?span lang=EN>(<h:inputText>)涓坊鍔犱簡涓涓?span lang=EN>AJAX 鏀寔. 璇ユ敮鎸佺粦瀹氫簡JavaScript浜嬩歡“onkeyup” .鍥犳, 姣忎竴嬈¤浜嬩歡鍙戝竷緇欑埗鏍囩鏃?span lang=EN>,鎴戜滑鐨勭▼搴忓皢鍙戦佷竴涓?span lang=EN>AJAX璇鋒眰鍒?span lang=EN>Server.榪欐剰鍛崇潃鎴戜滑鐨勫彈綆$悊鐨?span lang=EN>bean灝嗗寘鍚“text” 鍩熶腑鎴戜滑杈撳叆鐨勬渶鏂版暟鎹?span lang=EN>. or The algorithm has three inputs錛堢畻娉曟湁涓変釜杈撳叆錛? The outcome, that is, the value of an action attribute or the string resulting from the invocation of a method reference. action灞炴х殑鍊兼垨鑰呭紩鐢ㄦ柟娉曠殑榪斿洖緇撴灉錛堝瓧絎︿覆綾誨瀷錛?/p>
The view ID of the current view銆傚綋鍓嶈鍥?/p>
The action, that is, the literal value of the action attribute in the component that triggered the navigation.鐢ㄤ互瑙﹀彂瀵艱埅鐨勭粍浠跺睘鎬с?/p>
The first of two phases is to find the matching navigation-rule, following these steps錛堢浜岄樁孌電殑絎竴姝ュ氨鏄鎵劇鍚堢殑瀵艱埅瑙勫垯錛? The second of two phases is to consider all navigation-case elements in the matching navigation rule (which may consist of several merged navigation-rule elements with matching from-view-id.values). Follow these steps to find the matching case. You can add a locale attribute to the f:view element, for example <f:view locale="de"> You can set the default and supported locales in WEB-INF/faces-config.xml (or another application configuration resource): Request Session 浜斻丆onfigure Bean
淇敼web.xml錛屽鍔燼4j鐨刦ilter閰嶇疆<filter>
<display-name>Ajax4jsf Filter</display-name>
<filter-name>ajax4jsf</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>ajax4jsf</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
</filter>
浜屻丣SP
<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<head>
<title>repeater</title>
</head>
<body>
<f:view>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="Type the Text:" />
<h:inputText value="#{bean.text}">
<a4j:support event="onkeyup" reRender="repeater" />
</h:inputText>
<h:outputText value="Text in the AJAX Response:" />
<h:outputText id="repeater" value="#{bean.text}" />
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
涓夈丅ean & faces-config.xml
package com.ivo.a4j.bean;
public class Bean {
private String text;
public Bean() {
//text = "11";
//System.out.println("Create");
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>bean</managed-bean-name>
<managed-bean-class>com.ivo.a4j.bean.Bean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
]]>
榪涘畼鏂圭綉绔?a >http://jsf-spring.sourceforge.net錛屼笅杞絣ib
浜屻佸弬鑰僸uickstart閰嶇疆鐩稿簲鏂囦歡
http://jsf-spring.sourceforge.net/quickstart.shtml
鏈緇堥厤緗粨鏋滃涓?br>web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>
/WEB-INF/classes/faces/faces-config.xml,
/WEB-INF/classes/faces/faces-config-beans.xml
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:spring/applicationContext-*.xml
</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>de.mindmatters.faces.spring.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
鏍規(guī)嵁quitstart閰嶇疆瀹屼箣鍚庡彲鑳借繕鏈夊涓嬪紓甯革細
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: de.mindmatters.faces.spring.factory.BeansEvaluationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uiBean': Scope 'request' is not active; nested exception is java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:532)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:408)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
de.mindmatters.faces.lifecycle.RenderResponsePhase.executePhase(RenderResponsePhase.java:45)
de.mindmatters.faces.lifecycle.AbstractPhase.execute(AbstractPhase.java:37)
de.mindmatters.faces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:166)
de.mindmatters.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:226)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
鐒跺悗鍐嶆妸榪欎釜listener鍔犱笂
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
灝眔k浜嗐?br>
鍙?br>濡傛灉榪樻湁闂錛屽湪faces-config.xml涓坊鍔?br><application>
<variable-resolver>
org.springframework.web.jsf.DelegatingVariableResolver
</variable-resolver>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
]]>
閫氳繃action榪斿洖鐨勫瓧絎︿覆錛岀劧鍚庢瘮杈?nbsp; from-outcome鏍囩鍊鹼紝濡傛灉鐩稿悓錛屽氨榪斿洖鍒?nbsp; to-view-id 鍒跺畾鐨勯〉闈?br>娉細 view ID strings must start with a /.
浜屻佸姩鎬佸鑸?br><h:commandButton label="Login" action="#{loginController.verifyUser}"/>
鏍規(guī)嵁a(chǎn)ction涓皟鐢ㄧ殑bean鏂規(guī)硶榪斿洖鍊兼潵紜畾鏄劇ず欏甸潰
loginController鐨勯獙璇佹柟娉?br>String verifyUser() {
if (...)
return "success";
else
return "failure";
}
涓夈侀珮綰у鑸?br>Redirection
濡傛灉浣犲湪to-view-id 鍚?鍔爎edirect鍏冪礌錛屽垯JSP瀹瑰櫒鍗充腑鏂綋鍓峳equest璇鋒眰錛屽茍鍙戦佷竴涓狧TTP redirect 璇鋒眰鍒癱lient.
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/success.jsp</to-view-id>
<redirect/>
</navigation-case>
Wildcards(閫氶厤絎?
<navigation-rule>
<from-view-id>/secure/*</from-view-id>
<navigation-case>
. . .
</navigation-case>
</navigation-rule>
鍙鏄湪/secure/榪欎釜鐩綍涓嬬殑欏甸潰閮戒嬌鐢ㄨ繖涓鑸鍒欍?br>
鎵鏈?br><from-view-id>/*</from-view-id>
<from-view-id>*</from-view-id>
Using from-action
<navigation-case>
<from-action>#{quiz.answerAction}</from-action>
<from-outcome>again</from-outcome>
<to-view-id>/again.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{quiz.startOverAction}</from-action>
<from-outcome>again</from-outcome>
<to-view-id>/index.jsp</to-view-id>
</navigation-case>
鏍規(guī)嵁涓嶅悓鐨刟ction浣跨敤涓嶅悓鐨勫鑸鍒欍?br>
瀵艱埅綆楁硶
Naturally, we recommend that you do not create tricky navigation rules in your own programs. As long as you stay away from wildcards and from-action elements, you won't need to know about the gory details of the navigation algorithm.
]]>
鏍煎紡濡備笅錛?/p>
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>com.corejsf.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
浜屻丮essage Bundle
鑷畾涔夎祫婧愭枃浠?font face="Courier New">com/corejsf/messages.properties錛岄氳繃f:loadBundle璁塊棶
<f:loadBundle basename="com.corejsf.messages" var="msgs"/>
basename : properties鏂囦歡鐨勮礬寰?br>var: 鏂囦歡瀹氫箟鐨刴essage key
com/corejsf/messages_de.properties.
鍥介檯鍖栵紝鍦ㄩ粯璁よ祫婧愭枃浠剁殑鍩虹涓婏紝澧炲姞鍚庣紑錛屾爣璇嗚璦綾誨埆銆?br>
璇█榛樿鏄劇ず璁劇疆
<faces-config>
<application>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>de</supported-locale>
</locale-config>
</application>
</faces-config>
涓夈丅acking Beans
鍥涖丅ean Scope
Application
璁劇疆灞炴у?br> <managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>com.corejsf.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>name</property-name>
<value>me</value>
</managed-property>
<managed-property>
<property-name>password</property-name>
<value>secret</value>
</managed-property>
</managed-bean>
璁劇疆null鍊?br><managed-property>
<property-name>password</property-name>
<null-value/>
</managed-property>
]]>
浜屻丣SP欏甸潰
index.jsp
welcome.jsp
涓夈丅ean
UserBean .java
package com.test.jsf.bean;
public class UserBean {
private String name;
private String password;
// PROPERTY: name
public String getName() {
return name;
}
public void setName(String newValue) {
name = newValue;
}
// PROPERTY: password
public String getPassword() {
return password;
}
public void setPassword(String newValue) {
password = newValue;
}
public String check() {
name = "wxf";
return "success";
//return SUCCESS;
}
}
鍥涖乫aces-config
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "<faces-config >
<navigation-rule>
<from-view-id>/login/index.jsp</from-view-id>
<navigation-case>
<from-outcome>login</from-outcome>
<to-view-id>/login/welcome.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>user</managed-bean-name>
<managed-bean-class>
com.test.jsf.bean.UserBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
浜斻亀eb.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns=" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee <context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>
鍏佹祴璇?br>
http://localhost:8080/jsf/login/index.faces
娉ㄦ剰錛岃皟鐢╦sp欏甸潰鏃朵竴瀹氳浣跨敤faces錛岀粨灝撅紝鍚﹀垯jsf鐨勬爣絳懼皢鏃犳硶璇嗗埆