2
我有一個帶有選項卡式面板的搜索頁面,每個選項卡中都有一個表單(請參閱下面的代碼),它們在提交時搜索數據庫中的匹配。但是,此表單上的後退按鈕支持不起作用(用戶在textField中提供的文本丟失)。如何實現此表單的後退按鈕支持?我在頁面,面板,窗體和textField上發佈了setVersioned(true),並在textField和窗體上使用了modelChanging()和modelChanged(),但都沒有奏效。我也嘗試從TabbedPanel重寫方法newLink作爲詳細的here,但那也沒有奏效。我不知所措...如何在Wicket窗體上實現後退按鈕支持?
任何幫助將不勝感激。
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類:
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));
}
}
謝謝Tnem!確實,問題出在IndicatingAjaxButton上。我用html中的常規提交按鈕替換了這個,並在窗體上添加了onSubmit和onError覆蓋方法,以調整結果面板何時可見。現在起作用了。 – Simmer 2011-04-08 11:04:28