Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6905487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:11:21+00:00 2026-05-27T08:11:21+00:00

Whenever I have to add some component (A) to the AjaxRequestTarget of another component

  • 0

Whenever I have to add some component (A) to the AjaxRequestTarget of another component (B) (usualy both children of the same parent, I face the same decision:

Make A a member-variable of the parent component vs. using the parents get(path) method. Both variants seem to have pros and cons and I can’t really decide which would be better from the perspective of “better” code…

The first variant is stable even if the path of (A) changes but leaves the parent cluttered with members that are only rarely used. The other variant results in a cleaner parent class but adds multiple points of failure when the component hierarchy changes. Additional this variant either litters the class with magic strings (the paths) or string constants (when I put the paths there)…

Any hints would be apreciated.

Edit: This applies to Wicket 1.4 since Wicket 1.5 solves this with its EventBus

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:11:22+00:00Added an answer on May 27, 2026 at 8:11 am

    Use Wicket 1.5’s event mechanism instead to update components using Ajax. This way you will decouple publisher and subscriber. See for example my presentation on new features in Wicket 1.5 given at JavaZone’11 (skip to about 51 minutes into the talk).

    Taken from the Wicket 1.5 release notes:

    Inter-component events

    Wicket 1.5 offers a simple, yet flexible, way for component to communicate with each other in a decoupled manner. The two major interfaces that facilitate this are:

    /**
     * Objects that can send events
     */
    public interface IEventSource {
        <T> void send(IEventSink sink, Broadcast broadcast, T payload);
    }
    

    and

    /**
     * Objects that can receive events
     */
    public interface IEventSink
    {
        /**
         * Called when an event is sent to this sink
         */
        void onEvent(IEvent<?> event);
    }
    

    The classes that implement these interfaces, and can thus participate in the event mechanism are: Component, RequestCycle, Session, and Application.

    The mechanism allows for different event broadcast methods defined here:

    /**
     * Defines the event broadcast type.
     */
    public enum Broadcast {
        BREADTH,
        DEPTH,
        BUBBLE,
        EXACT;
    }
    

    There is an example in wicket-examples which demonstrates the usage of this.

    Applications can register custom event dispatchers in FrameworkSettings; the dispatchers can be used to build custom event delivery mechanisms. For example a custom IEventDispatcher mechanism can route events to annotated methods, for example:

    public class MyComponent extends Component {
        @OnEvent
        private void onUserAdded(UserAddedEvent event) {...}
    }
    

    where UserAddedEvent is the event payload object.

    The default Component#onEvent method will be called even if custom dispatchers are registered.

    A default event is raised whenever Wicket begins to create an AJAX response. The payload of the event is the AjaxRequestTarget used for event. Sample implementation:

    // component that always adds itself to the ajax response
    public class MyComponent extends Component {
        public void onEvent(IEvent event) {
            if (event.getPayload() instanceof AjaxRequestTarget) {
                ((AjaxRequestTarget)event.getPayload()).add(this);
             }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a textbox with an 'Add to clipboard' button next to it. Whenever
I have a PHP application using an Oracle XE database. Whenever I add a
I have been trying to add columns to a table using some logic that
I have a table with some rows and inputs inside them. I want add
I have some line of statements in my database.Whenever I create an article and
I have some Zend Framework apps running and it's time to add user access
I have an ArrayList which I add some Objects to it dynamically, and I
I have a window in which I want to add/remove component and resize the
I have a vector<some_struct&> array in my code, and whenever I want to add
I have a combobox where I add some stuff from an Excel sheet with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.