Conditional Popup

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Conditional Popup

hfriederichs
Hello,

I have a wicket PopupPage that answers a wicket link, but I don't want it to popup when certain conditions are not met. In that case I want an info-message.

So I tried something like:
final Link<String> theLink = new Link<String>(...) {
                               
public void onClick() {
if (condition) {
   info("Do this first");
} else {
  setPopupSettings(thePopupSettings);
  setResponsePage(thePopupPage);
}
};

But no matter what I try, the popuppage always comes.


                                               
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

Tom Götz
Could you please provide a quickstart or post the interesting HTML and Java snippets?

   -Tom


On 01.06.2012 at 15:24 hfriederichs wrote:

> Hello,
>
> I have a wicket PopupPage that answers a wicket link, but I don't want it to
> popup when certain conditions are not met. In that case I want an
> info-message.
>
> So I tried something like:
> final Link<String> theLink = new Link<String>(...) {
>
> public void onClick() {
> if (condition) {
>   info("Do this first");
> } else {
>  setPopupSettings(thePopupSettings);
>  setResponsePage(thePopupPage);
> }
> };
>
> But no matter what I try, the popuppage always comes.
>
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Conditional-Popup-tp4649649.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

hfriederichs
A quick-start costs me one or two hours; in the end, maybe I will. But I think this is a reasonably simple question, so I'll await some straightforward suggestions first.
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

Tom Götz
To create a quickstart normally costs me around 5-7 seconds (copy/paste is my friend) ;-)
Isolating the problem is another question, right. But in your case this sound rather trivial. In my experience a lot of problems are solved easyly by creating a quickstart, in most cases because then I realize that I did something wrong ;-)

   -Tom


On 01.06.2012 at 16:06 hfriederichs wrote:

> A quick-start costs me one or two hours; in the end, maybe I will. But I
> think this is a reasonably simple question, so I'll await some
> straightforward suggestions first.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

hfriederichs
For other questions I had earlier on, I created quickstarts, but, since I'm working on a very complex application, I couldn't reproduce the problem in a quickstart. I spent hours and hours copying more and more of my application into the quickstart, but to no avail.

So again, it's a simple question: how to make a conditional popup.
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

Martin Grigorov-4
try with:

if (condition) { setPopupSettings(nonNull) } else { setPopupSettings(null) }

On Fri, Jun 1, 2012 at 5:40 PM, hfriederichs <[hidden email]> wrote:

> For other questions I had earlier on, I created quickstarts, but, since I'm
> working on a very complex application, I couldn't reproduce the problem in a
> quickstart. I spent hours and hours copying more and more of my application
> into the quickstart, but to no avail.
>
> So again, it's a simple question: how to make a conditional popup.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Conditional-Popup-tp4649649p4649654.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>



--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

Tom Götz
In reply to this post by hfriederichs
As I suppose that you want to create a Javascript popup (i.e. a Wicket Link with PopupSettings), you need to decide wether to open the popup or not in the frontend (Javascript layer), not in the onClick() of the Link. So you could try something like this:

PopupSettings popupSettings = new PopupSettings() {
    @Override
    public String getPopupJavaScript() {
        return "if(!condition) return false; " + super.getPopupJavaScript();
    }
};

Link link = new Link("link") {
    @Override
    public void onClick() {
        // ...
    }

};
link.setPopupSettings(popupSettings);
add(link);

   -Tom



On 01.06.2012 at 16:40 hfriederichs wrote:

> For other questions I had earlier on, I created quickstarts, but, since I'm
> working on a very complex application, I couldn't reproduce the problem in a
> quickstart. I spent hours and hours copying more and more of my application
> into the quickstart, but to no avail.
>
> So again, it's a simple question: how to make a conditional popup.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

Tom Götz
In reply to this post by hfriederichs
As an alternative, you could use an AjaxLink and push the popup-opener JS to teh frontend, then you could have your decision logic (wether to open it or not) in the backend (Wicket layer).

   -Tom




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

hfriederichs
In reply to this post by Tom Götz
Thomas Götz-2 wrote
PopupSettings popupSettings = new PopupSettings() {
    @Override
    public String getPopupJavaScript() {
        return "if(!condition) return false; " + super.getPopupJavaScript();
    }
};
I'm sorry, but I don't understand your code. My condition is in the Java/Wicket-layer, how can you put that between double quotes?
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

Tom Götz
I thought you might have some condition that you could evaluate in JS. This is the reason I asked for a short quickstart, it simply eases discussion.

   -Tom


On 01.06.2012 at 19:19 hfriederichs wrote:

> I'm sorry, but I don't understand your code. My condition is in the
> Java/Wicket-layer, how can you put that between double quotes?


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

hfriederichs
In reply to this post by Martin Grigorov-4
Martin Grigorov-4 wrote
try with:

if (condition) { setPopupSettings(nonNull) } else { setPopupSettings(null) }
This doesn't work. The condition has to be checked every time the link is clicked, so within the onCLick().
setPopupSettings(null) gives the current page as popup.

Maybe this information is relevant: The link is part of a row in a repeater (within the populateItem of a ListView).

Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

hfriederichs
In reply to this post by hfriederichs
No suggestions? Anyone?
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

Tom Götz
What about the AjaxLink alternative I already suggested?

   -Tom


On 04.06.2012 at 09:35 hfriederichs wrote:

> No suggestions? Anyone?


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

hfriederichs
In reply to this post by Tom Götz
Thomas Götz-2 wrote
As an alternative, you could use an AjaxLink and push the popup-opener JS to teh frontend, then you could have your decision logic (wether to open it or not) in the backend (Wicket layer).
   
But, how would you do that?

if  (condition) {
   info("Do this first");
} else {
   activate JS-popup-opener ????
}

And furthermore, I need to pass data to the popup-page, so I would have to stick that in the Session?
Reply | Threaded
Open this post in threaded view
|

Re: Conditional Popup

Tom Götz
On 04.06.2012 at 13:21 hfriederichs wrote:

>
> Thomas Götz-2 wrote
>>
>> As an alternative, you could use an AjaxLink and push the popup-opener JS
>> to teh frontend, then you could have your decision logic (wether to open
>> it or not) in the backend (Wicket layer).
>>
>>
>
> But, how would you do that?
>
> if  (condition) {
>   info("Do this first");
> } else {
>   activate JS-popup-opener ????
> }

Yes, this would be a possible solution, maybe something like that:

AjaxLink link = new AjaxLink("link") {
    @Override
    public void onClick(AjaxRequestTarget target) {
        if (condition) {
            info("...");
            // target.add(feedbackPanel);
        } else {
            target.appendJavaScript("Wicket.$('" + myPopup.getMarkupId() + "').open();");
        }
    }
};
add(link);


> And furthermore, I need to pass data to the popup-page, so I would have to
> stick that in the Session?

You could also pass a model to the Page's constructor e.g.

Cheers,
   -Tom


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]