cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Oliver <res1c...@verizon.net>
Subject Releasing components in a flow script (was Re: Best practice for "database" manipulation?)
Date Wed, 18 Feb 2004 05:21:56 GMT
Bastian Breithaupt wrote:

>Hello:
>
>  
>
>>If the logic is contained in avalon components, you'd need to obtain 
>>them first (AFAIR cocoon.newInstance(MYCOMPONENT.ROLE)) and release them
>>afterwards. Remember to release components before creating a 
>>continuation, though.
>>    
>>
>
>I have a flow script:
>
>       var facade = cocoon.getComponent( Packages.....ROLE );
>	
>	var cmd = cocoon.request.getParameter("cmd");
>	
>	if ( cmd == "soSomething" ) {
>		doSomething( facade , form );
>                form.finish("page/admin.xsp");
>
>	} else {
>		cocoon.sendPageAndWait("page/admin.xsp");	
>	}
>
>The Avalon component is a business facade which sends messages to the logic and delivers
objects to the GUI. Where in this script do I have to realease the component (and how?) ?
>  
>

You release a component like this:
  
     cocoon.releaseComponent(facade);

If you are using Woody you (currently) must do this before calling 
form.showForm(). In 2.1.4 with cocoon.sendPageAndWait() you can pass a 
function that will be called after pipeline processing but before the 
script is suspended (see the docs), like this:

var component = null;
try {
   component = cocoon.getComponent(...);
   // do something with component...
   cocoon.sendPageAndWait("page/admin.xsp", function() {
      cocoon.releaseComponent(component);
      component = null;
  });
} finally {
  if (component != null) {
    cocoon.releaseComponent(component);
  }
}

As regards Woody, the CVS version has experimental version of its 
flowscript API (with a sample) that allows you to set a "bookmark" in 
your script that will be returned to each time the form is redisplayed 
(for example during validation). This allows you to acquire resources 
needed to populate the form or otherwise needed by your pipeline each 
time the form is displayed. In addition, it takes an additional function 
argument like sendPageAndWait() where you can release those resources. 
For example like this:

 function showForm() {
        var uri = ...;
        var form = new Form("form-definition.xml"):

    form.setBookmark();  // <-- your script will resume here if validation fails or an
action is invoked
    var facade = null;
    try {
       facade = cocoon.getComponent( Packages.....ROLE );
       ...
       form.showForm("form-template.xml", function() {
          cocoon.releaseComponent(facade);
          facade = null;
       });
    } finally {
       if (facade != null) cocoon.releaseComponent(facade);
    }
}    



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message