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 9216287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:23:09+00:00 2026-06-18T02:23:09+00:00

I have a java class: public Task { private int id; private Company sender;

  • 0
  1. I have a java class:

    public Task {
    
        private int id;
        private Company sender;
        private Company receiver;
    
        //Getter and Setter
        ...
    }
    

    As you can see, I have 2 other custom classes in the task class. And a company has for example Adress and Directory.

  2. I have a CompanyPanel which will reusable be used on the Page. Here is some code from the panel.

    public class CompanyPanel extends Panel {
    
        protected List<Company> companies;
    
        public CompanyPanel(String id, IModel<Company> model) {
    
        super(id,new CompoundPropertyModel<Company>(model));
        companies = new ArrayList<Company>();
    
        Company company_1 = new Company();
            //Setting default predefined values for the company, so I can select it from the dropdown and to set fields automatically
    
        company_1.setFtpAdress("adress1.com");
        company_1.setFtpDir("/MusterDir/");
        companies.add(company_1);
    
        //SAME for another company
                ...
        companies.add(comany_2);
                ...
    
        final DropDownChoice<Company> companyList = new DropDownChoice<Company>("companies", model,
            new LoadableDetachableModel<List<Company>>() {
        @Override
        protected List<Company> load() { 
            return companies;
        }
        }){
            protected boolean wantOnSelectionChangedNotifications() {
            return true;
            }
        };
        add(companyList);
    
        final TextField<String> ftpAdress = new TextField<String>("ftpAdress");
        ftpAdress.setOutputMarkupId(true);
        add(ftpAdress);
    
        final TextField<String> ftpDir = new TextField<String>("ftpDir");
        ftpDir.setOutputMarkupId(true);
        add(ftpDir);
    
         //added Ajax to dropdown to update textfields automatically, based on selection of dropdown
        companyList.add(new AjaxFormComponentUpdatingBehavior("onchange")
        {
        @Override
        protected void onUpdate(AjaxRequestTarget target)
        {
            target.add(ftpAdress);
            target.add(ftpDir);
        }
        });
      }
    }
    
  3. In the Page I use reuseable CompanyPanels.

    ...
    CompanyPanel senderPanel = new CompanyPanel("senderPanel", new PropertyModel(task,"sender"));
    senderPanel.setOutputMarkupId(true);
    form.add(senderPanel);
    
    CompanyPanel receiverPanel = new CompanyPanel("receiverPanel", new PropertyModel(task,"receiver"));
    receiverPanel.setOutputMarkupId(true);
    form.add(receiverPanel);
    ...
    
  4. When I submit the form I do:

    public void onSubmit(AjaxRequestTarget target, Form<?> form) {
    
        //doSomething
        target.add(senderPanel);
        target.add(receiverPanel);
    
    }
    

The problem: The company panel is not being rerendered. And I don’t really know why.

Workflow:

  1. I select a company from the dropdown panel
  2. The TextFields(which are inside the companyPanel) will be set correctly, based on the dropdown
  3. I modify a textField (which belongs to a company)
  4. I submit the form
  5. I change the company from the dropdown list
  6. I change back to the first company -> PROBLEM: the modified textfields displays still the modified text inside. It was not reseted to the default values.

Any help very appreciated.

  • 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-18T02:23:10+00:00Added an answer on June 18, 2026 at 2:23 am

    Of course they will display the modified values. You create a list of companies in the CompanyPanel constructor. When you modify a company’s data, the object is modified inside that list.

    A quick way to fix this would be to replace the CompanyPanel panel with a new instance of CompanyPanel in your onSubmit method. That would recreate the list of companies with your default values. You would of course lose the modified values.

    Another possibly better fix is to move the companies list creation into the loadabledetachablemodel:

    final DropDownChoice<Company> companyList = new DropDownChoice<Company>("companies", model,
        new LoadableDetachableModel<List<Company>>() {
    @Override
    protected List<Company> load() { 
        List<Company>companies = new ArrayList<Company>();
    
        Company company_1 = new Company();
        //Setting default predefined values for the company, so I can select it from the dropdown and to set fields automatically
    
        company_1.setFtpAdress("adress1.com");
        company_1.setFtpDir("/MusterDir/");
        companies.add(company_1);
    
    //SAME for another company
            ...
        companies.add(comany_2);
            ...
    
        return companies;
    }
    

    This way the list of companies is recreated on every request with the default values.

    Make sure you implement a proper equals() and hashCode() method in Company though for DropDownChoice to show the proper selected element though – because in this scenario the object in your model and the objects in the list may never be ==.

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

Sidebar

Related Questions

If I have a java class which is package-private (declared with class, not public
I have this class public class wordObject implements java.io.Serializable { String wordName; int occCount;
i have a java class like this public class A { private String field1;
I have a Java class, Node as follows : class Node { public ArrayList<Node>
I have a simple Java class that has some methods: public class Utils {
I have create a Java class extending LinearLayout as shown below public class CustomLinear
I have create a Java class extending LinearLayout as shown below public class News
Let's say I have a regular simple Java class, such as: public class Foo
In java I have: public class MyClass{ public enum STATUS { ZERO, ONE ,
Say suppose I have the following Java code. public class Example { public static

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.