Actually, that's what I initially tried, but it didn't work.  If you use the
simple example below, you'll see that.  None of the components with
isEnabled() overridden to return true are enabled.  I am using wicket
1.4-rc4.  In looking at the source code, it looks like if I were able to
override isEnabledInHierarchy to return true it would work.  

Java code:
package test.web.page;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

@SuppressWarnings( {
                "unused", "serial"
})
public class DemoPage extends WebPage {

        private String firstName = "Steve";
        private String lastName = "Lowery";

        public DemoPage(PageParameters parameters) {
                super(parameters);

                Form<DemoPage> form = new Form<DemoPage>("form", new
CompoundPropertyModel<DemoPage>(this));
                add(form.setEnabled(false));

                form.add(new TextField<String>("firstName"));
                form.add(new TextField<String>("lastName") {

                        @Override
                        public boolean isEnabled() {
                                return true;
                        }
                });

                form.add(new Link("regular") {

                        @Override
                        public void onClick() {
                                System.out.println("do something");
                        }
                });

                form.add(new Link("enabled") {

                        @Override
                        public void onClick() {
                                System.out.println("i want this link always 
enabled, regardless of what
its hierarch looks like");
                        }

                        @Override
                        public boolean isEnabled() {
                                return true;
                        }
                });
        }
}

Html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd";>

<html xmlns:wicket="http://wicket.apache.org/";>

<head>
        <title>Demo</title>
</head>

<body>
        <form wicket:id="form">
                <table>
                        <tbody>
                                <tr>
                                        <td>[first name]</td>
                                        <td><input type="text" 
wicket:id="firstName"/></td>
                                </tr>
                                <tr>
                                        <td>[last name]</td>
                                        <td><input type="text" 
wicket:id="lastName"/></td>
                                </tr>
                                <tr>
                                        <td>&nbsp;</td>
                                        <td> [reg link] </td>
                                </tr>
                                <tr>
                                        <td>&nbsp;</td>
                                        <td> [enabled link] </td>
                                </tr>
                        </tbody>
                </table>
        </form>
</body>
</html>

MartinM wrote:
> 
> Yes, you could do it another way. Make each component that you want to
> enable/disable like this:
> form.add(new xxxFormComponent("id") {
>   @Override
>   isEnabled() {
>      return your logic here;
>   }
> });
> 
> 2009/7/17 Steve Lowery <[email protected]>:
>> I would like to build a simple form whose markup looks like the
>> following:
>>
>>
>>
>> <wicket:panel>
>>
>>       <form wicket:id="form">
>>
>>              <table>
>>
>>                     <thead>
>>
>>                           <tr>
>>
>>                                  <th>[Label]</th>
>>
>>                                  <th>  wicket:id="editLink">[edit] </th>
>>
>>                           </tr>
>>
>>                     </thead>
>>
>>                     <tbody>
>>
>>                           <tr>
>>
>>                                  <td>[attr1]</td>
>>
>>                                  <td><input type="text"
>> wicket:id="attr1"/></td>
>>
>>                           </tr>
>>
>>                           <tr>
>>
>>                                  <td>[attr2]</td>
>>
>>                                  <td><input type="text"
>> wicket:id="longitude"/></td>
>>
>>                           </tr>
>>
>>                     </tbody>
>>
>>                     <tfoot>
>>
>>                           <tr>
>>
>>                                  <td colspan="2">
>>
>>                                         <button
>> wicket:id="submit">[submit]</button>
>>
>>                                         <button
>> wicket:id="cancel">[cancel]</button>
>>
>>                                  </td>
>>
>>                           </tr>
>>
>>                     </tfoot>
>>
>>              </table>
>>
>>       </form>
>>
>> </wicket:panel>
>>
>>
>>
>> I call setEnabled(false) on the Form when it is constructed which makes
>> its FormComponents disabled making a "read only" version of the form.
>> I'd then like the editLink.onClick() to enable the form, which will
>> enable it's components.  However, since the editLink is a child of the
>> Form which is initially disabled, that link is disabled.  I am looking
>> for a way to not have the link be disabled eventhough the form it is in
>> is disabled.  My thought was for that link, I could override
>> isEnabledInHierarchy() to just negate the value returned by super (if
>> the form is disabled the link is enabled and vice versa), but that
>> method is final, so no can do.
>>
>>
>>
>> Is anyone aware of another way I could go about doing this?  I know I
>> could create a wicket component on say the tbody element and have it be
>> disabled, but then the link would have to be passed which element(s) it
>> needs to enable when clicked and I was hoping to just be able to use the
>> hierarchy so I can make the EditLink a reusable component since this is
>> a very common use case for us (having read only forms that become
>> editable with a click).
>>
>>
>>
>> Thanks in advance!
>>
>> Steve
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/override-isEnabledInHierarchy--tp24535687p24557612.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to