You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sergiu Sapojnic <se...@gmail.com> on 2009/04/08 16:40:47 UTC

AjaxFallbackLink and Component visibility

Hi to all!
I am new to Wicket and am beginning to love it.
I have the following question:
--------------
There's the following markup:

<p>
            <a href="#" wicket:id="clickAjaxLink">This Ajax link</a> has
been clicked <span wicket:id="clickAjaxLabel">[123]</span> times.<br/>
            <span wicket:id="ghost">[VISIBLE ONLY WHEN LINK WAS CLICKED AT
LEAST ONCE]</span>
</p>
--------------
and the following corresponding Java code:

public class HelloPage extends WebPage {

    int counter;
    Label ghostLabel;
    Label clickLabel;

    public HelloPage() {

        add(new AjaxFallbackLink("clickAjaxLink") {
            @Override
            public void onClick(AjaxRequestTarget target) {
                counter++;
                if(target != null) {
                    target.addComponent(clickLabel);
                    target.addComponent(ghostLabel);
                }
            }
        });

        // clickLabel displays how many times the link was clicked
        clickLabel = new Label("clickAjaxLabel", new PropertyModel(this,
counter));
        clickLabel.setOutputMarkupId(true);
        add(clickLabel);

       // ghostLabel should be visible only when the link was clicked at
least once
       ghostLabel = new Label("ghost", "I should be visible only when the
link was clicked at least once") {
           @Override
           public boolean isVisible() {
               return counter > 0;
           }
       };
      add(ghostLabel);
    }

}
---------------

clickLabel works properly and displays the value of counter. But my aim with
ghostLabel is that it is visible only when the AjaxFallbackLink was clicked
at least once. I added it to the request target so that it should be
updated. However, it remains invisible. How can I solve this problem?

Thanks in advance!

Re: AjaxFallbackLink and Component visibility

Posted by Igor Vaynberg <ig...@gmail.com>.
for components that start out as invisible you should call
setoutputmarkupplaceholdertag(true), in your case you need to call it
on the label after you construct it.

there are explanations on why you need to do this in the list archives.

-igor

On Wed, Apr 8, 2009 at 7:40 AM, Sergiu Sapojnic <se...@gmail.com> wrote:
> Hi to all!
> I am new to Wicket and am beginning to love it.
> I have the following question:
> --------------
> There's the following markup:
>
> <p>
>            <a href="#" wicket:id="clickAjaxLink">This Ajax link</a> has
> been clicked <span wicket:id="clickAjaxLabel">[123]</span> times.<br/>
>            <span wicket:id="ghost">[VISIBLE ONLY WHEN LINK WAS CLICKED AT
> LEAST ONCE]</span>
> </p>
> --------------
> and the following corresponding Java code:
>
> public class HelloPage extends WebPage {
>
>    int counter;
>    Label ghostLabel;
>    Label clickLabel;
>
>    public HelloPage() {
>
>        add(new AjaxFallbackLink("clickAjaxLink") {
>            @Override
>            public void onClick(AjaxRequestTarget target) {
>                counter++;
>                if(target != null) {
>                    target.addComponent(clickLabel);
>                    target.addComponent(ghostLabel);
>                }
>            }
>        });
>
>        // clickLabel displays how many times the link was clicked
>        clickLabel = new Label("clickAjaxLabel", new PropertyModel(this,
> counter));
>        clickLabel.setOutputMarkupId(true);
>        add(clickLabel);
>
>       // ghostLabel should be visible only when the link was clicked at
> least once
>       ghostLabel = new Label("ghost", "I should be visible only when the
> link was clicked at least once") {
>           @Override
>           public boolean isVisible() {
>               return counter > 0;
>           }
>       };
>      add(ghostLabel);
>    }
>
> }
> ---------------
>
> clickLabel works properly and displays the value of counter. But my aim with
> ghostLabel is that it is visible only when the AjaxFallbackLink was clicked
> at least once. I added it to the request target so that it should be
> updated. However, it remains invisible. How can I solve this problem?
>
> Thanks in advance!
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org