Hi,

I am fairly new to world of wicket. so my issue might be something very trivial. I am using a simple form to input some fields. and i want to update the table below in the same page with the newly entered info in the form above. Page should not refresh. table should be updated through AJAX.

Looking at various examples, I could get my ajax part working. but. now when i enter details in the form above 2nd time, the refreshed table below replaces all the old entries same as latest entry. e.g. 1st time descr was "1sst time", when i try to submit page second time with description "2nd time" both rows of table now show "2nd time" as description.

Can anyone help pinpoint what i am doing wrong?

Here is the code that i tried.
*Fee.java*

public class Fee extends WebPage {
        private static final Logger logger = LoggerFactory.getLogger(Fee.class);
        private String pageTitle;
        /** Container for the fees table, used to update the listview. */
        private WebMarkupContainer feesContainer;
        private ListView fees;
        private FeeForm form;
        public Fee() {
                super();
                FeeModel fee = new FeeModel();
                CompoundPropertyModel propertyModel = new 
CompoundPropertyModel(fee);
                form = new FeeForm("feeForm", propertyModel);
                pageTitle = "Add Fees and listing of Current Fees!";
                fees = new ListView("fees", getFeesList()) {
                        // This method is called for each 'entry' in the list.
                        @Override
                        protected void populateItem(ListItem item) {
                                FeeModel fee = (FeeModel) item.getModelObject();
                                logger.debug("fee" + fee);
                                item.add(new Label("description", 
fee.getDescr()));
                                item.add(new Label("type", fee.getType()));
                                item.add(new Label("capitalized", 
fee.getCapitalized()));
                                item.add(new Label("taxable", 
fee.getTaxable()));
                                item.add(new Label("amount", 
String.valueOf(fee.getAmount())));
                        }
                };

                add(form);
                TextField descr = new TextField("descr");
                TextField amount = new TextField("amount");
                DropDownChoice type = new DropDownChoice("type", Arrays.asList(new 
String[]{"Registration","Documentation","Others","TaxItems"}));
                RadioChoice taxable = new RadioChoice("taxable");
                CheckBox capitalized = new CheckBox("capitalized");

                Button submitButton = new AjaxButton("submitButton"){
                        @Override
                        protected void onSubmit(AjaxRequestTarget target, Form 
form) {
                                logger.debug("Ajax success: form: ",form);
                                logger.debug("model object 
is"+form.getModelObject());
                                getFeesList().add(form.getModelObject());
                                target.addComponent(feesContainer);
                        }
                        @Override
                        protected void onError(AjaxRequestTarget target, Form 
form) {
                                logger.debug("in ajax error msg");
                                super.onError(target, form);
                        }
                };
                form.add(descr);
                form.add(amount);
                form.add(type);
                form.add(taxable);
                form.add(capitalized);
                form.add(submitButton);
                
                feesContainer = new WebMarkupContainer("feesContainer");
                feesContainer.setOutputMarkupId(true);
                feesContainer.add(fees);
                add(feesContainer);
                
                add(new Label("pageTitle", pageTitle));
        }
        
        private List feesList = new ArrayList();

        public List getFeesList() {
                return feesList;
        }

        public void setFeesList(List feesList) {
                this.feesList = feesList;
        }

}

FeeForm.java

public class FeeForm extends Form{
   private static final Logger log = LoggerFactory.getLogger(FeeForm.class);
   private static final long serialVersionUID = 1L;
   public FeeForm(String id, IModel model) {
       super(id,model);
   }
}

FeeModel.java

public class FeeModel implements Serializable{
        private String descr;
        private double amount;
        private String type ;
        private String taxable ;
        private String capitalized ;;
        // and getters and setters
}



Fee.html






Description:
Amount:
Type:
Taxable: Yes No
Capitalized:
submit


Current Fees are:
#       Description     Type    Capitalized     Taxable         Amount
[3222]  [Registration Fee]      [Documentation]         [No]    [Yes]   
[$200.44]

Can anyone help me out?

Any pointers would be appriciated

--
Cheers,
VJ

Reply via email to