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

  • Home
  • SEARCH
  • 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 8700741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:14:15+00:00 2026-06-13T02:14:15+00:00

I have a dropdown component added on a page. the purpose of this dropdown

  • 0

I have a dropdown component added on a page. the purpose of this dropdown is to change the type of input form that is rendered. for example, different forms have different required fields, editable fields, etc.

public final class Test extends WebPage
{

    CustomPanel currentPanel = new MeRequest("repeater",FormType.MIN);

    public Test(PageParameters parameters)
    {
        add(currentPanel);         

        DropDownChoice ddc = new DropDownChoice("panel", new PropertyModel(this, "selected"), panels, choiceRenderer);
        ddc.add(new AjaxFormComponentUpdatingBehavior("onchange") {
            protected void onUpdate(AjaxRequestTarget target) {
                System.out.println("changed");
                currentPanel = new MeRequest("repeater",FormType.PRO);
                target.add(currentPanel);
            }
        });
        add(ddc);
    }

i’ve tried various options with limited results. the only real success has been updating the model, but what i really want to do is change how the components behave.

any thoughts on what i’m missing?

  • 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-06-13T02:14:17+00:00Added an answer on June 13, 2026 at 2:14 am

    1) If you want to replace one panel with another you may just do the following.

    First of all, you should output the markup id of the original panel:

    currentPanel.setOutputMarkupId(true);
    

    And then in the ajax event handler write something like that:

    protected void onUpdate(AjaxRequestTarget target) {
        CustomPanel newPanel = new MeRequest("repeater", FormType.PRO);
        currentPanel.replaceWith(newPanel);
        currentPanel = newPanel;
        currentPanel.setOutputMarkupId(true);
        target.addComponent(currentPanel);
    }
    

    In this case with every change of dropdown choice you add new panel to the page and you remove old panel from the page.

    2) But I would proposed a slightly different approach to your problem. You should move the construction logic of your panel to the onBeforeRender() method:

    public class MeRequest extends Panel {
    
        private FormType formType;
    
        public MeRequest(String id, FormType formType) {
            super(id);
            this.formType = formType;
    
            // don't forget to output the markup id of the panel
            setOutputMarkupId(true);
    
            // constructor without construction logic
        }
    
        protected void onBeforeRender() {
            // create form and form components based on value of form type
            switch (formType) {
                case MIN:
                    // ...
                    break;
                case PRO:
                    // ...
                    break;
            }            
    
            // add form and form components to panel
            addOrReplace(form);
            form.add(field1);
            form.add(field2);
            // ...
    
            super.onBeforeRender();
        }
    
        public void setFormType(FormType formType) {
            this.formType = formType;
        }
    }
    

    Then you’ll be able to only change type of the panel in the ajax event:

    protected void onUpdate(AjaxRequestTarget target) {        
        currentPanel.setFormType(FormType.PRO);
        target.addComponent(currentPanel);
    }
    

    Thus we rebuilt the original panel without recreating it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user control, a dropdown list, that's comprised of many component controls.
I have inherited a jquery component that simulates a dropdown for users to choose
I have this dropdown. I need clone for my other dropdown lists: <select name=general>
I have a dropdown menu that pulls in text from a database column. The
I have a dropdown menu that I am using and can't quite get it
I have several DropDown controls on a Web Form which are filled using AJAX
I have a dropdown menu system setup such as this... This is the scripting
I have a dropdown list(in a php file and without form tag) print <select
I'm using primefaces layout component and have a dropdown List in north layout unit.
I have this dropdown (select) menu generated with JQuery, dynamically using JSON coming from

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.