Hello, Here is my scenario. I have a 2 page Wizard. The first page asks you to type in the primary key of a table. If that row already exists in the table, the second page gets loaded with the rest of that row's data. So, in summary, the first page of the wizard should be able to populate the second page.
But here's my problem: The first page only populates the 2nd page if I haven't visited the second page yet. If, on the second page, I click the "previous" button and then pick a new primary key, when I visit the 2nd page again, the input fields are not updated. I've used the debugger to see that the Model Object *is* being updated. I can't figure out why this is happening. I only use PropertyModels (those are dynamic models, right?). I can only guess that the Wizard serializes the steps you've visited and doesn't check if the model has changed when you go back to them. One last thing that may be revealing: One of the things that second page displays is a listview of fields. If the second primary key I pick has more items in the list than the first one, the extra items do get populated on the page. IE: First pk has 3 items. Second pk has 4 items. The second page will have the correct 4th item in the list but the first 3 will be of the first pk. Here is my code in a pastebin: http://pastebin.org/26606 Here is my code inlined into the email: package com.haverlocke.tellah.web.component; import com.haverlocke.tellah.model.dao.WebsiteDao; import com.haverlocke.tellah.model.dao.WebsiteHistoryDao; import com.haverlocke.tellah.model.dto.LinkDto; import com.haverlocke.tellah.model.dto.WebsiteDto; import com.haverlocke.tellah.web.model.TellahUrlValidator; import com.haverlocke.tellah.web.page.HomePage; import com.haverlocke.tellah.web.util.SimilarWebsiteUtil; import com.haverlocke.tellah.web.component.recaptcha.ReCaptchaPanel; import net.databinder.components.AjaxOnKeyPausedUpdater; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.form.AjaxButton; import org.apache.wicket.behavior.HeaderContributor; import org.apache.wicket.extensions.wizard.Wizard; import org.apache.wicket.extensions.wizard.WizardModel; import org.apache.wicket.extensions.wizard.WizardStep; import org.apache.wicket.feedback.FeedbackMessage; import org.apache.wicket.feedback.IFeedbackMessageFilter; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.markup.html.form.TextArea; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.panel.FeedbackPanel; import org.apache.wicket.model.PropertyModel; import org.apache.wicket.model.IModel; import org.apache.wicket.spring.injection.annot.SpringBean; import org.apache.wicket.PageParameters; import org.apache.wicket.Component; import java.util.List; /** * @author Daniel Kaplan * @since 7.10.5 */ public class SubmitWizard extends Wizard { private static final String PUBLIC_DEV = "fake"; private static final String PRIVATE_DEV = "fake"; @SpringBean private WebsiteDao websiteDao; @SpringBean private WebsiteHistoryDao websiteHistoryDao; private WebsiteDto websiteDto = new WebsiteDto(); private Label note; private String noteString; private boolean insert; public SubmitWizard(String id, PageParameters pp) { super(id, false); insert = pp.getString("websiteName") == null || "".equals(pp.getString("websiteName")); WizardModel model = new WizardModel(); model.add(new WebsiteName()); WebsiteDetails websiteDetails = new WebsiteDetails(); model.add(websiteDetails); init(model); websiteDetails.addReCaptchaPanel(); initPage(pp.getString("websiteName")); } @Override public void onFinish() { new WizardFinishedAction(new PropertyModel(this, "websiteDto"), getPage()).onSubmit(); } @Override public void onCancel() { setRedirect(true); setResponsePage(HomePage.class); } @Override protected FeedbackPanel newFeedbackPanel(String id) { return new FeedbackPanel(id, new IFeedbackMessageFilter() { public boolean accept(FeedbackMessage message) { //never show anything. We show all messages in a different panel defined in the WizardPage.java return false; } }); } private class WebsiteName extends WizardStep { public WebsiteName() { add(HeaderContributor.forCss("images/submit.css")); if (insert) { add(new Label("formHeader", "Set the name")); } else { add(new Label("formHeader", "Edit the name")); } TextField name = new TextField("name", new PropertyModel(websiteDto, "name")); add(name.setRequired(true).add(new WebsiteLoadBehavior())); note = new Label("note", new PropertyModel(SubmitWizard.this, "noteString")); add(note.setOutputMarkupId(true)); } } private class WebsiteDetails extends WizardStep { public WebsiteDetails() { add(HeaderContributor.forCss("images/submit.css")); if (insert) { add(new Label("formHeader", "Set the details")); } else { add(new Label("formHeader", "Edit the details")); } TextField url = new TextField("url", new PropertyModel(websiteDto, "url")); add(url.add(new TellahUrlValidator(new String[]{"http", "https"})) .setOutputMarkupId(true)); TextArea idea = new TextArea("idea", new PropertyModel(websiteDto, "whatItDoes")); add(idea.setOutputMarkupId(true)); TextArea revenueSource = new TextArea("revenueSource", new PropertyModel(websiteDto, "revenueSource")); add(revenueSource.setOutputMarkupId(true)); TagArea tagArea = new TagArea("tags", websiteDto); add(tagArea.setOutputMarkupId(true)); AjaxButton addSimilarButton = new AjaxButton("addSimilar") { protected void onSubmit(AjaxRequestTarget target, Form form) { SubmitWizard.this.websiteDto.getSimilarTos().add(""); target.addComponent(form); } }; add(addSimilarButton.setDefaultFormProcessing(false).setOutputMarkupId(true) ); SimilarToList similarToList = new SimilarToList("similarToList", new PropertyModel(websiteDto, "similarTos")); add(similarToList.setOutputMarkupId(true)); AjaxButton addLinkButton = new AjaxButton("addLink") { protected void onSubmit(AjaxRequestTarget target, Form form) { SubmitWizard.this.websiteDto.getLinks().add(new LinkDto()); target.addComponent(form); } }; add(addLinkButton.setDefaultFormProcessing(false).setOutputMarkupId(true)); LinkList linkList = new LinkList("linkList", new PropertyModel(websiteDto, "links")); add(linkList.setRenderBodyOnly(true)); WebsiteHistoryPanel websiteHistoryPanel = new WebsiteHistoryPanel("websiteHistoryPanel", new PropertyModel(this, "websiteDto")); add(websiteHistoryPanel.setOutputMarkupPlaceholderTag(true)); websiteHistoryPanel.setVisible(websiteHistoryDao.isHistory(websiteDto.getNam e())); } /** * We need to do this separately from the constructor because the getForm() * doesn't work until after Wizard#init(model); is called */ public void addReCaptchaPanel() { add(new ReCaptchaPanel("recaptcha", false, PUBLIC_DEV, PRIVATE_DEV, "Invalid Captcha", getForm())); } } private class WebsiteLoadBehavior extends AjaxOnKeyPausedUpdater { protected void onUpdate(AjaxRequestTarget target) { initPage(websiteDto.getName()); target.addComponent(note); } } private void initPage(String websiteName) { if (websiteName != null) { WebsiteDto ws = websiteDao.getWebsite(websiteName); if (ws != null) { websiteDto.become(ws); } } updateNoteString(); websiteDto.removeEmptyLinks(); websiteDto.getLinks().add(new LinkDto()); websiteDto.removeEmptySimilarTos(); websiteDto.getSimilarTos().add(""); } public void updateNoteString() { if (websiteDto != null && websiteDto.getName() != null) { List<String> similars = websiteDao.getSimilarNames(websiteDto.getName()); noteString = SimilarWebsiteUtil.getSimilarWebsiteMessage(similars); } else { noteString = ""; } } public WebsiteDto getWebsiteDto() { return websiteDto; } public void setWebsiteDto(WebsiteDto websiteDto) { this.websiteDto = websiteDto; } public String getNoteString() { return noteString; } public void setNoteString(String noteString) { this.noteString = noteString; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
