You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Simone Gianni <s....@thebug.it> on 2006/02/27 00:27:11 UTC

Re: Cast type in flowscript [ Javaflow]

Hi Andrew,
wow, lots of questions :)

Andrew Madu wrote:

> Hi Simone,
> many thanks for your reply. Would you by any chance have an example of 
> a very simple process done in a .js and .java version? 
>
> I take it that I can still reference the java classes from my sitemap 
> as I would do the flowscripts?:
>
>
>  <map:flow language="java">
>   <map:script src="flow/login.class"/>
>  </map:flow>

Nearly. In the normal way, the class must be in classpath (so either a 
jar in WEB-INF/lib or in classes) and referenced with its fully 
qualified name, so for example <map:script 
src="com.mycompany.myproject.cart.ShoppingCartFlow"/> . This 
unfortunately means that you will have to recompile your flows and 
restart the server for each change you make.

Another approach is the compiling classloader, that compiles from source 
code, and thus avoids all the rebuild/restart problems. I haven't used 
this myself, and can't give you much help on this subject.

>
> How would I reference method calls from the site map to java methods? 
> In javascript it would be:
>
> <map:call function="terms">
> <map:parameter name="page_Name" value="account"/>
> </map:call>
>
> Would I be correct in thinking that I would do:
>
> <map:call login.user="terms">
> <map:parameter name="page_Name" value="account"/>
> </map:call>

Unfortunately no. Every method you wish to call from the sitemap must be 
public, void, with no parameters, and called doSomethingToDo. You will 
then call it from the sitemap with <map:call function="somethingToDo"/> 
. The "function name space" is flat, so if you have two methods with the 
same name in two different classes (or in two different javascripts) it 
will be a problem.

>
> How would I read the parameter into the class/method from the sitemap? 
> Like so?:
>
> private String artistID = cocoon.parameters.artistID;

Nearly : String artistID = getParameters().get("artistID");

>
> Would I pass it from the sitemap the same was as shown 
> above?: <map:parameter name="page_Name" value="account"/>

Yes, the same.

>
> What about persisting data? I have a variable which persists a user 
> object after a user has logged in:
>
> var userGlobal = cocoon.session.getAttribute("user");
>
> Would the javaflow equiv be:
>
> private Object userGlobal = cocoon.session.getAttribute("user"); ???

Hey, pay attention. In Javaflow AND in flowscript, global variabiles are 
quite dangerous : they are global in the real sense, can span different 
user sessions, you should not use them if not for singleton classes, or 
other really global data like configuration.

Also, they are not continuation-safe, so i always go for local variables :

// This is a singleton class, so no danger in using it as global.
private ShoppingCartManager cartManager = ShoppingCartManager.getInstance();

public void doSomethingToDo() {
    String user = getRequest().getSession().getAttribute("user");
    ShoppingCart cart = cartManager.findCartForUser(user);

    VarMap bizdata = new VarMap();
    bizdata.put("user", user);
   
    FormInstance fi = new FormInstance("cart.def.xml");
    fi.createBinding("cart.bnd.xml");
    fi.load(cart);
    fi.show("cart", bizdata);
    ....
}

I'm going by heart, so i apologize in advance for errors :)

>
> How do i represent forms in javaflow:
>
> var form = new Form("forms/artistOrder.xml");
> form.showForm("artistLyricsPopUp1.xml",{"artistID":artistID,"artist_name":artist_name,"artist_info":artist_info,"track_lyrics":track_lyrics,"track_title":track_title,"userGlobal":userGlobal});
> var model = form.getModel();
> var bizData = {"next" : model.next, "delItem" : model.delItem, 
> "quantity" : model.quantity}
>
See previous example.

> and finally would I be correct in thinking that continuation is still 
> represented as:
>
> cocoon.sendPageAndWait("artistDetails2.xml",{"artistID":artistID});

sure :

VarMap bizdata = new VarMap();
bizdata.put("artistID", artistID);
sendPageAndWait("artistDetails2.xml",bizdata);


>
> many thanks
>
> Andrew
>
You're welcome.

Simone

-- 
Simone Gianni

Re: Cast type in flowscript [ Javaflow]

Posted by Andrew Madu <an...@gmail.com>.
Hey Simone,

> wow, lots of questions :)

your email came through just as I sent one back ;-)

Many thanks

Andrew

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


Re: Cast type in flowscript [ Javaflow]

Posted by Simone Gianni <s....@thebug.it>.
Hi Jason,
I made a quick experiment with javaflow. Yeah, you are completely right, 
global variables DOES NOT span sessions, static ones does. They are 
initialized for each user session, and when the sitemap changes if 
sitemap gets reloaded. They are not bound to continuations, that means 
that if I initialize private int a = 1, then check a value and send a 
form, the set a = 2, if the user hits the back button "a" will still be 
2. So, they should not be used for "state" informations with a scope 
smaller than user session, but can safely be initialized with session 
values.

Sorry for saying uncorrect things, I'm sure i had problems with global 
variables spaning different sessions in flowscript back in 2.1.6 and 
thought this remained unchanged 'till now.

Simone

Jason Johnston wrote:

>Simone Gianni wrote:
>  
>
>>Hey, pay attention. In Javaflow AND in flowscript, global variabiles are
>>quite dangerous : they are global in the real sense, can span different
>>user sessions, you should not use them if not for singleton classes, or
>>other really global data like configuration.
>>    
>>
>
>I'm pretty sure this is not correct; at least in flowscript global
>variables (explicitly declared with the var keyword in global scope) are
>attached to the user session and do not span across sessions.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>  
>


Re: Cast type in flowscript [ Javaflow]

Posted by Jason Johnston <co...@lojjic.net>.
Simone Gianni wrote:
> Hey, pay attention. In Javaflow AND in flowscript, global variabiles are
> quite dangerous : they are global in the real sense, can span different
> user sessions, you should not use them if not for singleton classes, or
> other really global data like configuration.

I'm pretty sure this is not correct; at least in flowscript global
variables (explicitly declared with the var keyword in global scope) are
attached to the user session and do not span across sessions.

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


Re: Re[2]: Cast type in flowscript [ Javaflow]

Posted by Andrew Madu <an...@gmail.com>.
g[R]eK,

> newUser.setFirstName(bizData.getMap().get("fname"));

ahhhhhhhhh! I continue to cross purpose myself here ;-)

many thanks

Andrew

Re[2]: Cast type in flowscript [ Javaflow]

Posted by "g[R]eK" <gr...@crispymail.com>.
Hello Andrew!

> Hey guys,

>>     VarMap bizdata = new VarMap();
>>     bizdata.put("user", user);

> i'm doing something very silly here but can't figure it at all....

>                         VarMap bizData = new VarMap()
>                         .add("fname", model.lookupWidget("fname").getValue());
>                         
>                         ......
>                         newUser.setFirstName(bizData.fname);

It's java, so you have forget about all magic you used to have in flowscript ;-)
Try:
newUser.setFirstName(bizData.getMap().get("fname"));
and take a look at:
http://cocoon.apache.org/2.1/apidocs/org/apache/cocoon/components/flow/java/VarMap.html

HTH

-- 
 g[R]eK


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


Re: Cast type in flowscript [ Javaflow]

Posted by Andrew Madu <an...@gmail.com>.
Hey guys,

>     VarMap bizdata = new VarMap();
>     bizdata.put("user", user);

i'm doing something very silly here but can't figure it at all....

			VarMap bizData = new VarMap()
			.add("fname", model.lookupWidget("fname").getValue());
			
			......
			newUser.setFirstName(bizData.fname);

This gives me bizData.fname cannot be resolved or is not a field.  
What am I doing wrong?

many thanks

Andrew

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


Re: Cast type in flowscript [ Javaflow]

Posted by Simone Gianni <s....@thebug.it>.
Hi Andrew,
yeah, sorry, you have to explictly cast it :

Form model = (Form)fi.getModel();

Simone

Andrew Madu wrote:

>  Simone,
>
>> Form form = fi.getModel();
>
>
> this incorrect as I get a 'Type mismatch: cannot convert from widget  
> to form' error. What is the issue here?:
>
>             FormInstance fi = new FormInstance("forms/register.xml");
>             fi.show("register1.xml", new VarMap()
>                     .add("msg",Registermsg)
>                     .add("newOrderReg2",neworderreg2));
>            
>             Form model = fi.getModel();
>
> many thanks
>
> Andrew
>
>
>
> ---------------------------------------------------------------------
> 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: Cast type in flowscript [ Javaflow]

Posted by Andrew Madu <an...@gmail.com>.
  Simone,

> Form form = fi.getModel();

this incorrect as I get a 'Type mismatch: cannot convert from widget  
to form' error. What is the issue here?:

			FormInstance fi = new FormInstance("forms/register.xml");
			fi.show("register1.xml", new VarMap()
					.add("msg",Registermsg)
					.add("newOrderReg2",neworderreg2));
			
			Form model = fi.getModel();

many thanks

Andrew



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


Re: Cast type in flowscript [ Javaflow]

Posted by Simone Gianni <s....@thebug.it>.
Andrew Madu wrote:

>
> sorry for being a pain but i'm still not clear about the form 
> implementation.
>
> var form = new Form("forms/register.xml");
> form.showForm("register1.xml", {"msg":Registermsg, "newOrderReg2" : 
> neworderreg2});
>
> becomes:
>
> FormInstance fi = new FormInstance("forms/register.xml");
>
> fi.createBinding("register1.xml",new VarMap()
> .add("msg":Registermsg)
> .add("newOrderReg2" : neworderreg2);

Nope. You have 2 files for each form, a definition and a template. 
Optionally you can have a binding. Also, you need a pipe in the sitemap 
to show the form. In javascript you use :

var form = new Form("definition");
form.showForm("pipe", {"key: variable});

in this case, you are not using a binding. So, this in javaflow is :

FormInstance fi = new FormInstance("definition");
fi.show("pipe", new VarMap().add("key", variable));

The fi.createBinding is used to assign a binding to the form instance. 
fi.load is used once you have a binding to "transfer" values from  a 
bean or xml document to widget fields, while fi.save transfers values 
from the form widgets to the bean or document.

> ---------------------------------------------------   
>                
> var model = form.getModel();
>
> becomes:
>
> fi.getModel model = fi.getModel(); ????

fi.getModel() returns a org.apache.cocoon.forms.formmodel.Form, that is 
the underlying form object. So you can do :

Form form = fi.getModel();
form.lookupWidget(.....).getValue();
etc..etc..

>
> many thanks 
>
> Andrew
>
Simone

-- 
Simone Gianni

Re: Cast type in flowscript [ Javaflow]

Posted by Andrew Madu <an...@gmail.com>.
Hi Simone,

>     FormInstance fi = new FormInstance("cart.def.xml");
>     fi.createBinding("cart.bnd.xml");
>     fi.load(cart);
>     fi.show("cart", bizdata);

sorry for being a pain but i'm still not clear about the form  
implementation.

var form = new Form("forms/register.xml");
form.showForm("register1.xml", {"msg":Registermsg, "newOrderReg2" :  
neworderreg2});

becomes:

FormInstance fi = new FormInstance("forms/register.xml");

fi.createBinding("register1.xml",new VarMap()
.add("msg":Registermsg)
.add("newOrderReg2" : neworderreg2);
---------------------------------------------------

var model = form.getModel();

becomes:

fi.getModel model = fi.getModel(); ????

many thanks

Andrew