Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JBoss User Help »

[jboss-user] [JBoss Seam] - A suggested SeamTest improvement

scott.stark@jboss.org

2007-07-12


I spent some time debugging one of my tests, trying to figure out why the conversation wasn't being propagated. I had something (very roughly) like this:


|
|    String cid = new FacesRequest("/page1.xhtml") {
|      @Override
|      protected void invokeApplication() throws Exception {
|        Manager.instance().beginConversation();
|        FacesManager.instance().redirect("/page2.xhtml");
|      }
|      
|    }.run();
|    
|    cid = new FacesRequest("/page2.xhtml", cid) {
|      @Override
|      protected void invokeApplication() {
|        assert Manager.instance().isLongRunningConversation();
|      }
|    }.run();
|

But the assertion fails, which I learned has to do with the fact that there was nothing rendered in the first request. So, I can fix it by doing this:


|
|    String cid = new FacesRequest("/page1.xhtml") {
|      @Override
|      protected void invokeApplication() throws Exception {
|        Manager.instance().beginConversation();
|         FacesManager.instance().redirect("/page2.xhtml");
|      }
|      
|    }.run();
|    
|    cid = new NonFacesRequest("/page2.xhtml", cid) {
|    }.run();
|    
|    cid = new FacesRequest("/page2.xhtml", cid) {
|      @Override
|      protected void invokeApplication() {
|        assert Manager.instance().isLongRunningConversation();
|      }
|    }.run();
|

But it annoys me to have that empty request in there. So, it'd be nice to have something like this:


|    String cid = new FacesRequestAndRedirect("/page1.xhtml", null, "/page2.xhtml") {
|      @Override
|      protected void invokeApplication() throws Exception {
|        Manager.instance().beginConversation();
|         FacesManager.instance().redirect(getRedirectedTo());
|      }
|      
|      @Override
|      public void renderAfterRedirect() throws Exception {
|        assert Manager.instance().isLongRunningConversation();
|      }
|    }.run();
|    
|    cid = new FacesRequest("/page2.xhtml", cid) {
|      @Override
|      protected void invokeApplication() throws Exception {
|        assert Manager.instance().isLongRunningConversation();
|      }
|    }.run();
|

And it turns out that I could make it happen with this convolution:

|
|  public class FacesRequestAndRedirect extends FacesRequest {
|    
|    private String redirectedTo;
|
|    public FacesRequestAndRedirect() {
|      super();
|    }
|    
|    public FacesRequestAndRedirect(String viewId, String conversationId) {
|      super(viewId, conversationId);
|    }
|
|    public FacesRequestAndRedirect(String viewId) {
|      super(viewId);
|    }
|
|    public FacesRequestAndRedirect(String viewId, String conversationId, String redirectedTo) {
|      super(viewId, conversationId);
|      setRedirectedTo(redirectedTo);
|    }
|    
|    @Override
|    public final void renderResponse() throws Exception {
|
|    }
|    
|    public void renderAfterRedirect() throws Exception {
|      
|    }
|    
|    public String getRedirectedTo() {
|      return redirectedTo;
|    }
|    
|    public void setRedirectedTo(String redirectedTo) {
|      this.redirectedTo = redirectedTo;
|    }
|    
|    @Override
|    public String run() throws Exception {
|      String cid = super.run();
|      
|      cid = new NonFacesRequest(getRedirectedTo(), cid) {
|      
|        @Override
|        protected void renderResponse() throws Exception {
|          renderAfterRedirect();
|        }
|      }.run();
|      return cid;
|    }
|  }
|

So, I haven't used it or thought about it much, but it might be worth putting something like this into Seam. Any thoughts?



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4063325#4063325

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4063325
_______________________________________________
jboss-user mailing list
jboss-user@(protected)
https://lists.jboss.org/mailman/listinfo/jboss-user
©2008 junlu.com - Jax Systems, LLC, U.S.A.