You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Steve Lowery <sl...@gatessolutions.com> on 2009/07/17 16:35:28 UTC

override isEnabledInHierarchy?

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><a
wicket:id="editLink">[edit]</a></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


Re: override isEnabledInHierarchy?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Well..

public class MyCentrallyEnabledPage/Panel xxx {
private boolean centralEnable;

CentrallyEnabledTextField extends TextField {
 ....
  isEnabled() {
     return centralEnable;
  }
}

I think you get the idea. It can be an inner class or any kind of
class (just needs the necessary built-in handle).

**
Martin

2009/7/19 slowery23 <sl...@gatessolutions.com>:
>
> can u give an code example of what your "centrallyenableddisabledcomponent"
> looks like?
>
>
> MartinM wrote:
>>
>>> That certainly will work.  But if I have a form and I want to disable all
>>> of
>>> the elements in the form except for the "Edit Form" link, it is, IMO,
>>> much
>>> simpler to disable the form and override the one link so it is enabled,
>>> rather than disabling many form components.
>>
>> You can just make your own "centrallyenableddisabledcomponent". That's
>> what we did and works great.
>>
>> **
>> Martin
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/override-isEnabledInHierarchy--tp24535687p24559838.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: override isEnabledInHierarchy?

Posted by slowery23 <sl...@gatessolutions.com>.
can u give an code example of what your "centrallyenableddisabledcomponent"
looks like?


MartinM wrote:
> 
>> That certainly will work.  But if I have a form and I want to disable all
>> of
>> the elements in the form except for the "Edit Form" link, it is, IMO,
>> much
>> simpler to disable the form and override the one link so it is enabled,
>> rather than disabling many form components.
> 
> You can just make your own "centrallyenableddisabledcomponent". That's
> what we did and works great.
> 
> **
> Martin
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

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


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


Re: override isEnabledInHierarchy?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> That certainly will work.  But if I have a form and I want to disable all of
> the elements in the form except for the "Edit Form" link, it is, IMO, much
> simpler to disable the form and override the one link so it is enabled,
> rather than disabling many form components.

You can just make your own "centrallyenableddisabledcomponent". That's
what we did and works great.

**
Martin

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


Re: override isEnabledInHierarchy?

Posted by slowery23 <sl...@gatessolutions.com>.
That certainly will work.  But if I have a form and I want to disable all of
the elements in the form except for the "Edit Form" link, it is, IMO, much
simpler to disable the form and override the one link so it is enabled,
rather than disabling many form components.  We have one use case where we
probably have 80 form components on the page (not great web design, i know,
but that's what the users wanted).  The onClick() method of the Edit Form
link would be 80 lines long enabling the components instead of 1 to enable
the form.


MartinM wrote:
> 
> Don't disable the form. Disable only the components you want to disable.
> 
> **
> Martin
> 
> 2009/7/19 slowery23 <sl...@gatessolutions.com>:
>>
>> 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.
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

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


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


Re: override isEnabledInHierarchy?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
Don't disable the form. Disable only the components you want to disable.

**
Martin

2009/7/19 slowery23 <sl...@gatessolutions.com>:
>
> 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.
>

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


Re: override isEnabledInHierarchy?

Posted by slowery23 <sl...@gatessolutions.com>.
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 <sl...@gatessolutions.com>:
>> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 
> 

-- 
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: override isEnabledInHierarchy?

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
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 <sl...@gatessolutions.com>:
> 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><a
> wicket:id="editLink">[edit]</a></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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org