完全に正常に動作するこれら 2 つの DropDownChoice (DDC) オブジェクトがあります。最初の DDC から 1 つの要素が選択されると、2 番目のリストが関連する選択肢で更新されます。前者は strumListDDC で、後者は controlListDDC です。
controlListDDC.setOutputMarkupId(true);
controlListDDC.setChoiceRenderer(new ChoiceRenderer<>("name"));
controlListDDC.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
QCControl qcc = controlListDDC.getModelObject();
lotList = QCLot.getLotsForCtrl(qcc.getId());
if (!lotList.isEmpty()) {
target.add(lotListDDC);
}
}
});
searchForm.addOrReplace(new Label("strumListLabel", "Strumento:"));
searchForm.addOrReplace(strumListDDC = new DropDownChoice<>("strumList", InstalledStrum.loadAllStrum(false)));
strumListDDC.setDefaultModel(new Model<>());
strumListDDC.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
InstalledStrum is = strumListDDC.getModelObject();
controlList = QCControl.loadQCControlPerStrumType(is.getStrumType());
lotList = new ArrayList<>();
if (!controlList.isEmpty()) {
target.add(controlListDDC);
target.add(lotListDDC);
}
}
});
便宜上、すべての HTML ページの派生元であるページ テンプレートに、この小さな Javascript を追加しました。
$(function filtersScroll() {
var $filters = $(".viewANfilters");
detailsPos = $filters.position().top;
$(window).on("scroll", function () {
if ($(window).scrollTop() > detailsPos)
$filters.css("position", "fixed").css("top", 0);
else
$filters.css("position", "fixed").css("top", detailsPos -$(window).scrollTop());
});
});
Wicket を使用して JavaScript を追加します (ただし、コードを HTML に直接挿入しても問題は解決しません。完全を期すために投稿するだけです)。
response.render(JavaScriptContentHeaderItem.forScript(Costants.JS_FILTERS_SCROLL, "filters_scroll"));
JavaScript を追加すると、最初の DDC の onUpdate 関数が呼び出されません (デバッガーでチェック)。JavaScriptを削除するとすぐに、自動更新の動作が再び正常に機能し始めます。この JavaScript がページの基本であるというわけではありません。これがなくても続行できますが、本格的な JavaScript を追加する必要があるときに、同じことが再び起こるのではないかと心配しています。
Since I'm pretty new at javascript, can anybody give me a hint on what's stopping the AjaxFormComponentUpdatingBehavior from working? Can it be some sort of conflict between different script tags? There are others in the final page, added by Wicket itself, but since they have always been more than one I didn't think a new script would cause any trouble...