On 9/13/05, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
Usually, you want the disable attribute to not show up at when the tag
is /not/ disabled. You can do this by not putting the attribute in
your markup (<input type="text" wicket:id="foo" value="bar" />),
provide the second AttributeModifier argument 'true' (so attributes
will be added when they do not exist yet), and - important - let your
replacement model return null when the component is not enabled. If
the replacement model returns null, the attribute modifier will do
nothing, which is what you want in this case.
Eelco
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user
Wow, I tried this approach, and it makes sense:
class User {
public String name ;
}
// An AccountForm for both create and edit:
public AccountForm(String id, User user) {
super(id, new CompoundPropertyModel(user));
TextField nField = new TextField("name");
nField.add(new AttributeModifier("disabled", true, new Model(user.getName())));
nField.add(RequiredValidator.getInstance()) ;
}
While in creating, user.getName() return null, so TextField("name") is not disable
While in editing, user.getName() return, say, "foo", the field will be disabled with
a attribute disabled="foo" (browser disable the field no matter what value is).
Although this works magically, but it is really cleaner way to guard user input
for various conditions, great !!
OK... now I have another question here. When in editing mode, the field is populated with "foo" and disabled. After the user submit the form, I found that TextField("name") get null value from request parameter and does not pass
the validator. And finally the TextField("name") update the model with null value.
In my opinion, a disabled TextField should not get request parameter and should
not update the model. Maybe it should bypass validation too...
Any idea ?
--
Ingram Chen
Java [EMAIL PROTECTED]
Institue of BioMedical Sciences Academia Sinica Taiwan
blog: http://www.javaworld.com.tw/roller/page/ingramchen
