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/04 17:39:23 UTC

dynamically choosing an action at runtime

Hello, all.

Is it possible to choose what an action perform at runtime based on sitemap
parameters? I have the pipeline below for processing XMLForms. It is working
just nice for one form if I do not use the {1} param but hard code the
Action name. I would like to make it work as described so I could
dynamically choose what actions to apply to every form based on parameter.

Any ideas?

thanks

----------------------------------------------
  <!-- 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>



---------------------------------------------------------------------
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>


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

Posted by Josema Alonso <al...@aafunky.com>.
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: dynamically choosing an action at runtime

Posted by Josema Alonso <al...@aafunky.com>.
> It's also possible to only have the <map:generate/> as child of
> <map:select/> and <map:act/> and the rest comes after <map:select/>:
>...
I see, thanks.

> But for my eyes still everything seems to be the same except the action
> interna. Maybe it's better to use only one action and choosing there
> internally what to do?
Yes! That's what I'm trying to do, but I still couldn't. I can't think of a
way of coding that. Maybe I should know something about the Avalon
components and try to make something like an ActionDispatcher...but
unfortunately I don't know how to do it :-(

Thanks anyway :-)


---------------------------------------------------------------------
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: dynamically choosing an action at runtime

Posted by Joerg Heinicke <jo...@gmx.de>.
It's also possible to only have the <map:generate/> as child of 
<map:select/> and <map:act/> and the rest comes after <map:select/>:

    <map:match pattern="*">
     <map:select type="parameter">
      <map:parameter name="parameter-selector-test" value="{1}"/>
      <!-- Case #1 -->
      <map:when test="EquipmentType">
       <map:act type="EquipmentTypeAction">
        <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{page}.xml"/>
       </map:act>
      </map:when>
      <!-- Case #2, very very similar to the first one, it should be a 
better
way to choose between both -->
      <map:when test="RecordingType">
       <map:act type="RecordingTypeAction">
        <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{page}.xml"/>
       </map:act>
      </map:when>
     </map:select>
     <!-- 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:match>

But for my eyes still everything seems to be the same except the action 
interna. Maybe it's better to use only one action and choosing there 
internally what to do?

Regards,

Joerg

Artur Bialecki wrote:
> Check out the 	"Calling resources" on this page
> http://xml.apache.org/cocoon/userdocs/concepts/sitemap.html
> Maybe you can organize the 'meat' of your pipeline as
> as a resource and just map:call it from your main pipeline.
> 
> Artur...
> 
> 
>>-----Original Message-----
>>From: Josema Alonso [mailto:alonso@aafunky.com] 
>>Sent: November 4, 2002 12:57 PM
>>To: cocoon-users@xml.apache.org
>>Subject: Re: dynamically choosing an action at runtime
>>
>>
>>
>>>Just use appropriate selector:
>>>http://xml.apache.org/cocoon/userdocs/selectors/selectors.html
>>>
>>
>>I already tried but haven't found a nice way of using them 
>>for this purpose.
>>I can make something like the pipeline below, but i have 
>>dozens of similar
>>cases and it doesn't seem like a good approach. Maybe I 
>>haven't understood
>>selectors well...
>>
>>
>>--------------------------------------
>>  <!-- XMLForms pipeline -->
>>  <map:pipeline>
>>   <map:match pattern="*">
>>    <map:select type="parameter">
>>     <map:parameter name="parameter-selector-test" value="{1}"/>
>>     <!-- Case #1 -->
>>     <map:when test="EquipmentType">
>>      <map:act type="EquipmentTypeAction">
>>       <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{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:when>
>>     <!-- Case #2, very very similar to the first one, it 
>>should be a better
>>way to choose between both -->
>>     <map:when test="RecordingType">
>>      <map:act type="RecordingTypeAction">
>>       <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{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:when>
>>    </map:select>
>>   </map:match>
>>  </map:pipeline>
>>
>>
>>
>>---------------------------------------------------------------------
>>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>
> 
> 


---------------------------------------------------------------------
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: dynamically choosing an action at runtime

Posted by Artur Bialecki <ar...@digitalfairway.com>.
Check out the 	"Calling resources" on this page
http://xml.apache.org/cocoon/userdocs/concepts/sitemap.html
Maybe you can organize the 'meat' of your pipeline as
as a resource and just map:call it from your main pipeline.

Artur...

> -----Original Message-----
> From: Josema Alonso [mailto:alonso@aafunky.com] 
> Sent: November 4, 2002 12:57 PM
> To: cocoon-users@xml.apache.org
> Subject: Re: dynamically choosing an action at runtime
> 
> 
> > Just use appropriate selector:
> > http://xml.apache.org/cocoon/userdocs/selectors/selectors.html
> >
> I already tried but haven't found a nice way of using them 
> for this purpose.
> I can make something like the pipeline below, but i have 
> dozens of similar
> cases and it doesn't seem like a good approach. Maybe I 
> haven't understood
> selectors well...
> 
> 
> --------------------------------------
>   <!-- XMLForms pipeline -->
>   <map:pipeline>
>    <map:match pattern="*">
>     <map:select type="parameter">
>      <map:parameter name="parameter-selector-test" value="{1}"/>
>      <!-- Case #1 -->
>      <map:when test="EquipmentType">
>       <map:act type="EquipmentTypeAction">
>        <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{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:when>
>      <!-- Case #2, very very similar to the first one, it 
> should be a better
> way to choose between both -->
>      <map:when test="RecordingType">
>       <map:act type="RecordingTypeAction">
>        <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{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:when>
>     </map:select>
>    </map:match>
>   </map:pipeline>
> 
> 
> 
> ---------------------------------------------------------------------
> 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: dynamically choosing an action at runtime

Posted by Josema Alonso <al...@aafunky.com>.
>    You don't have to include the parts of your pipeline that are the
> same in the <map:when> elements. You can just include the <map:act>
> element, since it appears that you're not returning any parameters from
> your action, and then you won't have to duplicate the part that doesn't
> vary.
I'm returning the {page} parameter from the action. I'll try it the way you
describe anyway and I'll see if I can get some results.

>    An even better way would be to have a proxy Action class that
> dynamically loads a particular helps class depending on a parameter
> passed to it. Cocoon already includes something like this with
> ServerPagesAction, and you write the action in XSP.
Yes! But I don't know how to code it. I'll take a look at the Action you
mention.

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: dynamically choosing an action at runtime

Posted by Justin Fagnani-Bell <ju...@paraliansoftware.com>.
Josema,

   You don't have to include the parts of your pipeline that are the 
same in the <map:when> elements. You can just include the <map:act> 
element, since it appears that you're not returning any parameters from 
your action, and then you won't have to duplicate the part that doesn't 
vary.

   An even better way would be to have a proxy Action class that 
dynamically loads a particular helps class depending on a parameter 
passed to it. Cocoon already includes something like this with 
ServerPagesAction, and you write the action in XSP.

Justin


On Monday, November 4, 2002, at 09:57  AM, Josema Alonso wrote:

>> Just use appropriate selector:
>> http://xml.apache.org/cocoon/userdocs/selectors/selectors.html
>>
> I already tried but haven't found a nice way of using them for this 
> purpose.
> I can make something like the pipeline below, but i have dozens of 
> similar
> cases and it doesn't seem like a good approach. Maybe I haven't 
> understood
> selectors well...
>
>
> --------------------------------------
>   <!-- XMLForms pipeline -->
>   <map:pipeline>
>    <map:match pattern="*">
>     <map:select type="parameter">
>      <map:parameter name="parameter-selector-test" value="{1}"/>
>      <!-- Case #1 -->
>      <map:when test="EquipmentType">
>       <map:act type="EquipmentTypeAction">
>        <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{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:when>
>      <!-- Case #2, very very similar to the first one, it should be a 
> better
> way to choose between both -->
>      <map:when test="RecordingType">
>       <map:act type="RecordingTypeAction">
>        <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{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:when>
>     </map:select>
>    </map:match>
>   </map:pipeline>
>
>
>
> ---------------------------------------------------------------------
> 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: dynamically choosing an action at runtime

Posted by Josema Alonso <al...@aafunky.com>.
> Just use appropriate selector:
> http://xml.apache.org/cocoon/userdocs/selectors/selectors.html
>
I already tried but haven't found a nice way of using them for this purpose.
I can make something like the pipeline below, but i have dozens of similar
cases and it doesn't seem like a good approach. Maybe I haven't understood
selectors well...


--------------------------------------
  <!-- XMLForms pipeline -->
  <map:pipeline>
   <map:match pattern="*">
    <map:select type="parameter">
     <map:parameter name="parameter-selector-test" value="{1}"/>
     <!-- Case #1 -->
     <map:when test="EquipmentType">
      <map:act type="EquipmentTypeAction">
       <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{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:when>
     <!-- Case #2, very very similar to the first one, it should be a better
way to choose between both -->
     <map:when test="RecordingType">
      <map:act type="RecordingTypeAction">
       <!-- 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="{1}/schematron/{1}-validator.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="{../1}/{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:when>
    </map:select>
   </map:match>
  </map:pipeline>



---------------------------------------------------------------------
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: dynamically choosing an action at runtime

Posted by Artur Bialecki <ar...@digitalfairway.com>.
Just use appropriate selector:
http://xml.apache.org/cocoon/userdocs/selectors/selectors.html

Artur...

> -----Original Message-----
> From: Josema Alonso [mailto:alonso@aafunky.com] 
> Sent: November 4, 2002 11:39 AM
> To: Cocoon-Users
> Subject: dynamically choosing an action at runtime
> 
> 
> Hello, all.
> 
> Is it possible to choose what an action perform at runtime 
> based on sitemap
> parameters? I have the pipeline below for processing 
> XMLForms. It is working
> just nice for one form if I do not use the {1} param but hard code the
> Action name. I would like to make it work as described so I could
> dynamically choose what actions to apply to every form based 
> on parameter.
> 
> Any ideas?
> 
> thanks
> 
> ----------------------------------------------
>   <!-- 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>
> 
> 
> 
> ---------------------------------------------------------------------
> 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>