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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:09:25+00:00 2026-06-02T23:09:25+00:00

I have such problem with Wickets AjaxFormComponentUpdatingBehaviour . When you set this to some

  • 0

I have such problem with Wickets AjaxFormComponentUpdatingBehaviour. When you set this to some components on the form, and add validation to them, after you press “Submit form” button, and, lets say, you get an error, that your component has not passed validation, after that ajax is behaving different, does not update models.

Here is code example:

TextField someText = new TextField("someTextId");
someText.setRequired(true); //added validation on requireness
CheckBox checkBx = new CheckBox("checkBxId");
TextField changeableTxt = new TextField("changeableTxtId");
changeableTxt.setEnabled(false);

checkBx.add(new AjaxFormComponentUpdatingBehaviour("onclick"){
protected void onUpdate(AjaxRequestTarget target) {
    if(compoundModel.isCheckBx()){
         changeableTxt.setEnabled(true);
         target.addComponent(changeableTxt);
    }else{
         compoundModel.setChangeableTxt(null);
         changeableTxt.setEnabled(false);
         target.addComponent(changeableTxt);
    }
  }
});
Form form = new Form("form", compoundModel);
form.add(someText, checkBx, changeableTxt);
add(form);

So if check the checkBx, input some value to changeableTxt, leave someText empty and press submit button, error will appear, that field someText is required. After that, if we click on checkBx, it will make changeableTxt field disabled, but it will leave before the input value inside, instead of null.

  • 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-02T23:09:26+00:00Added an answer on June 2, 2026 at 11:09 pm

    Well let’s start with explaining why you might think your code is working:
    The AjaxFormComponentUpdatingBehavior will update the model of your CheckBox but only this model. That means that the changeableTxt will even stay empty if you remove the code line compoundModel.setChangeableTxt(null);

    So if the Checkbox is supposed to change the value of the changeableTxt TextField it should submit the value it has while clicking it as well. You can achieve this by wrapping a Form around checkBx and changeableTxt and submit this form when click on the CheckBox by using a AjaxFormSubmitBehavior.

    public class TestingPanel extends Panel {
        public TestingPanel(String id) {
        super(id);
    
        final CompoundModel compoundModel = new CompoundModel();
    
        final Form<CompoundModel> form = new Form<CompoundModel>("form",
                new CompoundPropertyModel<CompoundModel>(compoundModel)) {
            @Override
            protected void onValidate() {
                System.out.println("validate: "
                        + compoundModel.getChangeableTxt());
                System.out.println("validate: "
                        + getModel().getObject().getChangeableTxt());
    
                super.onValidate();
            }
        };
        form.setOutputMarkupId(true);
        add(form);
    
        TextField someText = new TextField("someText");
        someText.setRequired(true); // added validation on requireness
        final CheckBox checkBx = new CheckBox("checkBx");
        final TextField changeableTxt = new TextField("changeableTxt");
        changeableTxt.setOutputMarkupId(true);
        changeableTxt.setEnabled(false);
    
        Form checkBoxForm = new Form("checkBoxForm");
        form.add(checkBoxForm);
    
        AjaxFormSubmitBehavior submitBehavior = new AjaxFormSubmitBehavior(
                checkBoxForm, "onclick") {
    
            @Override
            protected void onSubmit(AjaxRequestTarget target) {
                if (checkBx.getModelObject() == true) {
                    changeableTxt.setEnabled(true);
                    target.add(changeableTxt);
                } else {
                    compoundModel.setChangeableTxt(null);
                    changeableTxt.setEnabled(false);
                    target.add(changeableTxt);
                }
    
            }
    
            @Override
            protected void onError(AjaxRequestTarget target) {
    
            }
        };
        checkBx.add(submitBehavior);
        checkBoxForm.add(checkBx, changeableTxt);
    
        AjaxFormComponentUpdatingBehavior updateBehavior = new AjaxFormComponentUpdatingBehavior(
                "onclick") {
            protected void onUpdate(AjaxRequestTarget target) {
                if (compoundModel.isCheckBx()) {
                    changeableTxt.setEnabled(true);
                    target.addComponent(changeableTxt);
                } else {
                    // compoundModel.setChangeableTxt("");
                    changeableTxt.setEnabled(false);
                    target.add(changeableTxt);
                }
            }
        };
    
        form.add(someText);
    
        FeedbackPanel feedbackPanel = new FeedbackPanel("feedbackPanel");
        form.add(feedbackPanel);
    
        AjaxSubmitLink submit = new AjaxSubmitLink("submit", form) {
    
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                target.add(form);
            }
    
            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                target.add(form);
    
            }
        };
        add(submit);
    
    }
    
    class CompoundModel implements Serializable {
    
        private boolean checkBx = false;
    
        private String someText = null;
    
        private String changeableTxt = null;
    
        public boolean isCheckBx() {
            return checkBx;
        }
    
        public void setCheckBx(boolean checkBx) {
            this.checkBx = checkBx;
        }
    
        public String getSomeText() {
            return someText;
        }
    
        public void setSomeText(String someText) {
            this.someText = someText;
        }
    
        public String getChangeableTxt() {
            return changeableTxt;
        }
    
        public void setChangeableTxt(String changeableTxt) {
            this.changeableTxt = changeableTxt;
        }
    
    }
    }
    

    with the following html:

    <!DOCTYPE html>
    <html xmlns:wicket="http://wicket.apache.org">
    <wicket:panel>
        <form wicket:id="form">
            <div wicket:id="feedbackPanel" />
            <input type="text" wicket:id="someText"  /><br />
            <form wicket:id="checkBoxForm">
                <input type="checkbox" wicket:id="checkBx" /><br />
                <input type="text" wicket:id="changeableTxt" /><br />
            </form>
        </form>
        <a wicket:id="submit">submit</a>
    </wicket:panel>
    

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

Sidebar

Related Questions

I have some problem whith such mysql_query INSERT INTO table VALUES ('', CURDATE()-1) why
I have some complicated, problem to be solved. Now I need to write such
I have such problem: I have 2 custom components, which have their own nesting
I have such text: <Neednt@email.com> If you do so, please include this problem report.
I have this problem when I try to getDefinitionByName('some_var_by_class_linkage') . But I have such
Problem I have such code var ls = src.iter.toList src.iter = ls.iterator (this is
I have such problem: I'm using rails, devise gem and jQuery validation plugin. I
I have such a basic problem in Delphi,I can't solve it. My Code: Note:DataR
I have a problem such that i have zip files uploaded from forms and
Maybe somebody had faced with such problem? I just have tried to use Video-JS

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.