开发者

Change className for a component when a button is disabled using wicket?

For example:

<span class="button4">
   <button wicket:id="saveButton" type="submit">
     <wicket:message key="modalArchiveAccount.button.save" />
   </button>
</span> 

From java code I set this button to be enabled or disabled, the problem is tha开发者_如何转开发t I don't know how to change the span className when button is disabled.


Wrap a WebMarkupContainer around your button

add(new WebMarkupContainer("spanId") {
                    {
                        add(new Button<String>("saveButton")){
                        [... button logic...]
                        };
                    }
                });

<span wicket:id="spanId">
   <button wicket:id="saveButton" type="submit">
     <wicket:message key="modalArchiveAccount.button.save" />
   </button>
</span> 

then add a new AttributeModifier("class",...) or AttributeAppender("class",...) to the WebMarkupContainer that uses the same logic as you use to disable the button.


var jSpan = $('#saveButton').parent();
jSpan.removeClass( 'button4' );
jSpan.addlass( someclass );


Here is the example code:

       final Button  button=new Button("buttn") {
            public void onSubmit() {
                System.out.println("change....");
                setEnabled(false);
            };
        };
        button.add(new AttributeModifier("class", true, new Model<Serializable>() {
            @Override
            public Serializable getObject() {               
                if (button.isEnabled())
                    return "your_enabled_class";
                else return "your_disabled_class";
            }
        }));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜