Hi,

2011/10/19 Yves-Marie LAINÉ <ymla...@gmail.com>:
> Hi All,
>
> Yesterday, i wrote a Page that need to ajax replace a component, so with
> outputMarkupId at true. This component has to know the markupId when
> onInitialize is called (depending of a component used by it that create a
> javascript)
>
> I know that when we replace Components, the markupId of the replaced
> Component is set on the added one.
>
> But in order to make the added component work on that page, i had to wrote
> code like this :
>
>
>                             public void onClick(AjaxRequestTarget target) {
>
>                                UserDialogPanel userDialogPanel = new
> UserDialogPanel("dialog", rowModel);
>
> *
> userDialogPanel.setMarkupId(getPage().get("dialog").getMarkupId());*    //
> This line of code could probably be avoided.
>
>
> getPage().get("dialog").replaceWith(userDialogPanel);
>                                target.addComponent(userDialogPanel);
>
>                                userDialogPanel.open(target);
>                            }
>
> And after looking at the wicket code it seems to be normal  :
>
>    *public final MarkupContainer replace(final Component child)*
>    {
>        checkHierarchyChange(child);
>
>        if (child == null)
>        {
>            throw new IllegalArgumentException("argument child must be not
> null");
>        }
>
>        if (log.isDebugEnabled())
>        {
>            log.debug("Replacing " + child.getId() + " in " + this);
>        }
>
>        if (child.getParent() != this)
>        {
>            // Add to map
>            final Component replaced = put(child);
>
>            // Look up to make sure it was already in the map
>            if (replaced == null)
>            {
>                throw new WicketRuntimeException(
>                    exceptionMessage("Cannot replace a component which has
> not been added: id='" +
>                        child.getId() + "', component=" + child));
>            }
>
>            // first remove the component.
>            removedComponent(replaced);
>
> *            // then add the other one.
>            addedComponent(child); // onInitialize is called in this method*
>
>            // The position of the associated markup remains the same
>            child.markupIndex = replaced.markupIndex;
>
> *            // The generated markup id remains the same
>            child.setMarkupIdImpl(replaced.getMarkupIdImpl()); // and then,
> the markupid is replaced.*
>        }
>
>        return this;
>    }
>
>
> So if wicket developpers read this, do you think it's possible to improve
> this by modifying the sequence and setting the markupId before adding the
> component ?
Wicket developer here :-)
Please create a ticket in our Jira to not forget about this request.
But I'm not sure this improvement will go in 1.4.x. 1.4.x is in
maintenance and receives only bug fixes. New features and improvements
go in 1.5.x.
> (Sorry for my english, i hope to be clear enough..)
>
> Regards,
> Yves-Marie LAINÉ
>



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

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

Reply via email to