开发者

Java Wicket AjaxFallbackLink needing double click after becoming visible

I have two containers, BEFORE and AFTER. When the page loads up, BEFORE is visible and AFTER is not.

BEFORE contains an AjaxFallbackLink that redraws BEFORE and AFTER but makes BEFORE invisible and AFTER visible, i.e. a visibility trigger.

I also have an AjaxFallbackLink inside AFTER that does the reverse: redraws BEFORE and AFTER but makes BEFORE visible and AFTER invisible.

The problem: the link inside AFTER needs two clicks to have the panels redraw themselves when I should only need one. I've set setOutputMarkupPlaceholderTag to true on every component I can find, but still I need two clicks on the AFTER link to have the panels redraw themselves.

Is there a way to resolve this?

Here's some (simplified) code:

private class ViewDatesFragment extends Fragment<Campaign> {
    private ViewDatesFragment(final MarkupContainer markupProvider) {
        super("flightNoDates", "viewDatesFragment", markupProvider);
        add(new AddDatesLink());
        setOutputMarkupPlaceholderTag(true);
    }

    private class AddDatesLink extends AjaxFallbackLink<Campaign> {

        private AddDatesLink() {
            super("addDates");

            add(new Label("startDate", "This is the start date").setOutputMarkupPlaceholderTag(true));
        setOutpu开发者_如何学GotMarkupPlaceholderTag(true);
        }

        @Override
        public void onClick(final AjaxRequestTarget target) {
            target.addComponent(viewDatesContainer.setVisible(false));
            target.addComponent(editDatesContainer.setVisible(true));            
    }
    }
}

private class EditDatesFragment extends Fragment<Campaign> {

    private EditDatesFragment(final MarkupContainer markupProvider) {
        super("flightDates", "editDatesFragment", markupProvider);

        add(new CancelDatesLink().setOutputMarkupPlaceholderTag(true));
        setOutputMarkupPlaceholderTag(true);
    }

    private class CancelDatesLink extends AjaxFallbackLink {
        private CancelDatesLink() {
            super("cancelDates");
            add(new Label("cancelDatesText", "cancel").setOutputMarkupPlaceholderTag(true));
            setOutputMarkupPlaceholderTag(true);
        }

        @Override
        public void onClick(final AjaxRequestTarget target) {
            target.addComponent(viewDatesContainer.setVisible(true));
            target.addComponent(editDatesContainer.setVisible(false));
        }
    }
}


I discovered the answer: don't ever use wicket:component in your HTML when you're using AJAX.

Always use real HTML elements.

Basically, I changed <wicket:component wicket:id="myId" /> to <div wicket:id="myId" /> and everything worked fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜