in the ajaxified version you have to call
target.setOutputMarkupPlaceHolderTag(true) in the constructor,
so that an invisible dummy tag is rendered in case the target is initially
invisible.
the dummy tag is then replaced with the actual markup of the target, once
it's visible.

hth,
  gerolf

On Feb 7, 2008 9:26 PM, Fabrizio Giudici <[EMAIL PROTECTED]>
wrote:

> Hello.
> I have a custom component called CollapsiblePanel that has a header with
> an icon; clicking on the icon, the panel get shown or hidden (see picture in
> attachment for a quick view).
>
> The first listing is the current version of the link used to do the thing,
> and it works, but uses a regular request/response cycle, while I'd like to
> do this in the Ajax fashion.
> So I changed it into the second listing, where I've used the
> AjaxFallbackLink, I've set setOutputMarkupId(true) and I'm adding the
> component whose state I'm changing to the ajaxTarget.
>
> But it doesn' work (it does nothing). What's I'm doing wrong?
>
> Thanks.
>
>
>
>
> public class CollapseLink extends Link // AjaxLink
>   {
>     private final Panel target;
>     private final VRCSession session;
>     private final String attributeName;
>
>     public CollapseLink (final String id, final Panel target, final
> boolean initialVisibilityState)
>       {
>         super(id);
>         this.target = target;
>         session = VRCSession.get();
>         attributeName = target.getClass().getName() + "_isVisible";
>
>         boolean visible = initialVisibilityState;
>
>         if (session.getObject(attributeName) != null)
>           {
>             visible = isExpanded();
>           }
>
>         target.setVisible(visible);
>         session.putObject(attributeName, visible);
>       }
>
>     public boolean isExpanded ()
>       {
>         return (Boolean)session.getObject(attributeName);
>       }
>
>     @Override
>     public void onClick()
>       {
>         boolean visible = isExpanded();
>         visible = !visible;
>         target.setVisible(visible);
>         session.putObject(attributeName, visible);
>
>         final String imageName = isExpanded() ? "expanded.png" : "
> collapsed.png";
>         this.replace(new Image("collapseIcon", new Model(imageName)));
>       }
>   }
>
>
>
>
> public class CollapseLink extends AjaxFallbackLink
>   {
>     private final Panel target;
>     private final VRCSession session;
>     private final String attributeName;
>
>     public CollapseLink (final String id, final Panel target, final
> boolean initialVisibilityState)
>       {
>         super(id);
>         this.target = target;
>         session = VRCSession.get();
>         attributeName = target.getClass().getName() + "_isVisible";
>
>         boolean visible = initialVisibilityState;
>
>         if (session.getObject(attributeName) != null)
>           {
>             visible = isExpanded();
>           }
>
>         target.setVisible(visible);
>         target.setOutputMarkupId(true);
>         session.putObject(attributeName, visible);
>       }
>
>     public boolean isExpanded ()
>       {
>         return (Boolean)session.getObject(attributeName);
>       }
>
>     @Override
>     public void onClick (final AjaxRequestTarget ajaxRequestTarget)
>       {
>         boolean visible = isExpanded();
>         visible = !visible;
>         target.setVisible(visible);
>         session.putObject(attributeName, visible);
>
>         final String imageName = isExpanded() ? "expanded.png" : "
> collapsed.png";
>         this.replace(new Image("collapseIcon", new Model(imageName)));
>         ajaxRequestTarget.addComponent(target);
>       }
>   }
>
>
> --
> Fabrizio Giudici, Ph.D. - Java Architect, Project Manager
> Tidalwave s.a.s. - "We make Java work. Everywhere."
> weblogs.java.net/blog/fabriziogiudici - www.tidalwave.it/blog
> [EMAIL PROTECTED] - mobile: +39 348.150.6941
>
>
>
>

Reply via email to