You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Josema Alonso <al...@aafunky.com> on 2002/11/05 18:21:22 UTC

how to manage several XMLForms in a sitemap? (it was: dynamically choosing an action at runtime)

Well, after reading replies to my emails I have a better idea of wht to do
and unfortunately not a chance to do it.
I explain it.

A quick summary. I would like to manage many XMLForms in my sitemap. I would
like to declare a pipeline like this:
  <!-- XMLForms pipeline -->
  <map:pipeline>
   <map:match pattern="*">
    <map:act type="{1}Action">
     <!-- XMLForm parameters for the AbstractXMLFormAction -->
     <map:parameter name="xmlform-validator-schema-ns"
value="http://www.ascc.net/xml/schematron"/>
     <map:parameter name="xmlform-validator-schema"
value="schematron/equipment-type-sch-report.xml"/>
     <map:parameter name="xmlform-id" value="form-insert"/>
     <map:parameter name="xmlform-scope" value="session"/>
     <map:parameter name="xmlform-model"
value="net.josema.xmtrader.forms.xmldb.recordings.equipment.{1}Bean"/>
     <!-- original XMLForm document -->
     <map:generate src="{page}.xml"/>
     <!-- populating the document with model instance data -->
     <map:transform type="xmlform" label="debug, xml"/>
     <!-- personalizing the look and feel of the form controls  -->
     <map:transform src="styles/wizard2html.xsl"/>
     <!-- Transforming the XMLForm controls to HTML controls -->
     <map:transform src="styles/xmlform2html.xsl"/>
     <!-- sending the HTML back to the browser -->
     <map:serialize type="html"/>
    </map:act>
   </map:match>
  </map:pipeline>

For individual hard coded actions I have it working, but I do not want to
repeat those lines for every form I must configure. The conflicting line is
this one:
<map:act type="{1}Action">

It is not possible to specify the Action at runtime.

I searched through the mail archives and got some replies yesterday and
everything points into the direction mentioned at this message:
http://marc.theaimsgroup.com/?l=xml-cocoon-users&m=102870549825076&w=2

So, an Action Dispatcher (or call it Proxy Action or whatever) is needed so
the action could be choosed at runtime. Unfortunately this involves working
with Avalon components and I have no idea about them. I tried their white
paper at their website but it is too hard for me to understand at this
point...

So, the thing is, has anybody developed a component like this? If so,
please, could you share it?
I believe it's very easy to make one for someone with a good knowledge of
Avalon, hope someone could help me on this. I'm almost there with my
XMLForms<->Xindice application and I'd love to share my experiences once
finished.

Thanks you very much to all.


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: how to manage several XMLForms in a sitemap? (it was: dynamically choosing an action at runtime)

Posted by Christian Haul <ha...@informatik.tu-darmstadt.de>.
Josema Alonso wrote:
> So, an Action Dispatcher (or call it Proxy Action or whatever) is needed so
> the action could be choosed at runtime. Unfortunately this involves working
> with Avalon components and I have no idea about them. I tried their white
> paper at their website but it is too hard for me to understand at this
> point...
> 
> So, the thing is, has anybody developed a component like this? If so,
> please, could you share it?

Josema, look for a component called AbstractMultiAction, 
PrincipalMultiAction or the like. I believe it can be found in scratchpad

	Chris.

-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
     fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: how to manage several XMLForms in a sitemap? (it was: dynamically choosing an action at runtime)

Posted by Josema Alonso <al...@aafunky.com>.
> Just open org.apache.cocoon.samples.xmlform.WizardAction.java
> then look more carefully in webapp/samples/xmlform

I did but haven't found anything new...any tips?
I see in the sitemap the WizardAction and the UsageFeedbackAction declared
and a hardcoded pipeline for each one. I would not like to hardcode dozens
of pipelines for everyone of my forms...I'll try any of the suggestions you
gave me when I have some time. Thanks.




---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: how to manage several XMLForms in a sitemap? (it was: dynamically choosing an action at runtime)

Posted by Ivelin Ivanov <iv...@apache.org>.
----- Original Message -----
From: "Josema Alonso" <al...@aafunky.com>
To: <co...@xml.apache.org>
Sent: Saturday, November 09, 2002 5:35 PM
Subject: Re: how to manage several XMLForms in a sitemap? (it was:
dynamically choosing an action at runtime)


> > I am not sure if I would do this like you did.
> > There are is a certain lifecycle contract between every Cocoon component
> and
> > the container.
> > By invoking directly you may be violating this contract.
> > I would probably let the sitemap do the forwarding to actions.
> > In your case action sets might be good.
> > http://xml.apache.org/cocoon/userdocs/concepts/actions.html
> I considered them and maybe I'll use them. I'm trying to make a good
> decision.
>
> > Alternatively you can use one dispatcher action which inherits from
> > AbstractXMLFormAction and works directly with the backend based on the
> > requested command.
> I see. Someone pointed this one, too, but I'm that Avalon savvy to
implement
> something like this currently.

Just open org.apache.cocoon.samples.xmlform.WizardAction.java

then look more carefully in webapp/samples/xmlform

>
> > Yet another alternative is for the extending action to return an
> objectmodel
> > parameter which is matched later in the sitemap.
> > <map:action type="myxmlformaction">
> >   ...
> >   <map:call src="cocoon:{whichaction}">
> This one sounds new, interesting and easy to code. I'll give it a try :-)
>
> Thank you very much.
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: how to manage several XMLForms in a sitemap? (it was: dynamically choosing an action at runtime)

Posted by Josema Alonso <al...@aafunky.com>.
> I am not sure if I would do this like you did.
> There are is a certain lifecycle contract between every Cocoon component
and
> the container.
> By invoking directly you may be violating this contract.
> I would probably let the sitemap do the forwarding to actions.
> In your case action sets might be good.
> http://xml.apache.org/cocoon/userdocs/concepts/actions.html
I considered them and maybe I'll use them. I'm trying to make a good
decision.

> Alternatively you can use one dispatcher action which inherits from
> AbstractXMLFormAction and works directly with the backend based on the
> requested command.
I see. Someone pointed this one, too, but I'm that Avalon savvy to implement
something like this currently.

> Yet another alternative is for the extending action to return an
objectmodel
> parameter which is matched later in the sitemap.
> <map:action type="myxmlformaction">
>   ...
>   <map:call src="cocoon:{whichaction}">
This one sounds new, interesting and easy to code. I'll give it a try :-)

Thank you very much.


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: how to manage several XMLForms in a sitemap? (it was: dynamically choosing an action at runtime)

Posted by Ivelin Ivanov <iv...@apache.org>.
I am not sure if I would do this like you did.
There are is a certain lifecycle contract between every Cocoon component and
the container.
By invoking directly you may be violating this contract.
I would probably let the sitemap do the forwarding to actions.
In your case action sets might be good.
http://xml.apache.org/cocoon/userdocs/concepts/actions.html


Alternatively you can use one dispatcher action which inherits from
AbstractXMLFormAction and works directly with the backend based on the
requested command.
Yet another alternative is for the extending action to return an objectmodel
parameter which is matched later in the sitemap.

<map:action type="myxmlformaction">
  ...
  <map:call src="cocoon:{whichaction}">


Ivelin



----- Original Message -----
From: "Josema Alonso" <al...@aafunky.com>
To: "Cocoon-Users" <co...@xml.apache.org>
Sent: Thursday, November 07, 2002 11:53 AM
Subject: Re: how to manage several XMLForms in a sitemap? (it was:
dynamically choosing an action at runtime)


> Well, this is a followup to my previous message regarding this subject.
> I coded the Dispatcher, but I must say I didn't know what I was doing
> exactly. Surprisingly, it works but only from time to time...the behaviour
> is really weird...
> I'm copying the code below and hope someone could review it. I'm afraid
I'm
> breaking something somewhere in my cocoon...
>
> Thanks.
>
> ps: remember that I was trying to code a Action that could dispatch other
> actions, so I could call it for as many XMLForms as needed with a
parameter
> and it would choose the right action. Some kind of factory method...
>
> -----------------------
> package net.josema.xmtrader.forms;
>
> import java.util.HashMap;
> import java.util.Map;
>
> import
> net.josema.xmtrader.forms.xmldb.recordings.equipment.EquipmentTypeAction;
> import org.apache.avalon.framework.parameters.Parameters;
> import org.apache.avalon.framework.thread.ThreadSafe;
> import org.apache.cocoon.acting.ConfigurableComposerAction;
> import org.apache.cocoon.environment.Redirector;
> import org.apache.cocoon.environment.SourceResolver;
>
>
> /**
>  * This action let decide which action to use at runtime based on
>  * a sitemap parameter with the name of the action to load.
>  *
>  */
> public class ActionDispatcher extends ConfigurableComposerAction
implements
> ThreadSafe {
>
>     public Map act(Redirector redirector, SourceResolver resolver, Map
> objectModel,
>         String source, Parameters parameters)
>       throws Exception {
>
>        String actionName = parameters.getParameter("actionName");
>        Map resultMap = new HashMap();
>
>   //get the Action
>   if(actionName.equalsIgnoreCase("EquipmentTypeAction")) {
>    EquipmentTypeAction equipmentTypeAction = new EquipmentTypeAction();
>    //add this action to the manager
>    equipmentTypeAction.compose(this.manager);
>    resultMap = equipmentTypeAction.act(redirector, resolver, objectModel,
> source, parameters);
>   }
>   //place for the rest of the if clauses for more actions
>
>   //return the map gotten from the chosen action
>   return resultMap;
>     }
> }
>
>
>
>
> ---------------------------------------------------------------------
> Please check that your question  has not already been answered in the
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>
>
> To unsubscribe, e-mail:     <co...@xml.apache.org>
> For additional commands, e-mail:   <co...@xml.apache.org>
>


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


RE: how to manage several XMLForms in a sitemap? (it was: dynamically choosing an action at runtime)

Posted by Josema Alonso <al...@aafunky.com>.
[snip]
>   //get the Action
>   if(actionName.equalsIgnoreCase("EquipmentTypeAction")) {
>    EquipmentTypeAction equipmentTypeAction = new EquipmentTypeAction();

>    //add this action to the manager
>    equipmentTypeAction.compose(this.manager);

>This is incorrect. It allows the equipmentTypeAction access the
>component manager. Not the other way around.
I see. Thanks.

>Please don't invent the wheel a second time. Have a read of the great
>introduction to the Apache Avalon Framework.
I don't want to.
I tried but it is too hard for me right now. Anyway, I know is the way to
go.

Thanks.


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: how to manage several XMLForms in a sitemap? (it was: dynamically choosing an action at runtime)

Posted by Christian Haul <ha...@dvs1.informatik.tu-darmstadt.de>.
On 07.Nov.2002 -- 06:53 PM, Josema Alonso wrote:
[snip]
>   //get the Action
>   if(actionName.equalsIgnoreCase("EquipmentTypeAction")) {
>    EquipmentTypeAction equipmentTypeAction = new EquipmentTypeAction();

>    //add this action to the manager
>    equipmentTypeAction.compose(this.manager);

This is incorrect. It allows the equipmentTypeAction access the
component manager. Not the other way around.

Please don't invent the wheel a second time. Have a read of the great
introduction to the Apache Avalon Framework.

Basically, your action needs to implement Composable.
Then you need to get a selector for actions (this is not possible with
the compiled sitemap but works with the treeprocessor IIRC)
Then you could obtain a reference to the desired action.
Then you could fire up that action.
Then you would release that action.
And all the time the component manager takes care of invoking the
correct life cycle interfaces of the action if implemented.

If you cannot access the component manager that holds the actions, you
need to setup your own one.

	Chris.
-- 
C h r i s t i a n       H a u l
haul@informatik.tu-darmstadt.de
    fingerprint: 99B0 1D9D 7919 644A 4837  7D73 FEF9 6856 335A 9E08

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>


Re: how to manage several XMLForms in a sitemap? (it was: dynamically choosing an action at runtime)

Posted by Josema Alonso <al...@aafunky.com>.
Well, this is a followup to my previous message regarding this subject.
I coded the Dispatcher, but I must say I didn't know what I was doing
exactly. Surprisingly, it works but only from time to time...the behaviour
is really weird...
I'm copying the code below and hope someone could review it. I'm afraid I'm
breaking something somewhere in my cocoon...

Thanks.

ps: remember that I was trying to code a Action that could dispatch other
actions, so I could call it for as many XMLForms as needed with a parameter
and it would choose the right action. Some kind of factory method...

-----------------------
package net.josema.xmtrader.forms;

import java.util.HashMap;
import java.util.Map;

import
net.josema.xmtrader.forms.xmldb.recordings.equipment.EquipmentTypeAction;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.acting.ConfigurableComposerAction;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;


/**
 * This action let decide which action to use at runtime based on
 * a sitemap parameter with the name of the action to load.
 *
 */
public class ActionDispatcher extends ConfigurableComposerAction implements
ThreadSafe {

    public Map act(Redirector redirector, SourceResolver resolver, Map
objectModel,
        String source, Parameters parameters)
      throws Exception {

       String actionName = parameters.getParameter("actionName");
       Map resultMap = new HashMap();

  //get the Action
  if(actionName.equalsIgnoreCase("EquipmentTypeAction")) {
   EquipmentTypeAction equipmentTypeAction = new EquipmentTypeAction();
   //add this action to the manager
   equipmentTypeAction.compose(this.manager);
   resultMap = equipmentTypeAction.act(redirector, resolver, objectModel,
source, parameters);
  }
  //place for the rest of the if clauses for more actions

  //return the map gotten from the chosen action
  return resultMap;
    }
}




---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <co...@xml.apache.org>
For additional commands, e-mail:   <co...@xml.apache.org>