1 Reply Latest reply on Apr 19, 2007 8:47 PM by Sergey Smirnov

    Howto use Spring Web Flow in the a4j-include example?

    Thai Dang Vu Apprentice

      I'm sorry that I ask a question about Spring Web Flow here. If you've ever rewritten the a4j-include example http://livedemo.exadel.com/a4j-include/ using Spring Web Flow, could you please share it to me?

      The reasons I want to use SWF are:
      - SWF has a conversational scope. I think a4j:keepAlive can do this (in fact, I'm using a4j:keepAlive, but see some unexpected results that I will post here after debugging my application thoroughly).
      - SWF allows us to go to a particular page if a particular exception occurs (I don't know how to do that with JSF).
      - One more problem with a4j:keepAlive is that it requires that everything in the JSF-managed bean must be serializable. I want to use Spring DelegatingVariableResolver to inject some services into the JSF-managed bean so that for a particular action in the JSF bean, I can use those services to persist the JSF bean. So if I have those services in the JSF bean, I cannot use a4j:keepAlive because those services are not serializable. Then I have to use Spring FacesContextUtils.

      Could you please check if I design my app correctly?
      - My JSF bean is in the request. It has those properties: id and name.
      - My xhtml page looks like this:

      <h:form>
       <h:inputText value="#{mybean.name}" />
       <a4j:commandButton value="Create & Save this bean" action="#{mybean.create}" />
      </h:form>
      

      public class Mybean {
       // .... properties
       public String create() {
       Mybean persistedBean = jpaService.save(this);
       FacesContext.getCurrentInstance().getELContext().getELResolver().setValue(context.getELContext(), null, "mybean", persistedBean); // explanation for this line below
       }
      }
      

      Explanation: when a jpaService persists an object, it doesn't change the id property of that object. It creates another object with the id property value populated from a sequence (in my case). Here I have 2 options:
      1. copy the id from the persistedBean to the jsf bean
      2. or replace the jsf bean in the request scope with this persistedBean (that's what I did in the above code).

      If I choose option 1, then if I have to pass this jsf bean to another page for editing, then I have to explicitly write jpaService.save(this) after editing (because that jsf bean is not persisted).
      If I choose option 2, then I don't need to call jpaService.save(this), because this jsf bean is persisted already, so any change made to it will be save in the database finally.

      I don't know which option I should choose. Do you have any idea?

      PS: don't forget my question if you have a Spring Web Flow version for the a4j-include example :)