java - How should I better handle loading of Wicket Models when using Wicket forms? -
i in middle of writing form using apache wicket. same page/class used add together new item database , edit existing record in database. of course, since page constructor called once, model set whatever record loaded on page, or new record if we're not editing existing one.
i have found number of ways dynamically load data, seem verbose , little clunky. suspect there best practice handling scenario this.
for reference, here edited code:
public class jobmanagement extends webpage { private static final long serialversionuid = 1l; private long jobid = 0; protected void setjobid(long id) { this.jobid = id; } protected long getjobid() { homecoming jobid; } public jobmanagement() { loadabledetachablemodel<job> jobmodel = new loadabledetachablemodel<job>() { private static final long serialversionuid = 1l; @override protected job load() { job job = (job) entityfactory.getinstance().getbean("job"); // if we're editing existing job, load object if (jobid >= 1) { job.load(jobid); } homecoming job; } }; add(new feedbackpanel("feedbackpanel")); form<job> jobform = new form<job>("jobform") { private static final long serialversionuid = 1l; @override public void onsubmit() { // handles form submit... } }; add(jobform); jobform.setmodel(new compoundpropertymodel<job>(jobmodel)); // snip ... form fields go here! jobform.add(new button("submit")); }
}
i'm using loadabledetachablemodel, it's not exclusively clear me how best handle loading dynamically whenever page rendered. i've attempted load new instance of model, override getobject() class returns loadabledetachablemodel, there's feels wrong that. input appreciated. i've been trying sense way through framework via online documentation exclusively, forgive evident lack of familiarity.
to reply own question, problem experiencing model bound form appeared persist every time returned page. led me believe problem how managing models, problems related how linking pages.
the page above beingness linked follows:
link<string> link = new bookmarkablepagelink<string>("addlink", myaddclass.class);
while acceptable approach in cases, not right approach in particular case. should have happened this:
link<string> link = new link<string>("addlink") { public void onclick() { setresponsepage(new myaddclass()); } }
when links handled dynamically in way, application behaves intended. pitched in help open eyes fundamental problem links.
java wicket wicket-1.6
No comments:
Post a Comment