我试图使用AjaxLink改变wicket中按钮上的文字,但它无法正常工作,请提供帮助,这是我的代码;WebMarkupContainer xyzContainer = new WebMarkupContainer。
<form name="depForm" wicket:id="depSummaryForm" action="">
<div class="uw_summary"> <div class="buttonContainer">
<span class="button_v2" wicket:id="newRecruitContainer">
<button class="internal_button" wicket:id="newRecruitEWLButton"
type="button"> Create New Recruit EWL </button> </span>
final WebMarkupContainer newRecruitContainer = new
WebMarkupContainer("newRecruitContainer")
{
Label buttonlabel = new Label("newRecruitEWLButton", Model.of(" "));
buttonlabel.setOutputMarkupPlaceholderTag(true);
AjaxLink newRecruitEWLButton = new AjaxLink("newRecruitEWLButton") {
@Override public void onClick(AjaxRequestTarget target) {
buttonlabel.setDefaultModelObject(Model.of("Creating EWL"));
target.add(buttonlabel); boolean isWorkItemCreated =
NewRecruitEWLUtil.createNewRecruitWorkItem(appInfo); } };
你需要更新Label的模型,而不是添加一个新的Label。
WebMarkupContainer xyzContainer = new WebMarkupContainer("xyzContainer") {
@Override
public void onConfigure() { // [1]
super.onConfigure();
boolean isVisible = some code goes here
setVisible(isVisible);
}
};
final Label buttonlabel = new Label("clickMe", ""); // [2]
buttonlabel.setOutputMarkupId(true); // [3]
AjaxLink xyzButton = new AjaxLink("xyzButton") {
@Override
public void onClick(AjaxRequestTarget target) {
buttonlabel.setModelObject("Clicked")); // [4]
target.add(buttonlabel);
}
};
xyzContainer.add(xyzButton);
Form.add(xyzContainer);
以下是我建议的修改。
更新:你的代码应该是这样的。
<form name="depForm" wicket:id="depSummaryForm">
<div class="uw_summary">
<div class="buttonContainer">
<span class="button_v2" wicket:id="newRecruitContainer">
<button class="internal_button" wicket:id="newRecruitEWLButton"
type="button">
<span wicket:id="label">Create New Recruit EWL</span></button>
</span>
</div>
</div>
</form>
final WebMarkupContainer newRecruitContainer = new
WebMarkupContainer("newRecruitContainer");
Label buttonlabel = new Label("label", Model.of(" "));
buttonlabel.setOutputMarkupPlaceholderTag(true);
AjaxLink newRecruitEWLButton = new AjaxLink("newRecruitEWLButton")
{
@Override public void onClick(AjaxRequestTarget target) {
buttonlabel.setDefaultModelObject(Model.of("Creating EWL"));
target.add(buttonlabel);
boolean isWorkItemCreated =
NewRecruitEWLUtil.createNewRecruitWorkItem(appInfo); }
};
newRecruitContainer.add(newRecruitEWLButton);
newRecruitEWLButton.add(buttonlabel);
在html文件中使用div而不是span来做按钮标签,在onclick setDefaultModel()中调用这个方法;这个方法在这个sceanario中不起作用--setDefaultModelModelObject()