Reputation: 31
I'm trying to change the text on a button in wicket using AjaxLink but it is not working, any help please? here is my code;
<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); } };
Upvotes: 0
Views: 1691
Reputation: 31
using a div for the button label in the html file instead of a span works, and calling this method from the onclick setDefaultModel(); this method does not work in this sceanario - setDefaultModelModelObject()
Upvotes: 0
Reputation: 17533
You need to update the Label's model, not to add a new 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);
Here are my suggested changes:
Update: Here is how your code should look like:
<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);
Upvotes: 1