Is IComponentAssignedModel only in 1.3?
On 5/9/07, Igor Vaynberg <[EMAIL PROTECTED]> wrote:
> you can also factor out the javascript confirmation into a behavior and
> reuse it across any links classes like
>
> Link link=new Link("foo") { onclick(){..}}.add(new
> LinkConfirmation("sure?"));
> BookmarkablePageLink link=new BPL(...).add(new LinkConfirmation("sure?"));
>
> -igor
>
>
> public class LinkConfirmation extends AbstractBehavior {
>
> private final IModel msg;
>
> public LinkConfirmation(String msg) { this(new Model(msg)); }
>
> public LinkConfirmation(IModel msg) { this.msg = msg; }
>
> @Override
> public void onComponentTag(Component component, ComponentTag tag) {
> super.onComponentTag(component, tag);
>
> String onclick = tag.getAttributes().getString("onclick");
>
> IModel model = msg;
> if (model instanceof IComponentAssignedModel) {
> model = ((IComponentAssignedModel)
> model).wrapOnAssignment(component);
> }
>
> onclick = "if (!confirm('" + model.getObject().toString() + "'))
> return false; " + onclick;
> tag.getAttributes().put("onclick", onclick);
>
> model.detach();
> msg.detach();
> }
>
> }
>
> -igor
>
>
> On 5/9/07, Shams Mahmood <[EMAIL PROTECTED]> wrote:
> >
> > To help reduce some code, why not extend the BookmarkablePageLink class to
> > form your JavascriptConfirmLink and then no need to write the onclick().
> >
> > also try
> > new JavascriptConfirmLink(id, cls, new
> PageParameters("method=method1"), msg)
> >
> > and the id will be used here:
> > <span wicket:id="listViewId">
> > <a wicket:id="theLinkId"
> href="anotherPage?method=method1">method1</a>
> > </span>
> > You can ignore the href, as wicket will insert it for u.
> >
> >
> >
> >
> > > I'm trying to make a page with several similar links to another page:
> > >
> > > <a href="anotherPage?method=method1>method1</a>
> > > <a href="anotherPage?method=method2>method2</a>
> > > <a href="anotherPage?method=method3>method3</a>
> > >
> > > This would be really easy to put into my html code, but then it
> > > becomes fragile to whether or not I'm mounting my urls. I suppose I
> > > could just make sure to always mount them and make sure to keep these
> > > links in sync with that mapping. But let's for some reason suppose
> > > that I want to inject these from my java code. I'm not sure how to do
> > > this exactly. I was thinking I could do something like I outline
> > > below. Actually, my links are a bit more complicated than displayed
> > > above, since I would like to make sure to have a javascript
> > > confirmation for each click. So I think that for each link what I
> > > would need would be the class of the page they link to, and a map of
> > > the parameters. So I think the code might be something like:
> > >
> > > class JavascriptConfirmLink extends Link {
> > > JavascriptConfirmLink(id, pageClass, params, confirmationMessage) {
> > > super(id);
> > > _pageClass = pageClass;
> > > _params = params;
> > > add(new SimpleAttributeModifier("onclick", "return
> > > confirm"+confirmationMessage+");");
> > > }
> > >
> > > onClick() {
> > > setResponsePage(_pageClass, _params);
> > > }
> > > }
> > >
> > > Then I'd populate my page with several of these links using this code:
> > >
> > > add(new ListView("theLinks", theLinks) {
> > > @Override protected void populateItem(ListItem item)
> > > {
> > > Link link = (Link) item.getModelObject();
> > > item.add(link);
> > > }
> > > });
> > >
> > > Does this look correct?
> > >
> > > Now I have gotten myself a little confused about a couple of things:
> > > - what is the purpose of the id? Since I will be populating the page
> > > with my links using a ListView, I don't see where the id of each link
> > > will ever be referred to.
> > >
> > > Finally, creating these links is quite verbose. PageParameters is
> > > final, so I can't create my links like:
> > >
> > > new JavascriptConfirmLink(id, cls, new PageParameters() {{
> > > add("method", "method1"); }}, msg)
> >
> > > like I'd like so I end up having to new a PageParameters for each link
> > > and add to it before creating the JavascriptConfirmLink, which is
> > > seeming quite verbose.
> > >
> > > There may be some holes in my approach. Is there a better way to do
> this?
> > >
> > > Thanks,
> > > Lowell
> > >
> > >
> > >
> >
> >
> >
> -------------------------------------------------------------------------
> > This SF.net email is sponsored by DB2 Express
> > Download DB2 Express C - the FREE version of DB2 express and take
> > control of your XML. No limits. Just data. Click to get it now.
> > http://sourceforge.net/powerbar/db2/
> > _______________________________________________
> > Wicket-user mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> >
> >
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user