From richfaces-svn-commits at lists.jboss.org Thu Jul 31 09:46:05 2008 Content-Type: multipart/mixed; boundary="===============8884789948885405367==" MIME-Version: 1.0 From: richfaces-svn-commits at lists.jboss.org To: richfaces-svn-commits at lists.jboss.org Subject: [richfaces-svn-commits] JBoss Rich Faces SVN: r9849 - in trunk/samples/richfaces-demo/src/main/webapp/richfaces: beanValidator/examples and 3 other directories. Date: Thu, 31 Jul 2008 09:46:05 -0400 Message-ID: --===============8884789948885405367== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/exa= mples/simple.xhtml trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI.xhtml trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/usage.xh= tml Log: stateAPI sample Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/beanValida= tor/examples/simple.xhtml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/beanValidator/ex= amples/simple.xhtml 2008-07-31 13:40:14 UTC (rev 9848) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/beanValidator/ex= amples/simple.xhtml 2008-07-31 13:46:05 UTC (rev 9849) @@ -12,13 +12,19 @@ - + + + - + + + - + + + Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/exam= ples/details.xhtml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/example= s/details.xhtml (rev 0) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/example= s/details.xhtml 2008-07-31 13:46:05 UTC (rev 9849) @@ -0,0 +1,41 @@ + + + +

+ In order to use Rich Faces State Manager API you should perform next st= eps: +

+
    +
  • + Register state manager El resolver and navigation handler in faces con= fig: +

    + +

    = +
  • +
  • + Register additional application-factory in faces-config: +

    + +

    = +
  • +
  • + Register two managed beans. One should define and store states itself. = + And the other should define bean with type org.richfaces.ui.model.S= tates + and have managed property states bound to the bean which define= s states. + (Will be changed to xml declarations in future releases) +

    + +

    = +
  • +
  • + Define states in Config class. (full code example on the Usage = tab) +
  • +
  • + Use state bindings on the pages. = +
  • +
+
+ \ No newline at end of file Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snip= pets/app.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/app.xml (rev 0) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/app.xml 2008-07-31 13:46:05 UTC (rev 9849) @@ -0,0 +1,4 @@ + + org.richfaces.ui.application.StateNavigationHandler<= /navigation-handler> + org.richfaces.el.StateELResolver + Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snip= pets/appfact.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/appfact.xml (rev 0) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/appfact.xml 2008-07-31 13:46:05 UTC (rev 9849) @@ -0,0 +1,3 @@ + + org.richfaces.ui.application.StateApplicationFactor= y + Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snip= pets/bean.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/bean.java (rev 0) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/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 =3D name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password =3D password; + } + + public String getConfirmPassword() { + return confirmPassword; + } + + public void setConfirmPassword(String confirmPassword) { + this.confirmPassword =3D confirmPassword; + } + +} \ No newline at end of file Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snip= pets/beans.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/beans.xml (rev 0) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/beans.xml 2008-07-31 13:46:05 UTC (rev 9849) @@ -0,0 +1,15 @@ + + state + org.richfaces.ui.model.States + request + + states + org.richfaces.ui.model.States + #{config.states} + + + + config + org.richfaces.demo.stateApi.Config + none + \ No newline at end of file Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snip= pets/cfg.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/cfg.xml (rev 0) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/cfg.xml 2008-07-31 13:46:05 UTC (rev 9849) @@ -0,0 +1,30 @@ + + loginbean + org.richfaces.demo.stateApi.Bean + request + + + registerbean + org.richfaces.demo.stateApi.Bean + request + + + loginaction + org.richfaces.demo.stateApi.LoginAction + request + + bean + org.richfaces.demo.stateApi.Bean + #{loginbean} + + + + registeraction + org.richfaces.demo.stateApi.RegisterAction + request + + bean + org.richfaces.demo.stateApi.Bean + #{registerbean} + + \ No newline at end of file Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snip= pets/config.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/config.java (rev 0) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/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 =3D FacesContext.getCurrentInstance(); + States states =3D 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 =3D facesContext.getApplication() + .getExpressionFactory(); + + // Define "registerbean" available under "bean" EL binding on the page + ValueExpression beanExpression =3D expressionFactory + .createValueExpression(facesContext.getELContext(), + "#{registerbean}", Bean.class); + states.put("bean", beanExpression); + + // Define "registeraction" available under "action" EL binding on the + // page + beanExpression =3D expressionFactory.createValueExpression(facesContext + .getELContext(), "#{registeraction}", RegisterAction.class); + states.put("action", beanExpression); + + // Define method expression inside registeraction binding for this state + MethodExpression methodExpression =3D 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 =3D expressionFactory.createValueExpression(facesContext + .getELContext(), "#{loginbean}", Bean.class); + states.put("bean", beanExpression); + + beanExpression =3D expressionFactory.createValueExpression(facesContext + .getELContext(), "#{loginaction}", LoginAction.class); + states.put("action", beanExpression); + + methodExpression =3D 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/snip= pets/loginaction.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/loginaction.java (rev 0) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/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 =3D bean; + } +} = \ No newline at end of file Added: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snip= pets/registeraction.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/registeraction.java (rev 0) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/snippet= s/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()=3D=3Dnull){ + return "registered"; + }else{ + return null; + } + } + = + public Bean getBean() { + return bean; + } + + public void setBean(Bean bean) { + this.bean =3D bean; + } + +} \ No newline at end of file Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/u= sage.xhtml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/usage.x= html 2008-07-31 13:40:14 UTC (rev 9848) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI/usage.x= html 2008-07-31 13:46:05 UTC (rev 9849) @@ -13,17 +13,106 @@ }

- Description + Rich Faces State API allows easily define some set of states for the p= ages and any = + properties sets for this states. =

+

+ 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 cou= ld define + inputs values, controls labels and actions, rendering conditions and e= tc = + using the same state variables which will have different values for ev= ery state. = +

+

+ Next small example panel = + has two states: login and register. Lets list the change= s between + login and register. = +

+ +

+ Also there should be a link which will switch states from login to reg= ister +

+

+ Now try the example itself before further explanations. +

Title
+ = = + + + + = + + + + = + + + + = + = + + + + + = + + + + + = + + + + + = + + + + + = + + + + + + =
+

+ 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 a= nd = + any objects as values. So any value or method bindings or just simple = state + constants could be saved in State map. = +

+

+ Rich Faces state API implements states change as standard JSF navigati= on. + Action component should just return outcome and our extension for JSF = + navigation handler will check if this outcome registered as state chan= ge = + outcome. If such state change outcome found - corresponding state will= be = + activated and in other case - it will call standard navigation handlin= g = +

+

+ There is is more detailed explanation how configure and use Rich Faces= states = + mechanism in JSF application in details tab. = +

Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI.x= html =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI.xhtml 2= 008-07-31 13:40:14 UTC (rev 9848) +++ trunk/samples/richfaces-demo/src/main/webapp/richfaces/stateAPI.xhtml 2= 008-07-31 13:46:05 UTC (rev 9849) @@ -7,7 +7,20 @@ RichFaces - Open Source Rich JSF Components - S= tate Manager - + + + + = + + + = + + + = + --===============8884789948885405367==--