efficiency is the least of our worries here. what's more, the search for feedback interfaces on a form validate (which doesn't happen that often) is already in place in order to support the existing extension mechanism. while your suggested change would fix your particular problem, wicket needs to take a more general view. it should be possible to implement absolutely any kind of feedback mechanism for forms. not just label-oriented feedback. i think we should stick with what we've got since it's completely general and enhance it only if we have to in order
to implement a feedback label component. make sense?
i agree that you shouldn't have to cast the IFeedback to a Component. in the past, this was not necessary... i no longer understand the code here though... what is this refactor, eelco? and what is a "collectingComponent" ?? in the past, any component could implement IFeedback and act as a "sink" for feedback information:
public interface IFeedback { /*** Called to add feedback messages from a component. If the component is a
* container, messages will be added for all children of the container. * * @param component * The component with associated feedback messages * @param recurse* True if feedback messages should be added from children of the
* given component */ public void addFeedbackMessages(Component component, boolean recurse); }this is a very powerful way to wire things up and i don't understand why this was changed.
Igor Vaynberg wrote:
I can kind of see what you are saying. The abstract validator would have to search the page and find the Ifeedback for the formcomponent in error. But what if you have two ifeedbacks for a component - the feedback panel and the label? The search is also inefficient for something simple like this, I don't think a link in a formcomponent to a labelcomponent is that big a deal. In abstract validator you would also have to cast Ifeedback to a Component in order to get the model, this isnt very safe, it would be nice to have Icomponent and have Ifeedback extend Icomponent. Igor-----Original Message-----From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jonathan LockeSent: Friday, July 29, 2005 10:03 PM To: wicket-user@lists.sourceforge.net Subject: Re: [Wicket-user] FieldLabel componentwell, i don't know what's happened to the feedback interface stuff recently, but it was originally designed to be general enough to support what you're trying to do. seems like what you're writing is more or less a FormComponentFeedbackLabel. and the link is simply implementing IFeedback (or it used to be... i'm not sure what's changed... it looks unfamiliar now). the form code then finds the associated feedback elements for each form component.Igor Vaynberg wrote:I've seen the error border, it doesn't do what I want - in our app a red asterisk indicates a required field and field labelswith errors turn red.What I am looking for is a way to link the label to thecomponent notthe other way around. My primary interest was the validatorstuff, theOf Jonathandecoration of the label was a bonus. -Igor-----Original Message----- From: [EMAIL PROTECTED][mailto:[EMAIL PROTECTED] On Behalfasterisk, seeLocke Sent: Friday, July 29, 2005 8:14 PM To: wicket-user@lists.sourceforge.net Subject: Re: [Wicket-user] FieldLabel componentif you just want to show an error indicator like a redcontents onFormComponentFeedbackBorder.i personally don't like the idea of changing field labelwicket.model.IModel; importusers. so instead, i've emphasized FeedbackPanel and IFeedback.however, you should be able to implement what you're talking about though by implementing IFeedback on a subclass of Label.Igor Vaynberg wrote:Hi Guys, Ive been working on forms a lot lately, and what ive beenmissing fromtapestry is a fieldlabel component. Basically a fieldlabelis a labelthat is linked to a form component. This allows to do cool things like: 1) FieldLabel can change its apperance based on the form componentTextField tf=new RequiredTextField(...) FieldLabel lb=new FieldLabel("label1","First Name", tf) {public void initialize() { add(new AttributeModifier("style", true, new Model("color:red;")) { public boolean isEnabled() { return !getFieldComponent().isValid(); } }); } }; This will create a field label that will turn red when thelinked formcomponent has an error. Another good use is to prepand an asterisk to thefieldlabel's label ifthe linked form component has a requiredvalidator added. 2) FieldLabel's label can participate in validator messages With this patch it is possible to create generic errormessages of form :"'${label}' is required" or "'${label}' contains an invalidemail address"I am looking for feedback and ideas on how to make thisbetter before Isubmit this as a patch. Thank you! Igor ------------------------------------------------------------------------ Index: wicket/markup/html/form/FormComponent.java ===================================================================RCS file: /cvsroot/wicket/wicket/src/java/wicket/markup/html/form/FormComponent.java,v retrieving revision 1.43 diff -u -r1.43 FormComponent.java--- wicket/markup/html/form/FormComponent.java 28 Jul2005 11:56:51 -0000 1.43+++ wicket/markup/html/form/FormComponent.java 30 Jul2005 02:32:19 -0000@@ -30,6 +30,7 @@ import wicket.model.IModel; import wicket.util.lang.Classes; import wicket.util.string.StringList; +import wicket.version.undo.Change; /*** An html form component knows how to validate itself. Validators that @@ -71,6 +72,9 @@/** The validator or validator list for this component. */ private IValidator validator = IValidator.NULL; + /** The field label for this component */ + private FieldLabel fieldLabel; + /** * Typesafe interface to code that is called whenvisiting a form component* @@ -575,4 +579,24 @@ { validator.validate(this); } + + protected FormComponent setFieldLabel(FieldLabel label) { + if (fieldLabel!=null) { + + addStateChange(new Change() { + private final FieldLabel +oldFieldLabel=FormComponent.this.fieldLabel; + + public void undo() + { +FormComponent.this.fieldLabel=oldFieldLabel;+ } + }); + } + this.fieldLabel=label; + return this; + } + + public FieldLabel getFieldLabel() { + return fieldLabel; + } } \ No newline at end of file Index: wicket/markup/html/form/validation/AbstractValidator.java ===================================================================RCS file: /cvsroot/wicket/wicket/src/java/wicket/markup/html/form/validation/AbstractValidator.java,v retrieving revision 1.31 diff -u -r1.31 AbstractValidator.java ---wicket/markup/html/form/validation/AbstractValidator.java 21 Jul 2005 10:46:36 -0000 1.31+++wicket/markup/html/form/validation/AbstractValidator.java 30 Jul 2005 02:32:19 -0000@@ -21,6 +21,7 @@ import java.util.Map; import wicket.Localizer; +import wicket.markup.html.form.FieldLabel; import wicket.markup.html.form.FormComponent; import wicket.model.IModel; import wicket.model.Model; @@ -139,6 +140,21 @@ final Map resourceModel = new HashMap(4); resourceModel.put("input", formComponent.getInput()); resourceModel.put("name", formComponent.getId()); + + // try to retrieve the label from field label,default to empty string+ String labelValue = ""; + FieldLabel label = formComponent.getFieldLabel(); + if (label != null) + { + Object modelObject = label.getModelObject(); + if (modelObject != null) + { + labelValue = modelObject.toString(); + } + } + resourceModel.put("label", labelValue); + + return resourceModel; } } Index: wicket/markup/html/form/FieldLabel.java =================================================================== RCS file: wicket/markup/html/form/FieldLabel.java diff -N wicket/markup/html/form/FieldLabel.java --- /dev/null 1 Jan 1970 00:00:00 -0000+++ wicket/markup/html/form/FieldLabel.java 1 Jan 197000:00:00 -0000@@ -0,0 +1,55 @@ +package wicket.markup.html.form; + +import wicket.AttributeModifier; +import wicket.Component; +import wicket.markup.html.WebMarkupContainer;+import wicket.markup.html.basic.Label; import +wicket.markup.html.panel.Panel; importStrategies+wicket.model.Model; import wicket.model.PropertyModel; + +public class FieldLabel extends Label { + protected FormComponent fc; + + public FieldLabel(String id, FormComponent formComponent) + { + super(id); + internalInitialize(formComponent); + } + + public FieldLabel(String id, String string,FormComponent formComponent)+ { + super(id, string); + internalInitialize(formComponent); + } + + public FieldLabel(String id, IModel model,FormComponent formComponent)+ { + super(id, model); + internalInitialize(formComponent); + } + + private void internalInitialize(FormComponent formComponent) + { + if (fc==null) throw newIllegalArgumentException("formComponent cannot be null");+ this.fc=fc; + + fc.setFieldLabel(this); + setRenderBodyOnly(true); + + initialize(); + } + + public final FormComponent getFormComponent() { + return fc; + } + + public void initialize() { + + } + + + +}-------------------------------------------------------SF.Net email is sponsored by: Discover Easy Linux MigrationStrategiesfrom IBM. Find simple to follow Roadmaps, straightforward articles,informative Webcasts and more! Get everything you need to get up to speed, fast.http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user-------------------------------------------------------SF.Net email is sponsored by: Discover Easy Linux Migrationfrom IBM. Find simple to follow Roadmaps, straightforward articles,informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click_______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user-------------------------------------------------------SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click_______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user
------------------------------------------------------- SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click _______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user