Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Spring Webflow 2 Working With Persistent Conversation Data

  1. #11

    Default

    Misha79, Iīm happy that itīs working for you, at least partially! It seems you are closer, just a little more work on it and it will be working 100%.

    Well first of all take care about mixing different versions of a same librarie, is not a good practice and perhaps it could have and unexpected behavior in terms of I believe you can't be fully sure of the classloader will load always load the classes of the same librarie, unless you configure it explicitly. I'm not totally sure about that, but it is only an advice.

    About the error you are talking about, as far as I remember I believe I got the same error when I was implementing the solution. It happens because SWF canīt find a conversation that is suposed to exist. Probably in your scenario it is happening because the code you posted is still incomplete; your conversation manager is trying to load a conversation previously created but the method readConversation(ConversationId id) is always returning null.

    You must complete the code of your CustomPersistentConversationHelper, otherwise it will never work!! I will post my code for the same class tomorrow when I come back to work, please remember me with a private message if I don't do it, I can easily forget it hehehe

    Regards and good weekend.

  2. #12

    Default

    Well this is the code of the PersistentConversationHelper:

    Code:
    @Component
    public class PersistentConversationHelper {
    
    	private static WebFlowConversationsBo webFlowConversationsBo;
    	
    	@Autowired
    	public PersistentConversationHelper(WebFlowConversationsBo webFlowConversationsBo) {
    		PersistentConversationHelper.webFlowConversationsBo = webFlowConversationsBo;
    	}
    	
    	public static void createConversation(PersistentConversation conv) {
    		webFlowConversationsBo.save(new WebFlowConversation(conv.getIdAsString(), conv.getAttributesAsByteArray()));
    	}
    	
    	public static WebFlowConversation readConversation(ConversationId id) {
    		return webFlowConversationsBo.findOne(id.toString());
    	}
    	
    	public static void updateConversation(PersistentConversation conv) {
    		webFlowConversationsBo.save(new WebFlowConversation(conv.getIdAsString(), conv.getAttributesAsByteArray()));
    	}
    	
    	public static void deleteConversation(ConversationId id) {
    		webFlowConversationsBo.delete(id.toString());
    	}
    }
    As you can see, it doesn't have anything special, just a business object invocation. Then, the BO invokes a DAO which has the same methods and arguments which perform CRUD operations. Note that I'm using JPA 2 with Hibernate 3 and Spring Data. It is really up to you which technology use for DB interaction, just have in mind that basically in every scenario is nothing else but methods that execute CREATE, UPDATE, DELETE and SELECT queries.

    I hope it helps.

    Regards.

  3. #13

    Default

    Thanks a ton .. Alejandro .. i am going to try this code and will be back with output or questions.


    .
    Quote Originally Posted by alejandrogarciaseco View Post
    Well this is the code of the PersistentConversationHelper:

    Code:
    @Component
    public class PersistentConversationHelper {
    
    	private static WebFlowConversationsBo webFlowConversationsBo;
    	
    	@Autowired
    	public PersistentConversationHelper(WebFlowConversationsBo webFlowConversationsBo) {
    		PersistentConversationHelper.webFlowConversationsBo = webFlowConversationsBo;
    	}
    	
    	public static void createConversation(PersistentConversation conv) {
    		webFlowConversationsBo.save(new WebFlowConversation(conv.getIdAsString(), conv.getAttributesAsByteArray()));
    	}
    	
    	public static WebFlowConversation readConversation(ConversationId id) {
    		return webFlowConversationsBo.findOne(id.toString());
    	}
    	
    	public static void updateConversation(PersistentConversation conv) {
    		webFlowConversationsBo.save(new WebFlowConversation(conv.getIdAsString(), conv.getAttributesAsByteArray()));
    	}
    	
    	public static void deleteConversation(ConversationId id) {
    		webFlowConversationsBo.delete(id.toString());
    	}
    }
    As you can see, it doesn't have anything special, just a business object invocation. Then, the BO invokes a DAO which has the same methods and arguments which perform CRUD operations. Note that I'm using JPA 2 with Hibernate 3 and Spring Data. It is really up to you which technology use for DB interaction, just have in mind that basically in every scenario is nothing else but methods that execute CREATE, UPDATE, DELETE and SELECT queries.

    I hope it helps.

    Regards.

  4. #14

    Default

    One question -
    what is the difference between WebFlowConversation and PersistentConversation classes. Both are custom classes and PersistentConversation implements Conversation interface. What is the need of WebFlowConversation. I just added 2 attributes-
    Code:
    public class WebFlowConversation {
    
    	public String getId() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	public byte[] getAttributes() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    }

  5. #15

    Default

    Quote Originally Posted by Misha79 View Post
    One question -
    what is the difference between WebFlowConversation and PersistentConversation classes. Both are custom classes and PersistentConversation implements Conversation interface. What is the need of WebFlowConversation. I just added 2 attributes-
    Code:
    public class WebFlowConversation {
    
    	public String getId() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	public byte[] getAttributes() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    }
    Sorry for my late reply.

    First of all, let's talk about what both classes have in common; both WebFlowConversation and PersistentConversation represents and contains all data of conversation every conversation among different flow executions of a flow instance. The difference is in the scope each class plays its own role. In other words, WebFlowConversation is just a POJO mapped to the database table that stores the conversation data, in my case it is an JPA entity. On the other hand we have the PersistentConversation, which is created by parsing every WebFlowConversation retrieved from database and it implements org.springframework.webflow.conversation.Conversat ion, so it provides all the functionality to interact in conversations (for instance, locking and ending conversations, manage attributes, etc).

    In the original Erwin Vervaet, one of the authors of Spring Web Flow, there is only a class which represents the database entity and at the same time implements org.springframework.webflow.conversation.Conversat ion but it was my decision to split it in two different classes because in my opinion a database entity doesn't have to know anything about web layer's matters, for example, what a SWF conversation is and how to deal with it. You are free to do it whatever the way to consider better for your scenario.

    I hope I've solved your doubt.

    Regards.
    Last edited by alejandrogarciaseco; Sep 24th, 2012 at 05:26 AM.

  6. #16

    Default

    I have edited the original post, there was an important bug. The constructor of PersistentConversation should be like this:

    Code:
    	public PersistentConversation(ConversationId id, String flowName) {
    		this.id = id;
    		this.attributes = new HashMap<Object, Object>();
    		this.attributes.put("name", flowName);
    	}
    Hence, the PersistentConversationManager class is affected in the method beginConversation(ConversationParameters conversationParameters):

    Code:
    PersistentConversationHelper.createConversation(new PersistentConversation(convId, conversationParameters.getName()));
    Now the persistent conversation implementation allows as many different flows as required.

    Regards.

  7. #17

    Default

    Thank you so much Alejandro..for finding time to explain so nicely and providing me with code snippets. I been too busy & l work on this functionality this weekend and will reach you again if questions.



    Quote Originally Posted by alejandrogarciaseco View Post
    I have edited the original post, there was an important bug. The constructor of PersistentConversation should be like this:

    Code:
    	public PersistentConversation(ConversationId id, String flowName) {
    		this.id = id;
    		this.attributes = new HashMap<Object, Object>();
    		this.attributes.put("name", flowName);
    	}
    Hence, the PersistentConversationManager class is affected in the method beginConversation(ConversationParameters conversationParameters):

    Code:
    PersistentConversationHelper.createConversation(new PersistentConversation(convId, conversationParameters.getName()));
    Now the persistent conversation implementation allows as many different flows as required.

    Regards.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •