Ok,

If you already have this working then it should be relatively easy to
send the textfield value without submitting the form.
Be ready for some dirty work though.
Here is what you need, we'll get to how you can do it later ;)
- when the link /icon is clicked we need to get the field value
- then we need to trigger the popup with the value

Too get the value we need some javascript:
document.getElementById('text field id here').value

Then we need to trigger the popup I recommend something like:
OnClickLink onClickLink = new OnClickLink("link")
{
        public void linkClicked()
        {
                RequestCycle cycle = RequestCycle.get();
                PageParameters params = new PageParameters();
                cycle.setPage(cycle.getPageFactory().newPage
                        (DatePickerPopupPage.class, params));
        }
};
onClickLink.setPopupSettings(makePopup(index)); //you probably need an
index if you are going to use multiple datepickers on the same page, to
keep track

private PopupSettings makePopup(int index)
{
                PopupSettings popup = new PopupSettings(false, false,
false, false, false);
                popup.setHeight(500);
                popup.setWidth(560);
                popup.setLocation(500, 200);
                popup.setWindowName("some name_" + index);
                popup.setFocus(true);
                return popup;
}

Now to keep everything reusable we need to add some dynamic
javascripting, I use the following trick to do that:

private class JavaScriptPanel extends Panel
{
        /**
         * Construct.
         * @param componentName
         */
        public JavaScriptPanel(String componentName, int componentIndex)
        {
                super(componentName);
                add(new Label("script", new IModel()
                {
                        public Object getObject()
                        {
                                int index = componentIndex;
                                OnClickLink link = (OnClickLink)
parent.get("link");
                                String url =
getRequestCycle().urlFor(link, ILinkListener.class);
                                PopupSettings popup = makePopup(index);
                                popup.setTarget("'" +
url.replaceAll("&", "&") + "'+'&param1='+
document.getElementById('text field id here').value");
                                StringBuffer buffer = new StringBuffer(
                                        "<script
language=\"JavaScript1.1\">\r\n").append(
"\t<!--\r\n\t\tfunction datePopup()\r\n\t\t{\r\n").append("\t\t\t")
.append(popup.getPopupJavaScript()).append("\r\n\t\t}\r\n\t//-->\r\n</sc
ript>");
                                return buffer.toString();
                        }
                        public void setObject(Object object)
                        {
                                // not important
                        }
                }).setShouldEscapeModelStrings(false));
        }
}

Now all we need to do is extend/override onClickLink or make or own
implementation of Link, so that the javascript function datePopup() is
triggered. There are several ways to do this and I am confident you will
accomplish that part on your own.

What exactly did we do here?
The following should happen:
The link is clicked this triggers a javascript function that: A gets the
value, B dynamicly adjusts an url, C opens the url in a popup.
Wicket will now trigger a call to your onclick function which simply
tells it to render a page.

All you have to do now is get the request parameter "param1" and use it
as input.

Please Note that this code is not tested (frankly I'll be surprised if
it works in 1 go) but it should give you a general idea of what to do.
Also in my own code I use subclasses of both onclicklink and
popupsetting, I don't think you need my classes and I tried to make the
code not use any of my adaptations, but if you come across something the
wicket api does not recognize don't hesitate to ask.

Maurice
 

-----Oorspronkelijk bericht-----
Van: Antonio Casula [mailto:[EMAIL PROTECTED] 
Verzonden: vrijdag 11 februari 2005 18:02
Aan: [email protected]
Onderwerp: RE: [Wicket-user] onClick event

Probably my question it's not so clear ...
I am already opening a popup with a
BookmarkablePageLink as you can see. I need to get the
content of the textfield when the user click the link
before open the popup without submit the form. I think
is possible if there are some opportunity to change
the javascript code that is invoked by
BookmarkablePageLink .
I am able now to fill the textfield from the popup
with the user selected value but not the opposite!
I cannot show the actual data from textfield in the
popup calendar.
 

This is a part of the code of DatePicker:

public final class DatePicker extends Panel {
        
        /**
     * Constructor that uses the provided [EMAIL PROTECTED]
IModel}as its model. All components have
     * names. A component's name cannot be null.
     * @param name The non-null name of this component
     * @param model
     * @throws WicketRuntimeException Thrown if the
component has been given a null name.
     */
    public DatePicker(String name, IModel model)
    {
        super(name);
                TextField stringInput = new
TextField("campo",model);
                createUI(stringInput);
    }

...
        /**
        */
        public DatePicker(String name, IModel model, String
expression)
        {
        super(name);
                TextField stringInput = new
TextField("campo",model,expression);
                createUI(stringInput);
        }
        
        private void createUI(TextField field){
                add(field);
                PopupSettings popupSpec = new
PopupSettings().setHeight(200).setWidth(265).setLocation(100,100).setSta
tusBar(false).setWindowName("WCalendar")
;
                final BookmarkablePageLink link = new
BookmarkablePageLink("popupLink",
DatePickerPopupPage.class);
                link.setPopupSettings(popupSpec);
                link.add(new Image("image4", "cal.gif"));
                add(link);
        }
}

--- Maurice Marrink <[EMAIL PROTECTED]>
wrote:

> Since the textfield is likely to be in a form you
> might want to make the
> icon submit the form and then in the submit from
> your form open the
> popup.
> The trick will be however to update the mainpage
> without loosing any
> data after you close the popup.
> 
> IMO it would be far easier to use one of the many
> fully javascripted
> datepickers that open a floating div instead because
> you never have to
> leave the page.
> 
> Maurice
> 
> 
> -----Oorspronkelijk bericht-----
> Van: Antonio Casula [mailto:[EMAIL PROTECTED] 
> Verzonden: vrijdag 11 februari 2005 11:05
> Aan: [email protected]
> Onderwerp: [Wicket-user] onClick event
> 
> I have written a Calendar and a DatePicker
> components
> for wicket without use javascript (almost) (btw how
> to
> contribute them to the wicket community?) but
> something is missed.
> the datepicker component is composed by one
> textfield
> and a link (a calendar icon actually).
> I need to get the textfield value and send like
> parameter to the calendar component (a popup
> WebPage)
> when I click on icon.
> 
> Some suggestion?
> 
> Antonio
> 
> 
>               
> __________________________________ 
> Do you Yahoo!? 
> Meet the all-new My Yahoo! - Try it today! 
> http://my.yahoo.com 
>  
> 
> 
> 
>
-------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT
> Products from real users.
> Discover which products truly live up to the hype.
> Start reading now.
>
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
> _______________________________________________
> Wicket-user mailing list
> [email protected]
>
https://lists.sourceforge.net/lists/listinfo/wicket-user
> 
> 
>
-------------------------------------------------------
> SF email is sponsored by - The IT Product Guide
> Read honest & candid reviews on hundreds of IT
> Products from real users.
> Discover which products truly live up to the hype.
> Start reading now.
> http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
> _______________________________________________
> Wicket-user mailing list
> [email protected]
>
https://lists.sourceforge.net/lists/listinfo/wicket-user
> 



                
__________________________________ 
Do you Yahoo!? 
All your favorites on one personal page - Try My Yahoo!
http://my.yahoo.com 


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to