重复视图检票口上的验证器
Validator on repeatview wicket
我在重复视图(快速视图)上插入输入。当该输入有错误时(例如:RequiredValidator),提交事件将停止,但不会显示错误。如何在重复视图中验证和显示错误?
AddBaseEstimatePanel.java
public class AddBaseEstimatePanel extends Panel {
private void initForm(final Form<Estimate> form, final FeedbackPanel feedbackPanel) {
...
IDataProvider<EstimateDetailModel> data = new ListDataProvider<EstimateDetailModel>(
listEstimateDetailModel);
final WebMarkupContainer mitsumoriDeitaShōsaiRowssTable = new WebMarkupContainer(
"mitsumoriDeitaShōsaiRowssTable");
final EstimateDetailListAddTable mitsumoriDeitaShōsaiRows = new EstimateDetailListAddTable(
"mitsumoriDeitaShōsaiRows", data, listEstimateDetailModel,
new ItemsNavigationStrategy(), 10, start, null) {
private static final long serialVersionUID = 3950744346751551366L;
@Override
protected void initRow() {
super.initRow();
// addNewItems(initProductEmptyRows(5));
}
@Override
protected void onCheckBoxChange(EstimateDetailModel model,
AjaxRequestTarget target) {
super.onCheckBoxChange(model, target);
if (model.isChecked()) {
deleteProductBtn.setEnabled(true);
} else {
deleteProductBtn.setEnabled(hasCheckBoxChecked());
}
checkAll = allCheckboxIsChecked();
target.add(deleteProductBtn, checkAllCheckbox);
}
@Override
protected void onKeyTeikyo(AjaxRequestTarget target) {
super.onKeyTeikyo(target);
addNewItems(initProductEmptyRows(1));
}
@Override
protected void countTotal(EstimateDetailModel model,
AjaxRequestTarget target, Component... components) {
if (model.getUnitPrice() == null || model.getQuantity() == null) {
return;
}
float _amount = model.getUnitPrice() * model.getQuantity();
countTotal -= model.getAmount();
model.setAmount(_amount);
countTotal += model.getAmount();
target.add(total);
target.add(components);
}
};
mitsumoriDeitaShōsaiRowssTable.add(mitsumoriDeitaShōsaiRows);
...
}
EstimateDetailListAddTable.java
public abstract class EstimateDetailListAddTable extends
QuickView<EstimateDetailModel> {
@Override
protected void populate(final Item<EstimateDetailModel> item) {
CheckBoxAjaxChange checkbox = new CheckBoxAjaxChange("checkbox",
new PropertyModel<Boolean>(item.getModel(), "checked")) {
private static final long serialVersionUID = 3455428602642567322L;
@Override
protected void onCheckChange(final AjaxRequestTarget target) {
if (item.getModelObject().isChecked()) {
selectedItems.add(item);
} else {
selectedItems.remove(item);
}
onCheckBoxChange(item.getModelObject(), target);
}
};
Label no = new Label("no", new PropertyModel<Integer>(item.getModel(),
"no"));
final Select2ChoiceBase<Product> codeSelect = new Select2ChoiceBase<Product>(
"code", new PropertyModel<Product>(item.getModel(), "product"),
new ProductIdProvider(products, estimateDetailModels)) {
private static final long serialVersionUID = 737457596926341699L;
@Override
protected void config() {
super.config();
getSettings()
.setFormatSelection(
"function(obj){ if(obj.id==0)return '';return obj.id; }");
}
};
final Select2ChoiceBase<Product> nameSelect = new Select2ChoiceBase<Product>(
"name", new PropertyModel<Product>(item.getModel(), "product"),
new ProductNameProvider(products, estimateDetailModels));
final NumberTextField<Float> amount = new NumberTextField<Float>(
"amount", new PropertyModel<Float>(item.getModel(), "amount")) {
private static final long serialVersionUID = -2316554599671359643L;
};
final NumberTextField<Integer> quantity = new NumberTextField<Integer>(
"quantity", new PropertyModel<Integer>(item.getModel(),
"quantity")) {
private static final long serialVersionUID = -5753172372351592833L;
@Override
public void renderHead(IHeaderResponse response) {
String script = "$('#" + getMarkupId()
+ "').number( true, 0 );";
response.render(OnDomReadyHeaderItem.forScript(script));
}
};
quantity.setOutputMarkupId(true);
final TextField<String> unit = new TextField<String>("unit",
new PropertyModel<String>(item.getModel(), "product.unit")) {
private static final long serialVersionUID = -2316554599671359643L;
@SuppressWarnings("unchecked")
@Override
public <C> IConverter<C> getConverter(Class<C> type) {
return (IConverter<C>) new UnitConverter();
}
};
final NumberTextField<Integer> price = new NumberTextField<Integer>(
"price", new PropertyModel<Integer>(item.getModel(),
"unitPrice")) {
private static final long serialVersionUID = -8646496003644699535L;
};
unit.setOutputMarkupId(true);
price.setOutputMarkupId(true);
amount.setOutputMarkupId(true);
quantity.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1563937210317123609L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
onQuantityChange(item.getModelObject(), target, amount);
}
});
price.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = -8638379626220896934L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
onPriceChange(item.getModelObject(), target, amount);
}
});
codeSelect.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 7159818718453062684L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
onCodeChange(item, target, nameSelect, quantity, unit, price,
amount);
}
});
nameSelect.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = -7575744336298650067L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
onNameChange(item, target, codeSelect, quantity, unit, price,
amount);
}
});
final TextArea<String> apply = new TextArea<String>("apply",
new PropertyModel<String>(item.getModel(), "tekiyo"));
apply.add(new AbstractDefaultAjaxBehavior() {
private static final long serialVersionUID = 3598447798201761103L;
@Override
protected void respond(AjaxRequestTarget target) {
onKeyTeikyo(target);
}
@Override
public void renderHead(Component component, IHeaderResponse response) {
super.renderHead(component, response);
// response.render();
}
});
apply.add(StringValidator.maximumLength(40));
apply.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
// target.add(apply);
}
});
item.add(checkbox);
item.add(no);
item.add(codeSelect);
item.add(nameSelect);
item.add(quantity);
item.add(price);
item.add(unit);
item.add(amount);
item.add(apply);
// item.add(new EstimateDetailValidator(item.getModelObject()));
}
}
关于 QuicketView:https://github.com/vineetsemwal/quickview
此外,您应该将 IValidator 分配给 FormComponent and/or IFormValidator 分配给 Form 组件。向项目添加验证器不会执行任何操作。
刚刚在 git 上推送了 master 中的更改,ReuseAllStrategy 现在不应该在重新渲染时显示陈旧数据,如果问题仍然存在或新更改破坏了其他一些东西;)在 [=14 中创建一个问题=]枢纽。
打算对您之前回答的问题发表评论,但意识到您应该发表评论或投票 :)
(抱歉回复晚了)
我在重复视图(快速视图)上插入输入。当该输入有错误时(例如:RequiredValidator),提交事件将停止,但不会显示错误。如何在重复视图中验证和显示错误?
AddBaseEstimatePanel.java
public class AddBaseEstimatePanel extends Panel {
private void initForm(final Form<Estimate> form, final FeedbackPanel feedbackPanel) {
...
IDataProvider<EstimateDetailModel> data = new ListDataProvider<EstimateDetailModel>(
listEstimateDetailModel);
final WebMarkupContainer mitsumoriDeitaShōsaiRowssTable = new WebMarkupContainer(
"mitsumoriDeitaShōsaiRowssTable");
final EstimateDetailListAddTable mitsumoriDeitaShōsaiRows = new EstimateDetailListAddTable(
"mitsumoriDeitaShōsaiRows", data, listEstimateDetailModel,
new ItemsNavigationStrategy(), 10, start, null) {
private static final long serialVersionUID = 3950744346751551366L;
@Override
protected void initRow() {
super.initRow();
// addNewItems(initProductEmptyRows(5));
}
@Override
protected void onCheckBoxChange(EstimateDetailModel model,
AjaxRequestTarget target) {
super.onCheckBoxChange(model, target);
if (model.isChecked()) {
deleteProductBtn.setEnabled(true);
} else {
deleteProductBtn.setEnabled(hasCheckBoxChecked());
}
checkAll = allCheckboxIsChecked();
target.add(deleteProductBtn, checkAllCheckbox);
}
@Override
protected void onKeyTeikyo(AjaxRequestTarget target) {
super.onKeyTeikyo(target);
addNewItems(initProductEmptyRows(1));
}
@Override
protected void countTotal(EstimateDetailModel model,
AjaxRequestTarget target, Component... components) {
if (model.getUnitPrice() == null || model.getQuantity() == null) {
return;
}
float _amount = model.getUnitPrice() * model.getQuantity();
countTotal -= model.getAmount();
model.setAmount(_amount);
countTotal += model.getAmount();
target.add(total);
target.add(components);
}
};
mitsumoriDeitaShōsaiRowssTable.add(mitsumoriDeitaShōsaiRows);
...
}
EstimateDetailListAddTable.java
public abstract class EstimateDetailListAddTable extends
QuickView<EstimateDetailModel> {
@Override
protected void populate(final Item<EstimateDetailModel> item) {
CheckBoxAjaxChange checkbox = new CheckBoxAjaxChange("checkbox",
new PropertyModel<Boolean>(item.getModel(), "checked")) {
private static final long serialVersionUID = 3455428602642567322L;
@Override
protected void onCheckChange(final AjaxRequestTarget target) {
if (item.getModelObject().isChecked()) {
selectedItems.add(item);
} else {
selectedItems.remove(item);
}
onCheckBoxChange(item.getModelObject(), target);
}
};
Label no = new Label("no", new PropertyModel<Integer>(item.getModel(),
"no"));
final Select2ChoiceBase<Product> codeSelect = new Select2ChoiceBase<Product>(
"code", new PropertyModel<Product>(item.getModel(), "product"),
new ProductIdProvider(products, estimateDetailModels)) {
private static final long serialVersionUID = 737457596926341699L;
@Override
protected void config() {
super.config();
getSettings()
.setFormatSelection(
"function(obj){ if(obj.id==0)return '';return obj.id; }");
}
};
final Select2ChoiceBase<Product> nameSelect = new Select2ChoiceBase<Product>(
"name", new PropertyModel<Product>(item.getModel(), "product"),
new ProductNameProvider(products, estimateDetailModels));
final NumberTextField<Float> amount = new NumberTextField<Float>(
"amount", new PropertyModel<Float>(item.getModel(), "amount")) {
private static final long serialVersionUID = -2316554599671359643L;
};
final NumberTextField<Integer> quantity = new NumberTextField<Integer>(
"quantity", new PropertyModel<Integer>(item.getModel(),
"quantity")) {
private static final long serialVersionUID = -5753172372351592833L;
@Override
public void renderHead(IHeaderResponse response) {
String script = "$('#" + getMarkupId()
+ "').number( true, 0 );";
response.render(OnDomReadyHeaderItem.forScript(script));
}
};
quantity.setOutputMarkupId(true);
final TextField<String> unit = new TextField<String>("unit",
new PropertyModel<String>(item.getModel(), "product.unit")) {
private static final long serialVersionUID = -2316554599671359643L;
@SuppressWarnings("unchecked")
@Override
public <C> IConverter<C> getConverter(Class<C> type) {
return (IConverter<C>) new UnitConverter();
}
};
final NumberTextField<Integer> price = new NumberTextField<Integer>(
"price", new PropertyModel<Integer>(item.getModel(),
"unitPrice")) {
private static final long serialVersionUID = -8646496003644699535L;
};
unit.setOutputMarkupId(true);
price.setOutputMarkupId(true);
amount.setOutputMarkupId(true);
quantity.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1563937210317123609L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
onQuantityChange(item.getModelObject(), target, amount);
}
});
price.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = -8638379626220896934L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
onPriceChange(item.getModelObject(), target, amount);
}
});
codeSelect.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 7159818718453062684L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
onCodeChange(item, target, nameSelect, quantity, unit, price,
amount);
}
});
nameSelect.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = -7575744336298650067L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
onNameChange(item, target, codeSelect, quantity, unit, price,
amount);
}
});
final TextArea<String> apply = new TextArea<String>("apply",
new PropertyModel<String>(item.getModel(), "tekiyo"));
apply.add(new AbstractDefaultAjaxBehavior() {
private static final long serialVersionUID = 3598447798201761103L;
@Override
protected void respond(AjaxRequestTarget target) {
onKeyTeikyo(target);
}
@Override
public void renderHead(Component component, IHeaderResponse response) {
super.renderHead(component, response);
// response.render();
}
});
apply.add(StringValidator.maximumLength(40));
apply.add(new OnChangeAjaxBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
// target.add(apply);
}
});
item.add(checkbox);
item.add(no);
item.add(codeSelect);
item.add(nameSelect);
item.add(quantity);
item.add(price);
item.add(unit);
item.add(amount);
item.add(apply);
// item.add(new EstimateDetailValidator(item.getModelObject()));
}
}
关于 QuicketView:https://github.com/vineetsemwal/quickview
此外,您应该将 IValidator 分配给 FormComponent and/or IFormValidator 分配给 Form 组件。向项目添加验证器不会执行任何操作。
刚刚在 git 上推送了 master 中的更改,ReuseAllStrategy 现在不应该在重新渲染时显示陈旧数据,如果问题仍然存在或新更改破坏了其他一些东西;)在 [=14 中创建一个问题=]枢纽。 打算对您之前回答的问题发表评论,但意识到您应该发表评论或投票 :)
(抱歉回复晚了)