You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by "Robert Simmons Jr." <kr...@arcor.de> on 2004/10/07 01:55:50 UTC

Flow Control using Java and not JavaScript?

I was reading the flow ontrol documentation and I am uncomfortable with the 
whole idea of doing my app mostly in javascript. Would it be possible to do 
flow control with just java itself? That would be cool and much easier to 
debug.

-- Regards
-- Robert Simmons Jr.

Author: Hardcore Java, Published March 2004 by O'Reilly
http://www.oreilly.com/catalog/hardcorejv/ 




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


Re: Flow Control using Java and not JavaScript?

Posted by Ugo Cei <u....@cbim.it>.
John L. Webber wrote:
> We have a lot of flowscripts that typically assemble request parameters 
> and information from the session and then create new Java objects which 
> are sent to "createX" or "saveX" methods on DAO objects. These functions 
> are usually around 20 lines of code, sometimes longer. In theory we 
> could delegate these to Java objects, but if we pass in the request 
> object then the Java objects would need to know about Javascript to 
> unwrap the request. Here's an example of one of our flowscript functions:
<snip/>
> Do you think this is too much logic for a flowscript function? If so, 
> how would you deal with it?

No, I don't think there's much logic there at all. It's a bit verbose 
though. You might try defining a Javascript-aware helper Java class, 
pass the request and/or session to its constructor, have it unwrap them, 
extract the needed parameters and store them in fields. Then pass the 
instance of the helper to your business methods.

If you don't want your business objects to depend on the helper's 
implementation, you can have the latter implement an interface that 
declares only the getters. Thus, you get also the benefit that you can 
now unit test your business methods by passing them a mock 
implementation of the interface.

This amounts to a "Parameter Object" kind of pattern (see Martin Fowler, 
"Refactoring", pp. 295). I wouldn't recommend it if you only have a 
handful of parameters, but if you have more, it can be useful. It also 
might help when some parameters are required to have default values, 
unless some specific value is indicated in the request. You can just 
initialize the parameter object with default values at construction time.

To sum it up: the Parameter Object would have to depend on Javascript, 
but you can hide this dependency behind an interface.

Hope this helps,

	Ugo

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


Re: Flow Control using Java and not JavaScript?

Posted by "John L. Webber" <Jo...@jentro.com>.
We have a lot of flowscripts that typically assemble request parameters 
and information from the session and then create new Java objects which 
are sent to "createX" or "saveX" methods on DAO objects. These functions 
are usually around 20 lines of code, sometimes longer. In theory we 
could delegate these to Java objects, but if we pass in the request 
object then the Java objects would need to know about Javascript to 
unwrap the request. Here's an example of one of our flowscript functions:

function doAddNormalCallEntry() {
   var callDialog = null;
   var callData = null;
   importPackage (Packages.com.jentro.manager.callcenter.serverapi );
   var roleData = getUserRoleData();
   var callStarted = cocoon.session.getAttribute("prepared-call-date");
   var customerId = cocoon.session.getAttribute("current-user-id");
   var message = getParameter("call");
   var callEntry = new CallEntryData();
   callEntry.setMessage(	message );
   callEntry.setStarted( new Packages.java.util.Date() );
   callEntry.setColor( 
Packages.com.jentro.manager.callcenter.CallEntryColorCode.BLACK );
   try {
     callDialog = lookup( CallCenterHistoryDialog.ROLE );		
     callData = callDialog.addCallEntry( roleData, callStarted, 
customerId, callEntry );
   }
   catch (exception) {
      setError( exception);
   }
   finally {
      release( callDialog );
   }
}

Do you think this is too much logic for a flowscript function? If so, 
how would you deal with it?

John

Ugo Cei wrote:

> Look at the Javaflow block for this, but if I were you, I would 
> reconsider this choice. The "proper" way of using flowscript is only as 
> a means to script the flow of pages and you should tuck away all 
> business logic inside Java objects. It is certainly *not* recommended to 
> do your app "mostly in javascript".
> 
> If you are coming to the GT, my talk on Tuesday will also deal with 
> proper ways of partitiong application logic in a Cocoon application.


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


Re: Flow Control using Java and not JavaScript?

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 07/ott/04, alle 01:55, Robert Simmons Jr. ha scritto:

> I was reading the flow ontrol documentation and I am uncomfortable 
> with the
> whole idea of doing my app mostly in javascript. Would it be possible 
> to do
> flow control with just java itself? That would be cool and much easier 
> to
> debug.

Look at the Javaflow block for this, but if I were you, I would 
reconsider this choice. The "proper" way of using flowscript is only as 
a means to script the flow of pages and you should tuck away all 
business logic inside Java objects. It is certainly *not* recommended 
to do your app "mostly in javascript".

If you are coming to the GT, my talk on Tuesday will also deal with 
proper ways of partitiong application logic in a Cocoon application.

	Ugo

-- 
Ugo Cei - http://beblogging.com/

Re: Flow Control using Java and not JavaScript?

Posted by Ralph Goers <Ra...@dslextreme.com>.
Robert Simmons Jr. wrote:

>I was reading the flow ontrol documentation and I am uncomfortable with the 
>whole idea of doing my app mostly in javascript. Would it be possible to do 
>flow control with just java itself? That would be cool and much easier to 
>debug.
>
>  
>
You can use Javaflow.  It isn't as robust but it does work.


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


Re: Flow Control using Java and not JavaScript?

Posted by Bertrand Delacretaz <bd...@apache.org>.
> ...Would it be possible to do
> flow control with just java itself? That would be cool and much easier 
> to
> debug...

It is possible but still experimental - have a look at the javaflow 
block.

OTOH the use javascript is fairly limited in terms of lines of code in 
a typical app, and a flowscript debugger is available, see 
http://wiki.apache.org/cocoon/DebugFlowScripts

-Bertrand

Re: Flow Control using Java and not JavaScript?

Posted by "Robert Simmons Jr." <kr...@arcor.de>.
Python woudl be preferable for me as well. I have to say that I dont like 
javascript much.

-- Robert

"Patrick Verboom" <pa...@juwimm.com> wrote in message 
news:4164F103.3090909@juwimm.com...
> Hi,
>
> I tried running flows in java on a bea Weblogic 6.1 without success. The 
> java code worked fine on a tomcat.
> Java is much more work than javascript. Using Javascript for the flows was 
> something i didn't like either.
> Now after written a couple of flowscripts in javascript i changed my mind. 
> I still don't like Javascript but using a script language for the flow is 
> a good idea (i prefer to write them in another script language like 
> python/jython but there is no continuation support jet).
> There is a fine javascript debugger in cocoon. you can turn it on by.
> do the following
>
> open the cocoon.xconf file it is located in the cocoon WEB-INF directory.
>
> look for the following code
> <flow-interpreters default="javascript" logger="flow">
>    <!-- FOM (Flow Object Model) -->
>    <component-instance 
> class="org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter" 
> name="javascript">
> 
> <load-on-startup>resource://org/apache/cocoon/components/flow/javascript/fom/fom_system.js</load-on-startup>
>      <reload-scripts>true</reload-scripts>
>      <check-time>4000</check-time>
>      <!--  <debugger>enabled</debugger> -->  <!-- JavaScript Debugger 
> support -->
>    </component-instance>
>  <!--..... Start configuration from 'javaflow' -->
>
> remove the comments from <!--  <debugger>enabled</debugger> -->
>
> kind regards,
> Patrick Verboom
>
>
>
> Robert Simmons Jr. wrote:
>
>>I was reading the flow ontrol documentation and I am uncomfortable with 
>>the whole idea of doing my app mostly in javascript. Would it be possible 
>>to do flow control with just java itself? That would be cool and much 
>>easier to debug.
>>
>>-- Regards
>>-- Robert Simmons Jr.
>>
>>Author: Hardcore Java, Published March 2004 by O'Reilly
>>http://www.oreilly.com/catalog/hardcorejv/
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>For additional commands, e-mail: users-help@cocoon.apache.org
>>
>> 




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


Re: Flow Control using Java and not JavaScript?

Posted by Patrick Verboom <pa...@juwimm.com>.
Hi,

I tried running flows in java on a bea Weblogic 6.1 without success. The 
java code worked fine on a tomcat.
Java is much more work than javascript. Using Javascript for the flows 
was something i didn't like either.
Now after written a couple of flowscripts in javascript i changed my 
mind. I still don't like Javascript but using a script language for the 
flow is a good idea (i prefer to write them in another script language 
like python/jython but there is no continuation support jet). 

There is a fine javascript debugger in cocoon. you can turn it on by.
do the following

open the cocoon.xconf file it is located in the cocoon WEB-INF directory.

look for the following code
<flow-interpreters default="javascript" logger="flow">
    <!-- FOM (Flow Object Model) -->
    <component-instance 
class="org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter" 
name="javascript">
      
<load-on-startup>resource://org/apache/cocoon/components/flow/javascript/fom/fom_system.js</load-on-startup>
      <reload-scripts>true</reload-scripts>
      <check-time>4000</check-time>
      <!--  <debugger>enabled</debugger> -->  <!-- JavaScript Debugger 
support -->
    </component-instance>
  <!--..... Start configuration from 'javaflow' -->

remove the comments from <!--  <debugger>enabled</debugger> -->

kind regards,
Patrick Verboom



Robert Simmons Jr. wrote:

>I was reading the flow ontrol documentation and I am uncomfortable with the 
>whole idea of doing my app mostly in javascript. Would it be possible to do 
>flow control with just java itself? That would be cool and much easier to 
>debug.
>
>-- Regards
>-- Robert Simmons Jr.
>
>Author: Hardcore Java, Published March 2004 by O'Reilly
>http://www.oreilly.com/catalog/hardcorejv/ 
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>  
>



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