如何在 Wicket 中的表单上实现后退按钮支持?
我有一个带有选项卡式面板的搜索页面,每个选项卡内都有一个表单(请参阅下面的代码),提交后会在数据库中搜索命中。但是,此表单上的后退按钮支持不起作用(用户在文本字段中提供的文本丢失)。如何实现此表单的后退按钮支持?我一直在尝试在页面、面板、表单和文本字段上发出 setVersioned(true) ,并结合文本字段和表单上的 modelChanging() 和 modelChanged() ,但这些都不起作用。我还尝试过从 TabbedPanel 重写方法 newLink,详细信息此处,但这也不起作用。我不知所措...
任何帮助将不胜感激。
public class TextSearchPanel extends Panel {
CompoundsDataTablePanel hitsPanel;
@SpringBean
ICompoundDAO compoundDAO;
public TextSearchPanel(final String id, final FeedbackPanelWrapper feedbackPanel) {
super(id);
setOutputMarkupId(true);
// Text Search Form
Form<TextSearchPanel> textform = new Form<TextSearchPanel>("textForm");
// Add textField
TextField<String> textField = new TextField<String>("query", new Model<String>());
textField.setRequired(true);
textField.add(new StringValidator() {
@Override
protected void onValidate(final IValidatable<String> validatable) {
String query = Name.replaceApostropheVariantsWithApostrophe(validatable.getValue());
try {
// Ascertain parsing query does not throw an exception
compoundDAO.parseQuery(query);
}
catch (ParseException e) {
// Otherwise: Display the error back to the user
validatable.error(new ValidationError().setMessage(e.getMessage()));
}
}
});
textform.add(textField);
// Add submit button
textform.add(new IndicatingAjaxButton("ajaxsubmit") {
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
target.addComponent(feedbackPanel);
// Show hits panel
hitsPanel.setVisible(true);
target.addComponent(TextSearchPanel.this);
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
target.addComponent(feedbackPanel);
// Hide hits panel
hitsPanel.setVisible(false);
target.addComponent(TextSearchPanel.this);
}
});
add(textform);
// Text Hits Panel
hitsPanel = new CompoundsDataTablePanel("hits", new TextHitsProvider(textField.getModel()));
hitsPanel.setVisible(false);
add(hitsPanel);
}
}
页面类:
public class SearchPage extends BasePage {
public SearchPage() {
super("Search");
setOutputMarkupId(true);
List<ITab> tabs = new ArrayList<ITab>();
tabs.add(new AbstractTab(new Model<String>("Spectrum search")) {
@Override
public Panel getPanel(final String panelId) {
return new SpectrumSearchPanel(panelId, getFeedbackPanelWrapper());
}
});
tabs.add(new AbstractTab(new Model<String>("Mass search")) {
@Override
public Panel getPanel(final String panelId) {
return new MassSearchPanel(panelId, getFeedbackPanelWrapper());
}
});
tabs.add(new AbstractTab(new Model<String>("Formula search")) {
@Override
public Panel getPanel(final String panelId) {
return new FormulaSearchPanel(panelId, getFeedbackPanelWrapper());
}
});
tabs.add(new AbstractTab(new Model<String>("Text search")) {
@Override
public Panel getPanel(final String panelId) {
return new TextSearchPanel(panelId, getFeedbackPanelWrapper());
}
});
// Add tabs to page to switch between search modes
add(new TabbedPanel("tabs", tabs));
}
}
I have a search page with a tabbed panel, with a form within each tab (see code below), that when submitted searches the database for hits. However, back button support on this form is not working (user supplied text in textField is lost). How do I implement back button support for this form? I have been playing around with issuing setVersioned(true) on the page, panel, form and textField in combination with modelChanging() and modelChanged() on the textField and the form, but none of those have worked. I have also tried overriding method newLink from TabbedPanel as detailed here, but that has not worked either. I'm at a loss...
Any help would be greatly appreciated.
public class TextSearchPanel extends Panel {
CompoundsDataTablePanel hitsPanel;
@SpringBean
ICompoundDAO compoundDAO;
public TextSearchPanel(final String id, final FeedbackPanelWrapper feedbackPanel) {
super(id);
setOutputMarkupId(true);
// Text Search Form
Form<TextSearchPanel> textform = new Form<TextSearchPanel>("textForm");
// Add textField
TextField<String> textField = new TextField<String>("query", new Model<String>());
textField.setRequired(true);
textField.add(new StringValidator() {
@Override
protected void onValidate(final IValidatable<String> validatable) {
String query = Name.replaceApostropheVariantsWithApostrophe(validatable.getValue());
try {
// Ascertain parsing query does not throw an exception
compoundDAO.parseQuery(query);
}
catch (ParseException e) {
// Otherwise: Display the error back to the user
validatable.error(new ValidationError().setMessage(e.getMessage()));
}
}
});
textform.add(textField);
// Add submit button
textform.add(new IndicatingAjaxButton("ajaxsubmit") {
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
target.addComponent(feedbackPanel);
// Show hits panel
hitsPanel.setVisible(true);
target.addComponent(TextSearchPanel.this);
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
target.addComponent(feedbackPanel);
// Hide hits panel
hitsPanel.setVisible(false);
target.addComponent(TextSearchPanel.this);
}
});
add(textform);
// Text Hits Panel
hitsPanel = new CompoundsDataTablePanel("hits", new TextHitsProvider(textField.getModel()));
hitsPanel.setVisible(false);
add(hitsPanel);
}
}
Page class:
public class SearchPage extends BasePage {
public SearchPage() {
super("Search");
setOutputMarkupId(true);
List<ITab> tabs = new ArrayList<ITab>();
tabs.add(new AbstractTab(new Model<String>("Spectrum search")) {
@Override
public Panel getPanel(final String panelId) {
return new SpectrumSearchPanel(panelId, getFeedbackPanelWrapper());
}
});
tabs.add(new AbstractTab(new Model<String>("Mass search")) {
@Override
public Panel getPanel(final String panelId) {
return new MassSearchPanel(panelId, getFeedbackPanelWrapper());
}
});
tabs.add(new AbstractTab(new Model<String>("Formula search")) {
@Override
public Panel getPanel(final String panelId) {
return new FormulaSearchPanel(panelId, getFeedbackPanelWrapper());
}
});
tabs.add(new AbstractTab(new Model<String>("Text search")) {
@Override
public Panel getPanel(final String panelId) {
return new TextSearchPanel(panelId, getFeedbackPanelWrapper());
}
});
// Add tabs to page to switch between search modes
add(new TabbedPanel("tabs", tabs));
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有机会尝试你的代码,但这可能是使用ajax的问题。 wicket 中的 ajax 尚不完全支持后退按钮:https://issues.apache。 org/jira/browse/WICKET-271。与第一次查看相比,您可能需要检查按下后退按钮时正在查看的页面的版本。
I haven't had chance to try your code out, but could it be a problem with the use of ajax. The back button is not fully supported with ajax in wicket yet: https://issues.apache.org/jira/browse/WICKET-271. You may want to check the versions of the pages you are viewing when pressing the back button when compared with viewing it the first time.