Samade
Samade

Reputation: 31

How to disable AjaxLink button in wicket?

I'm trying to disable an AjaxLink button in wicket inside the
public void onClick(AjaxRequestTarget target) method; I tried calling the setEnabled(false) directly but didn't work. some of the suggestions I saw online says call the isEnabled() or onConfigure() methods; but these cannot be implemented inside the onclick method; any help please?

            {
                buttonlabel.setDefaultModel(Model.of("Creating EWL"));
                target.add(buttonlabel);
                buttonlabel.setOutputMarkupPlaceholderTag(true);

                boolean isWorkItemCreated = NewRecruitEWLUtil.createNewRecruitWorkItem(appInfo);

                if (isWorkItemCreated)
                {
                    buttonlabel.setDefaultModel(Model.of("EWL Created"));
                    target.add(buttonlabel);
                    buttonlabel.setOutputMarkupPlaceholderTag(true);
                    setEnabled(false);
                    target.add(this);
                    System.out.println("setEnabled ..." + isEnabled());
                }

            }

Upvotes: 0

Views: 368

Answers (1)

martin-g
martin-g

Reputation: 17513

setEnabled(false) is the correct way! You also need to add the AjaxLink to the AjaxRequestTarget so it is repaint at the browser:

AjaxLink link = new AjaxLink("myLink") {
    @Override
    public void onClick(AjaxRequestTarget target) {
       setEnabled(false);
       target.add(this);
    }
};
add(link);
link.setOutputMarkupId(true);

Upvotes: 1

Related Questions