I've had a few requests about this, so here is an update with an
easy-to-implement solution.  It can be used to execute any arbitrary
JavaScript as part of an AJAX return.  I simply use the standard
renderSupport.addScript() method.

I created a component called "executescript":
public class ExecuteScript
{
    @Parameter(defaultPrefix=BindingConstants.LITERAL) private String
script;

    @Environmental
    private RenderSupport renderSupport;

    @BeforeRenderTemplate
    public void addScript()
    {
        System.out.println("script: "+script);
        if(!Util.isBlank(script)) renderSupport.addScript(script);
    }
}

(It has a simple mostly-empty "tml" file to go with it.)


Then, to use it, I add this to a page or component:
In the tml:
  <t:zone id="myZone" t:id="myZone">
  <t:executeScript script="prop:execScript"/>
  </t:zone>
In the Java:
  @Property @InjectComponent private Zone myZone;
  @Property private String execScript;
  public Object onCloseWindow()
  {
    execScript = "theIdForMyWindow.close();";   // or any other javascript
that you would like to run
    return myZone.getBody();
  }

When the zone is rendered, the executescript component is rendered.  That
the script to be executed is passed as a parameter and the component uses
renderSupport.addScript() to add the script to the ajax response.  Tapestry
will then automatically execute this script as part of the ajax processing.

-Nathan

On Thu, Mar 11, 2010 at 2:23 AM, Nathan Kopp <nathan.k...@gmail.com> wrote:

> I have a page that uses ChenilleKit to pop up a window that contains a
> component.  That component contains a form enclosed in a zone.  The form get
> submitted under a variety of circumstances primarily for the purpose of
> storing the state and redrawing the form based on some option the user just
> selected.  This all works great.  However, once the user has finally
> finished everything, I'd like for the final submit button to do something
> else other than just update the zone.  I want it to cause the window to
> close and for another zone on the page, outside of the window, to be
> updated.  And I need to make it close the ChenilleKit window.  I haven't
> figured out how to make this happen yet.
>
> I think I figured out that I can pass a zone from the page to the inner
> component (which has the form) and then return a MultiZoneUpdate to update a
> part of the page that is not otherwise known by the inner component.
>  However, I haven't been able to close the window using this method.  I
> think I might need to trigger a javascript callback (like ChenilleKit's
> OnEvent mixin).  Any ideas?
>
> -Nathan
>
>

Reply via email to