Author: ilya_shaikovsky
Date: 2008-07-31 09:46:05 -0400 (Thu, 31 Jul 2008)
New Revision: 9849
Added:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/examples/details.xhtml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/app.xml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/appfact.xml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/bean.java
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/beans.xml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/cfg.xml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/config.java
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/loginaction.java
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/registeraction.java
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/beanValidator/examples/simple.xhtml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI.xhtml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/usage.xhtml
Log:
stateAPI sample
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/beanValidator/examples/simple.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/beanValidator/examples/simple.xhtml 2008-07-31
13:40:14 UTC (rev 9848)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/beanValidator/examples/simple.xhtml 2008-07-31
13:46:05 UTC (rev 9849)
@@ -12,13 +12,19 @@
</f:facet>
<h:panelGrid columns="3">
<h:outputText value="Name:" />
- <h:inputText value="#{validationBean.name}" id="name"/>
+ <h:inputText value="#{validationBean.name}" id="name">
+ <rich:ajaxValidator/>
+ </h:inputText>
<rich:message for="name" />
<h:outputText value="Email:" />
- <h:inputText value="#{validationBean.email}" id="email"/>
+ <h:inputText value="#{validationBean.email}" id="email">
+ <rich:beanValidator/>
+ </h:inputText>
<rich:message for="email" />
<h:outputText value="Age:" />
- <h:inputText value="#{validationBean.age}" id="age"/>
+ <h:inputText value="#{validationBean.age}" id="age">
+ <rich:beanValidator/>
+ </h:inputText>
<rich:message for="age" />
</h:panelGrid>
<a4j:commandButton value="Submit"/>
Added:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/examples/details.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/examples/details.xhtml
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/examples/details.xhtml 2008-07-31
13:46:05 UTC (rev 9849)
@@ -0,0 +1,41 @@
+<!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:rich="http://richfaces.org/rich">
+ <ui:composition>
+ <p>
+ In order to use Rich Faces State Manager API you should perform next steps:
+ </p>
+ <ul>
+ <li>
+ Register state manager El resolver and navigation handler in faces config:
+ <p>
+ <rich:insert src="/richfaces/stateAPI/snippets/app.xml"
highlight="xml"/>
+ </p>
+ </li>
+ <li>
+ Register additional application-factory in faces-config:
+ <p>
+ <rich:insert src="/richfaces/stateAPI/snippets/appfact.xml"
highlight="xml"/>
+ </p>
+ </li>
+ <li>
+ Register two managed beans. One should define and store states itself.
+ And the other should define bean with type
<i>org.richfaces.ui.model.States</i>
+ and have managed property <i>states</i> bound to the bean which defines
states.
+ (Will be changed to xml declarations in future releases)
+ <p>
+ <rich:insert src="/richfaces/stateAPI/snippets/beans.xml"
highlight="xml"/>
+ </p>
+ </li>
+ <li>
+ Define states in Config class. (full code example on the <i>Usage</i>
tab)
+ </li>
+ <li>
+ Use <b>state</b> bindings on the pages.
+ </li>
+ </ul>
+ </ui:composition>
+</html>
\ No newline at end of file
Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/app.xml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/app.xml
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/app.xml 2008-07-31
13:46:05 UTC (rev 9849)
@@ -0,0 +1,4 @@
+ <application>
+
<navigation-handler>org.richfaces.ui.application.StateNavigationHandler</navigation-handler>
+ <el-resolver>org.richfaces.el.StateELResolver</el-resolver>
+ </application>
Added:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/appfact.xml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/appfact.xml
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/appfact.xml 2008-07-31
13:46:05 UTC (rev 9849)
@@ -0,0 +1,3 @@
+ <factory>
+
<application-factory>org.richfaces.ui.application.StateApplicationFactory</application-factory>
+ </factory>
Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/bean.java
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/bean.java
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/bean.java 2008-07-31
13:46:05 UTC (rev 9849)
@@ -0,0 +1,38 @@
+package org.richfaces.demo.stateApi;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Bean {
+
+ private String name;
+
+ private String password;
+
+ private String confirmPassword;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getConfirmPassword() {
+ return confirmPassword;
+ }
+
+ public void setConfirmPassword(String confirmPassword) {
+ this.confirmPassword = confirmPassword;
+ }
+
+}
\ No newline at end of file
Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/beans.xml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/beans.xml
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/beans.xml 2008-07-31
13:46:05 UTC (rev 9849)
@@ -0,0 +1,15 @@
+ <managed-bean>
+ <managed-bean-name>state</managed-bean-name>
+ <managed-bean-class>org.richfaces.ui.model.States</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ <managed-property>
+ <property-name>states</property-name>
+ <property-class>org.richfaces.ui.model.States</property-class>
+ <value>#{config.states}</value>
+ </managed-property>
+ </managed-bean>
+ <managed-bean>
+ <managed-bean-name>config</managed-bean-name>
+
<managed-bean-class>org.richfaces.demo.stateApi.Config</managed-bean-class>
+ <managed-bean-scope>none</managed-bean-scope>
+ </managed-bean>
\ No newline at end of file
Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/cfg.xml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/cfg.xml
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/cfg.xml 2008-07-31
13:46:05 UTC (rev 9849)
@@ -0,0 +1,30 @@
+ <managed-bean>
+ <managed-bean-name>loginbean</managed-bean-name>
+ <managed-bean-class>org.richfaces.demo.stateApi.Bean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+ <managed-bean>
+ <managed-bean-name>registerbean</managed-bean-name>
+ <managed-bean-class>org.richfaces.demo.stateApi.Bean</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ </managed-bean>
+ <managed-bean>
+ <managed-bean-name>loginaction</managed-bean-name>
+
<managed-bean-class>org.richfaces.demo.stateApi.LoginAction</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ <managed-property>
+ <property-name>bean</property-name>
+ <property-class>org.richfaces.demo.stateApi.Bean</property-class>
+ <value>#{loginbean}</value>
+ </managed-property>
+ </managed-bean>
+ <managed-bean>
+ <managed-bean-name>registeraction</managed-bean-name>
+
<managed-bean-class>org.richfaces.demo.stateApi.RegisterAction</managed-bean-class>
+ <managed-bean-scope>request</managed-bean-scope>
+ <managed-property>
+ <property-name>bean</property-name>
+ <property-class>org.richfaces.demo.stateApi.Bean</property-class>
+ <value>#{registerbean}</value>
+ </managed-property>
+ </managed-bean>
\ No newline at end of file
Added:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/config.java
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/config.java
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/config.java 2008-07-31
13:46:05 UTC (rev 9849)
@@ -0,0 +1,73 @@
+package org.richfaces.demo.stateApi;
+
+import javax.el.ExpressionFactory;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+import javax.faces.context.FacesContext;
+
+import org.richfaces.ui.model.States;
+
+public class Config {
+
+ public States getStates() {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ States states = new States();
+
+ // Registering new User State definition
+ states.setCurrentState("register"); // Name of the new state
+
+ // Text labels, properties and Labels for controls in "register" state
+ states.put("showConfirm", Boolean.TRUE); // confirm field rendering
+ states.put("link", "(To login)"); // Switch State link label
+ states.put("okBtn", "Register"); // Login/Register button label
+ states.put("stateTitle", "Register New User"); // Panel title
+
+ ExpressionFactory expressionFactory = facesContext.getApplication()
+ .getExpressionFactory();
+
+ // Define "registerbean" available under "bean" EL binding on the
page
+ ValueExpression beanExpression = expressionFactory
+ .createValueExpression(facesContext.getELContext(),
+ "#{registerbean}", Bean.class);
+ states.put("bean", beanExpression);
+
+ // Define "registeraction" available under "action" EL binding on
the
+ // page
+ beanExpression = expressionFactory.createValueExpression(facesContext
+ .getELContext(), "#{registeraction}", RegisterAction.class);
+ states.put("action", beanExpression);
+
+ // Define method expression inside registeraction binding for this state
+ MethodExpression methodExpression = expressionFactory
+ .createMethodExpression(facesContext.getELContext(),
+ "#{registeraction.ok}", String.class, new Class[] {});
+ states.put("ok", methodExpression);
+
+ // Outcome for switching to login state definition
+ states.setNavigation("switch", "login");
+
+ // Login Existent User State analogous definition
+ states.setCurrentState("login");
+ states.put("showConfirm", Boolean.FALSE);
+ states.put("link", "(To register)");
+ states.put("okBtn", "Login");
+ states.put("stateTitle", "Login Existent User");
+
+ beanExpression = expressionFactory.createValueExpression(facesContext
+ .getELContext(), "#{loginbean}", Bean.class);
+ states.put("bean", beanExpression);
+
+ beanExpression = expressionFactory.createValueExpression(facesContext
+ .getELContext(), "#{loginaction}", LoginAction.class);
+ states.put("action", beanExpression);
+
+ methodExpression = expressionFactory.createMethodExpression(
+ facesContext.getELContext(), "#{loginaction.ok}", String.class,
+ new Class[] {});
+ states.put("ok", methodExpression);
+
+ states.setNavigation("switch", "register");
+
+ return states;
+ }
+}
\ No newline at end of file
Added:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/loginaction.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/loginaction.java
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/loginaction.java 2008-07-31
13:46:05 UTC (rev 9849)
@@ -0,0 +1,25 @@
+package org.richfaces.demo.stateApi;
+
+import javax.faces.event.ActionEvent;
+
+public class LoginAction
+{
+
+ private Bean bean;
+
+ public void listener(ActionEvent event) {
+ //fetching some data on login
+ }
+
+ public String ok() {
+ return "loggedIn";
+ }
+
+ public Bean getBean() {
+ return bean;
+ }
+
+ public void setBean(Bean bean) {
+ this.bean = bean;
+ }
+}
\ No newline at end of file
Added:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/registeraction.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/registeraction.java
(rev 0)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippets/registeraction.java 2008-07-31
13:46:05 UTC (rev 9849)
@@ -0,0 +1,40 @@
+package org.richfaces.demo.stateApi;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+
+public class RegisterAction {
+ private Bean bean;
+
+ public void listener(ActionEvent event) {
+ //Check if the password fields are equals
+ if (bean.getConfirmPassword().equals(bean.getPassword())) {
+ FacesContext.getCurrentInstance().getApplication().getNavigationHandler().handleNavigation(FacesContext.getCurrentInstance(),
null, "registered");
+ } else {
+ FacesContext.getCurrentInstance().addMessage(
+ event.getComponent().getClientId(
+ FacesContext.getCurrentInstance()),
+ new FacesMessage(FacesMessage.SEVERITY_ERROR,
+ "Different passwords entered",
+ "Different passwords entered"));
+ }
+ }
+
+ public String ok() {
+ if (FacesContext.getCurrentInstance().getMaximumSeverity()==null){
+ return "registered";
+ }else{
+ return null;
+ }
+ }
+
+ public Bean getBean() {
+ return bean;
+ }
+
+ public void setBean(Bean bean) {
+ this.bean = bean;
+ }
+
+}
\ No newline at end of file
Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/usage.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/usage.xhtml 2008-07-31
13:40:14 UTC (rev 9848)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/usage.xhtml 2008-07-31
13:46:05 UTC (rev 9849)
@@ -13,17 +13,106 @@
}
</style>
<p>
- Description
+ Rich Faces State API allows easily define some set of states for the pages and any
+ properties sets for this states.
</p>
+ <p>
+ Imagine one state as a set of named value bindings method bindings and some
+ additional properties to be used after the state activated. So you could define
+ inputs values, controls labels and actions, rendering conditions and etc
+ using the same state variables which will have different values for every state.
+ </p>
+ <p>
+ Next small example panel
+ has two states: <b>login</b> and <b>register</b>. Lets list
the changes between
+ login and register.
+ </p>
+ <ul>
+ <li>
+ Confirmation field for password should appears in register state.
+ </li>
+ <li>
+ Method bindings should differs for the action button in every state.
+ </li>
+ <li>
+ Value bindings for the fields could be different between states.
+ </li>
+ <li>
+ Some labels should be changed between states
+ </li>
+ </ul>
+ <p>
+ Also there should be a link which will switch states from login to register
+ </p>
+ <p>
+ Now try the example itself before further explanations.
+ </p>
<fieldset class="demo_fieldset">
<legend class="demo_legend">Title</legend>
<div class="sample-container" >
<ui:include src="/richfaces/stateAPI/examples/example.xhtml"/>
<ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="openlabel" value="Template Page" />
<ui:param name="sourcepath"
value="/richfaces/stateAPI/examples/example.xhtml"/>
</ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="openlabel" value="Initial wizard page(Page with
EL bindings to state)" />
+ <ui:param name="sourcepath"
value="/richfaces/stateAPI/examples/simple.xhtml"/>
+ </ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="openlabel" value="Logged in page" />
+ <ui:param name="sourcepath"
value="/richfaces/stateAPI/examples/loginResult.xhtml"/>
+ </ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="openlabel" value="Registered page" />
+ <ui:param name="sourcepath"
value="/richfaces/stateAPI/examples/registerResult.xhtml"/>
+ </ui:include>
+
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcetype" value="java" />
+ <ui:param name="openlabel" value="Config Bean(States
definition)" />
+ <ui:param name="sourcepath"
value="/richfaces/stateAPI/snippets/config.java"/>
+ </ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcetype" value="java" />
+ <ui:param name="openlabel" value="Bean(Stores login/register
info)" />
+ <ui:param name="sourcepath"
value="/richfaces/stateAPI/snippets/bean.java"/>
+ </ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcetype" value="java" />
+ <ui:param name="openlabel" value="Loginaction.java" />
+ <ui:param name="sourcepath"
value="/richfaces/stateAPI/snippets/loginaction.java"/>
+ </ui:include>
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcetype" value="java" />
+ <ui:param name="openlabel" value="Registeraction.java"
/>
+ <ui:param name="sourcepath"
value="/richfaces/stateAPI/snippets/registeraction.java"/>
+ </ui:include>
+
+ <ui:include src="/templates/include/sourceview.xhtml">
+ <ui:param name="sourcetype" value="xml" />
+ <ui:param name="openlabel" value="faces-config beans
definitions" />
+ <ui:param name="sourcepath"
value="/richfaces/stateAPI/examples/cfg.xhtml"/>
+ </ui:include>
</div>
</fieldset>
+ <p>
+ Actually states is a map where the entry key is name of the state and value
+ is state map. Concrete state map has entries with some names as keys and
+ any objects as values. So any value or method bindings or just simple state
+ constants could be saved in State map.
+ </p>
+ <p>
+ Rich Faces state API implements states change as standard JSF navigation.
+ Action component should just return outcome and our extension for JSF
+ navigation handler will check if this outcome registered as state change
+ outcome. If such state change outcome found - corresponding state will be
+ activated and in other case - it will call standard navigation handling
+ </p>
+ <p>
+ There is is more detailed explanation how configure and use Rich Faces states
+ mechanism in JSF application in details tab.
+ </p>
</ui:define>
</ui:composition>
</html>
Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI.xhtml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI.xhtml 2008-07-31
13:40:14 UTC (rev 9848)
+++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI.xhtml 2008-07-31
13:46:05 UTC (rev 9849)
@@ -7,7 +7,20 @@
<ui:composition template="/templates/main.xhtml">
<ui:define name="title">RichFaces - Open Source Rich JSF Components -
State Manager</ui:define>
<ui:define name="body">
- <ui:include src="/templates/include/tab-panel.xhtml"/>
+ <rich:tabPanel switchType="server" styleClass="top_tab"
contentClass="content_tab" headerClass="header_tabs_class"
inactiveTabClass="inactive_tab" activeTabClass="active_tab"
+ selectedTab="#{componentNavigator.currentComponent.activeTab}">
+ <rich:tab label="Usage" name="usage">
+ <ui:include src="/richfaces/stateAPI/usage.xhtml"/>
+ </rich:tab>
+ <rich:tab label="Usage Details" name="details">
+ <ui:include src="/richfaces/stateAPI/examples/details.xhtml"/>
+ </rich:tab>
+ <rich:tab name="info" label="Tag Information">
+ <rich:insert
+ src="/WEB-INF/#{componentNavigator.currentComponent.tagInfoLocation}"
+ errorContent="/templates/include/tagInfoNotes.xhtml" />
+ </rich:tab>
+ </rich:tabPanel>
</ui:define>
</ui:composition>
</html>