0

I have one panel in Wicket. Inside i have 2 separates forms. In the second form i have 2 dropdowns, the second is dependant the forst one, indeed once selected a value in second i can lokk in the database for a list dynamically loaded from DB following firest selection.

I am stucked because i never managed to retrieve the form component model, but when i submit it (form) my values are present (exceptc the field needed because it needs itself another field value). So the issue i access to my models only after form submit not before

here the form creation:

var visitForm = new Form<>( "visitForm", new CompoundPropertyModel<>( new VisitModel() )) {
        @Override
        protected void onSubmit() {
            this.getModelObject().getVisitors().add( getPanelEntity() );
            VisitDAO.getInstance().persist( this.getModelObject() );
        }
    };
    visitForm.setOutputMarkupId( true );

then form initialization

        var companyDropDownChoice = some code... ;
        companyDropDownChoice.setRequired( true );
        companyDropDownChoice.setOutputMarkupId( true );
        visitForm.add( companyDropDownChoice );

        final var addVisitedPersonAutoCompleteField = new Select2Choice<>( "addVisitedPerson", visitedPersonModel, new ChoiceProvider<String>() 
            @Override
            public void query(String term, int page, Response<String> response) {

        // HERE I try many differents way to fin model                  

         companyDropDownChoice.getModelObject();//null
                companyDropDownChoice.getModel();//null
                getParent();
                visitForm.getModelObject().getCompanyVisited(); //null

        addVisitedPersonAutoCompleteField.setOutputMarkupPlaceholderTag( true );
        visitForm.add( addVisitedPersonAutoCompleteField );

        companyDropDownChoice.add( OnChangeAjaxBehavior.onChange( target -> {

            target.add( addVisitedPersonAutoCompleteField );
        } ) ); // i think this is useless as it is usefull oustside form

Any idea ?

2
  • what model did you pass to companyDropDownChoice ? Commented Jan 25, 2023 at 6:45
  • first i tried with form.getModel but not working, then i put null, and just use a model for the selection and use it, because i dont want a entire model because just used in the form so i thought to use the form model itself works because the ajaxBehavior use and fired the model modification, but was always null Commented Jan 31, 2023 at 7:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.