Get model object from another component in same form in WIcket 9.2

79 Views Asked by At

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 ?

0

There are 0 best solutions below