You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Werner Punz <we...@gmx.at> on 2002/08/07 15:18:33 UTC

Problem with Event context-possible bug

I now have following problem:

I´ve define a custom event in a from VelocityAction derived class and 
relinked the event via following code in a URL:

  #set($topicid = 
"&eventSubmit_doViewcontent=foobaz&topicid=$topic.get_nthemaid()")
         <LI> <A HREF = 
"$jslink.setAction("forum.TopicView")$topicid">$topic.get_ctitel()</A>


So far this code works.

The problem I now have is if I click on the URL my doViewcontent Event 
handler method is called and the passed context is filled properly, the 
problem is that somewhere in the base jetspeed system the context is 
replaced after the event calling and thus the content of the event 
context is lost somehow in the whole system. I checked it with a debugger:
my doViewcontent methods delivers a totally different context (the one 
generated by the underlying VelocityPortletAction class), than the 
buildNormalContext method, and only the context of the 
buildNormalContext method is parsed. Am I missing something there or is 
there a problem with the the Velocity Event mechanism somewhere in Jetspeed?


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


Re: Problem with Event context-possible bug

Posted by Werner Punz <we...@gmx.at>.
Ok it seems that, I have to answer my own questions. There definitely is 
a bug if using custom events. However there is a quick solution without 
having to touch the core system. Just add another jetspeed related event 
layer for custom events and it works:

Just add following code to your VelocityPortletAction derived class:


     static final String JS_BUTTON = "jsEventSubmit_";

     public void executeJSEvents(RunData data, Context context) throws 
Exception
     {
         // Name of the button.
         String theButton = null;

         // ParameterParser.
         ParameterParser pp = data.getParameters();

         String button = pp.convert(LC_BUTTON);

         // Loop through and find the button.
         for (Enumeration e = pp.keys() ; e.hasMoreElements() ;)
         {
             String key = (String) e.nextElement();
             if (key.startsWith(button))
             {
                 //remove the leading JS
                 key = key.substring(2,key.length());
                 theButton = formatString(key);
                 break;
             }
         }

         if (theButton == null)
             throw new NoSuchMethodException("ActionEvent: The button 
was null");

         try
         {
             // The arguments to the method to find.
             Class[] classes = new Class[2];
             classes[0] = RunData.class;
             classes[1] = Context.class;

             // The arguments to pass to the method to execute.
             Object[] args = new Object[2];

             Method method = getClass().getMethod(theButton, classes);
             args[0] = data;
             args[1] = context;
             method.invoke(this, args);
         }
         catch (NoSuchMethodException nsme)
         {
             // Attempt to execut things the old way..
             super.executeEvents(data);
         }
      }




     protected void perform( RunData rundata )
         throws Exception
     {
         Context context = getContext(rundata);
         if 
((context!=null)&&(rundata.getParameters().getString("action")!=null))
         {
             // if context is already defined and Actions defined, events
             // have already been processed, call doPerform
             Log.debug("Action detected with action + context");
             try {
                 executeJSEvents(rundata,context);
             } catch (Exception ex) {
                 //doPerform has to be called anyway
             }
             doPerform(rundata, context);
         }
         else
         {
             // if context is null, create a new one
             if (context==null)
             {
                 Log.debug("Action: building action context");
                 context = TurbineVelocity.getContext();
 
rundata.getTemplateInfo().setTemplateContext("VelocityActionContext",context);
             }

             try
             {
                 // process implicit ActionEvent invocation
                 Log.debug("Action: try executing events");
                 executeEvents(rundata, context);
             }
             catch (NoSuchMethodException e)
             {
                 // no event selected, process normal context generation
                 Log.debug("Action: calling doPerform");
                 doPerform(rundata, context);
             }
         }
     }

And you have another event layer without having to bypass the Turbin 
events. The events are called like the turbine ones, but you have to add
a js in front of the event call, this reroutes the call to the custom 
jetspeed events.


for instance passing a parameter like:
jsEventSubmit_doViewcontent=foobaz

would reroute the event system to the custom jetspeed event 
doViewcontent! I´m not sure if jetspeed already has its own event layer, 
but looking at the code it looks like that everything is handled on 
turbine level. The weird thing is that the call of the doUpdate seems to 
be outside of the turbine level, and thus the VelocityHelloworld works 
as expected (I checked it with the debugger, the doUpdate gets the 
correct context the custom turbine events don´t)










Werner Punz wrote:
> I now have following problem:
> 
> I´ve define a custom event in a from VelocityAction derived class and 
> relinked the event via following code in a URL:
> 
>  #set($topicid = 
> "&eventSubmit_doViewcontent=foobaz&topicid=$topic.get_nthemaid()")
>         <LI> <A HREF = 
> "$jslink.setAction("forum.TopicView")$topicid">$topic.get_ctitel()</A>
> 
> 
> So far this code works.
> 
> The problem I now have is if I click on the URL my doViewcontent Event 
> handler method is called and the passed context is filled properly, the 
> problem is that somewhere in the base jetspeed system the context is 
> replaced after the event calling and thus the content of the event 
> context is lost somehow in the whole system. I checked it with a debugger:
> my doViewcontent methods delivers a totally different context (the one 
> generated by the underlying VelocityPortletAction class), than the 
> buildNormalContext method, and only the context of the 
> buildNormalContext method is parsed. Am I missing something there or is 
> there a problem with the the Velocity Event mechanism somewhere in 
> Jetspeed?
> 




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