Sure, just create it (including the onClick which might be invalid), but afterwards set the setEnabled() as needed. As long as the link is disabled, it can never be clicked thus the onClick() will never be executed anyway, so it's irrelevant if the requestFormModel is valid or not... I dont think you want the setEnabled(false) inside the onClick - do you? That would deactivate the link after the first click which doesn't make that much sense?

Matt

Charles Moulliard wrote:
Hi,

I would like to know if there is a better way to code this case : What
I would like to do is to enable/disable a link depending on a
condition. If the condition is true, than we create the link otherwise
we disable it. In both case, a label must be defined for the Link.

I mean, is it possible to avoid to double the creation of the link =
new Link() ....

Here is my code

1) HTML

           <a href="#" wicket:id="linkRequest"><span
wicket:id="linkRequestTxt"/></a>


2) JAVA

                // Set link for requestId
                Link link;

                if (audit.getRequest() != null) {

                    final RequestFormModel requestFormModel = new
RequestFormModel();
                    requestFormModel.setRequestId( (int)
audit.getRequest().getId() );

                    link = new Link("linkRequest") {

                        @Override
                        public void onClick() {
                            setResponsePage(new RequestPage(requestFormModel));
                        }

                    };

                    link.add(new
Label("linkRequestTxt",String.valueOf(audit.getRequest().getId())));
                    item.add(link);

                } else {
                    link = new Link("linkRequest") {

                        @Override
                        public void onClick() {
                            this.setEnabled(false);
                        }

                    };
                    Label label = new Label("linkRequestTxt","");
                    link.add(label);
                    item.add(link);


Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer

*****************************
blog : http://cmoulliard.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



--
matthias.kel...@ergon.ch  +41 44 268 83 98
Ergon Informatik AG, Kleinstrasse 15, CH-8008 Zürich
http://www.ergon.ch
______________________________________________________________
e r g o n    smart people - smart software


Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to