Re: Form Components With Built In Feedback
textfield.add(new FieldBorder()) doesn't work. -jim igor.vaynberg wrote: use IComponentBorder and then simply add it to each form component or subclass formcomponents and add it in the constructor, eg textfield.add(new fieldborder()); -igor public class FieldBorder implements IComponentBorder { public static final IComponentBorder INSTANCE = new FieldBorder(); public void renderAfter(Component component) { final Response out = component.getResponse(); ListFeedbackMessage errors = component.getSession().getFeedbackMessages().messages( new ErrorsFilter(component)); if (errors.size() 0) { out.write(ul class=\errors\); for (FeedbackMessage error : errors) { out.write(li); out.write(error.getMessage().toString()); out.write(/li); } out.write(/ul); } } public void renderBefore(Component component) { component.setOutputMarkupId(true); final Response out = component.getResponse(); final boolean required = isRequired(component); out.write(label for=\); out.write(component.getMarkupId()); out.write(\); if (required) { out.write(strongem*/em); } String label = null; if (component instanceof LabeledWebMarkupContainer) { IModel labelModel = ((LabeledWebMarkupContainer)component).getLabel(); if (labelModel != null) { label = labelModel.getObject().toString(); } } if (label == null) { label = component.getString(component.getId()); } if (!Strings.isEmpty(label)) { out.write(label); if (separator) { out.write(getSeparator()); } } if (required) { out.write(/strong); } out.write(/label); } protected String getSeparator() { return :; } private boolean isRequired(Component component) { if (component instanceof FormComponent) { return ((FormComponent)component).isRequired(); } return false; } private static class ErrorsFilter implements IFeedbackMessageFilter { private final Component target; public ErrorsFilter(Component target) { this.target = target; } public boolean accept(FeedbackMessage message) { if (message.isError() message.getReporter() != null) { if (target == message.getReporter()) { return true; } if (target instanceof MarkupContainer) { if (((MarkupContainer)target).contains(message.getReporter(), true)) { return true; } } } return false; } } } On Tue, Jan 13, 2009 at 12:20 PM, walnutmon justin.m.boy...@gmail.com wrote: All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p23544681.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr
Re: Form Components With Built In Feedback
textfield.setcomponentborder(new fieldborder()); IDEs are good at helping you... -igor On Thu, May 14, 2009 at 9:56 AM, jobiwankanobi jobr...@spinnphr.com wrote: textfield.add(new FieldBorder()) doesn't work. -jim igor.vaynberg wrote: use IComponentBorder and then simply add it to each form component or subclass formcomponents and add it in the constructor, eg textfield.add(new fieldborder()); -igor public class FieldBorder implements IComponentBorder { public static final IComponentBorder INSTANCE = new FieldBorder(); public void renderAfter(Component component) { final Response out = component.getResponse(); ListFeedbackMessage errors = component.getSession().getFeedbackMessages().messages( new ErrorsFilter(component)); if (errors.size() 0) { out.write(ul class=\errors\); for (FeedbackMessage error : errors) { out.write(li); out.write(error.getMessage().toString()); out.write(/li); } out.write(/ul); } } public void renderBefore(Component component) { component.setOutputMarkupId(true); final Response out = component.getResponse(); final boolean required = isRequired(component); out.write(label for=\); out.write(component.getMarkupId()); out.write(\); if (required) { out.write(strongem*/em); } String label = null; if (component instanceof LabeledWebMarkupContainer) { IModel labelModel = ((LabeledWebMarkupContainer)component).getLabel(); if (labelModel != null) { label = labelModel.getObject().toString(); } } if (label == null) { label = component.getString(component.getId()); } if (!Strings.isEmpty(label)) { out.write(label); if (separator) { out.write(getSeparator()); } } if (required) { out.write(/strong); } out.write(/label); } protected String getSeparator() { return :; } private boolean isRequired(Component component) { if (component instanceof FormComponent) { return ((FormComponent)component).isRequired(); } return false; } private static class ErrorsFilter implements IFeedbackMessageFilter { private final Component target; public ErrorsFilter(Component target) { this.target = target; } public boolean accept(FeedbackMessage message) { if (message.isError() message.getReporter() != null) { if (target == message.getReporter()) { return true; } if (target instanceof MarkupContainer) { if (((MarkupContainer)target).contains(message.getReporter(), true)) { return true; } } } return false; } } } On Tue, Jan 13, 2009 at 12:20 PM, walnutmon justin.m.boy...@gmail.com wrote: All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p23544681.html Sent from the Wicket - User mailing list archive
Re: Form Components With Built In Feedback
Why would you use IComponentBorder instead of IBehaviour? igor.vaynberg wrote: use IComponentBorder and then simply add it to each form component or subclass formcomponents and add it in the constructor, eg textfield.add(new fieldborder()); -igor public class FieldBorder implements IComponentBorder { public static final IComponentBorder INSTANCE = new FieldBorder(); public void renderAfter(Component component) { final Response out = component.getResponse(); ListFeedbackMessage errors = component.getSession().getFeedbackMessages().messages( new ErrorsFilter(component)); if (errors.size() 0) { out.write(ul class=\errors\); for (FeedbackMessage error : errors) { out.write(li); out.write(error.getMessage().toString()); out.write(/li); } out.write(/ul); } } public void renderBefore(Component component) { component.setOutputMarkupId(true); final Response out = component.getResponse(); final boolean required = isRequired(component); out.write(label for=\); out.write(component.getMarkupId()); out.write(\); if (required) { out.write(strongem*/em); } String label = null; if (component instanceof LabeledWebMarkupContainer) { IModel labelModel = ((LabeledWebMarkupContainer)component).getLabel(); if (labelModel != null) { label = labelModel.getObject().toString(); } } if (label == null) { label = component.getString(component.getId()); } if (!Strings.isEmpty(label)) { out.write(label); if (separator) { out.write(getSeparator()); } } if (required) { out.write(/strong); } out.write(/label); } protected String getSeparator() { return :; } private boolean isRequired(Component component) { if (component instanceof FormComponent) { return ((FormComponent)component).isRequired(); } return false; } private static class ErrorsFilter implements IFeedbackMessageFilter { private final Component target; public ErrorsFilter(Component target) { this.target = target; } public boolean accept(FeedbackMessage message) { if (message.isError() message.getReporter() != null) { if (target == message.getReporter()) { return true; } if (target instanceof MarkupContainer) { if (((MarkupContainer)target).contains(message.getReporter(), true)) { return true; } } } return false; } } } On Tue, Jan 13, 2009 at 12:20 PM, walnutmon justin.m.boy...@gmail.com wrote: All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p23549947.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr
Re: Form Components With Built In Feedback
why not? -igor On Thu, May 14, 2009 at 3:11 PM, John Patterson jdp2...@gmail.com wrote: Why would you use IComponentBorder instead of IBehaviour? igor.vaynberg wrote: use IComponentBorder and then simply add it to each form component or subclass formcomponents and add it in the constructor, eg textfield.add(new fieldborder()); -igor public class FieldBorder implements IComponentBorder { public static final IComponentBorder INSTANCE = new FieldBorder(); public void renderAfter(Component component) { final Response out = component.getResponse(); ListFeedbackMessage errors = component.getSession().getFeedbackMessages().messages( new ErrorsFilter(component)); if (errors.size() 0) { out.write(ul class=\errors\); for (FeedbackMessage error : errors) { out.write(li); out.write(error.getMessage().toString()); out.write(/li); } out.write(/ul); } } public void renderBefore(Component component) { component.setOutputMarkupId(true); final Response out = component.getResponse(); final boolean required = isRequired(component); out.write(label for=\); out.write(component.getMarkupId()); out.write(\); if (required) { out.write(strongem*/em); } String label = null; if (component instanceof LabeledWebMarkupContainer) { IModel labelModel = ((LabeledWebMarkupContainer)component).getLabel(); if (labelModel != null) { label = labelModel.getObject().toString(); } } if (label == null) { label = component.getString(component.getId()); } if (!Strings.isEmpty(label)) { out.write(label); if (separator) { out.write(getSeparator()); } } if (required) { out.write(/strong); } out.write(/label); } protected String getSeparator() { return :; } private boolean isRequired(Component component) { if (component instanceof FormComponent) { return ((FormComponent)component).isRequired(); } return false; } private static class ErrorsFilter implements IFeedbackMessageFilter { private final Component target; public ErrorsFilter(Component target) { this.target = target; } public boolean accept(FeedbackMessage message) { if (message.isError() message.getReporter() != null) { if (target == message.getReporter()) { return true; } if (target instanceof MarkupContainer) { if (((MarkupContainer)target).contains(message.getReporter(), true)) { return true; } } } return false; } } } On Tue, Jan 13, 2009 at 12:20 PM, walnutmon justin.m.boy...@gmail.com wrote: All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p23549947.html Sent from the Wicket - User mailing list archive at Nabble.com
Re: Form Components With Built In Feedback
Good point! I had never seen IComponentBorder before so was just poking around and saw that to me it seems to do the same thing as IBehaviour... but less. So I thought I am probably missing some key difference. igor.vaynberg wrote: why not? -igor -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p23550337.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Form Components With Built In Feedback
textfield.setcomponentborder(new fieldborder()); I didn't see FieldBorder in the javadocs. What is the full class name? Thanks! =David - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Form Components With Built In Feedback
Igor, I know this is old, but in a post this morning you reminded me-it got lost in the shuffle at work lately. When I tried to implement this, I realized that IComponentBorder doesn't really extend from anything that can be added to a component. It extends IClusterable, which extends Serializeable, so I didn't know how to link it to a component. Simply adding it to a form component doesn't work, I also looked at using behaviors but they have renderBefore, not beforeRender. Thanks! Justin igor.vaynberg wrote: use IComponentBorder and then simply add it to each form component or subclass formcomponents and add it in the constructor, eg textfield.add(new fieldborder()); -igor public class FieldBorder implements IComponentBorder { public static final IComponentBorder INSTANCE = new FieldBorder(); public void renderAfter(Component component) { final Response out = component.getResponse(); ListFeedbackMessage errors = component.getSession().getFeedbackMessages().messages( new ErrorsFilter(component)); if (errors.size() 0) { out.write(ul class=\errors\); for (FeedbackMessage error : errors) { out.write(li); out.write(error.getMessage().toString()); out.write(/li); } out.write(/ul); } } public void renderBefore(Component component) { component.setOutputMarkupId(true); final Response out = component.getResponse(); final boolean required = isRequired(component); out.write(label for=\); out.write(component.getMarkupId()); out.write(\); if (required) { out.write(strongem*/em); } String label = null; if (component instanceof LabeledWebMarkupContainer) { IModel labelModel = ((LabeledWebMarkupContainer)component).getLabel(); if (labelModel != null) { label = labelModel.getObject().toString(); } } if (label == null) { label = component.getString(component.getId()); } if (!Strings.isEmpty(label)) { out.write(label); if (separator) { out.write(getSeparator()); } } if (required) { out.write(/strong); } out.write(/label); } protected String getSeparator() { return :; } private boolean isRequired(Component component) { if (component instanceof FormComponent) { return ((FormComponent)component).isRequired(); } return false; } private static class ErrorsFilter implements IFeedbackMessageFilter { private final Component target; public ErrorsFilter(Component target) { this.target = target; } public boolean accept(FeedbackMessage message) { if (message.isError() message.getReporter() != null) { if (target == message.getReporter()) { return true; } if (target instanceof MarkupContainer) { if (((MarkupContainer)target).contains(message.getReporter(), true)) { return true; } } } return false; } } } On Tue, Jan 13, 2009 at 12:20 PM, walnutmon justin.m.boy...@gmail.com wrote: All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Form Components With Built In Feedback
All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Form Components With Built In Feedback
Hi! There are: * FormComponentFeedbackBorder * FormComponentFeedbackIndicator ... and you can also make your own, it is easy to react to the feedback message status of a component and just make your own effect. Have a look at the source code within the abovementioned... ** Martin 2009/1/13 walnutmon justin.m.boy...@gmail.com: All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Form Components With Built In Feedback
This leaves one thing out of the problem though. Because FeedbackIndicator is a panel, it still needs some HTML markup, and I am trying to avoid adding a dozens of feedback panels to the markup and java code. However, I'm also confident that there is some way to accomplish this. I was thinking, you could make a custom panel which always includes a feedback component. But that would require me to change all of my add(new TextField(...)); to a add(new FeedbackTextField()); and also have to change some of the corresponding markup to remove the references to input instead converting them all to elements. Thanks! Justin Martin Makundi wrote: Hi! There are: * FormComponentFeedbackBorder * FormComponentFeedbackIndicator ... and you can also make your own, it is easy to react to the feedback message status of a component and just make your own effect. Have a look at the source code within the abovementioned... ** Martin 2009/1/13 walnutmon justin.m.boy...@gmail.com: All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21444965.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Form Components With Built In Feedback
You can easily... here is a simple example, you can improvize from there: public class FeedbackStyler extends AttributeModifier { /** * @param formComponent * @return FormComponent? */ public static FormComponent? add(FormComponent? formComponent) { formComponent.add(new FeedbackStyler(formComponent)); return formComponent; } /** * @param formComponent */ private FeedbackStyler(FormComponent formComponent) { this(formComponent, null); } /** * @param formComponent * @param defaultStyle */ public FeedbackStyler(FormComponent formComponent, String defaultStyle) { super(WebPageConstants.STYLE, true, new FeedbackStyleModel(formComponent, defaultStyle)); } /** * @see org.apache.wicket.AttributeModifier#isEnabled(org.apache.wicket.Component) */ @Override public boolean isEnabled(Component component) { return !Utils.isEmpty((String) getReplaceModel().getObject()); } } public class FeedbackStyleModel extends AbstractReadOnlyModelString { private final FormComponent? formComponent; private String defaultStyle; private ComponentFeedbackMessageFilter componentFeedbackMessageFilter; /** * @param formComponent * @param defaultStyle */ public FeedbackStyleModel(FormComponent? formComponent, String defaultStyle) { this.formComponent = formComponent; this.defaultStyle = defaultStyle; } /** * @see org.apache.wicket.model.AbstractReadOnlyModel#getObject() */ @Override public String getObject() { boolean inError = 0 TakpSession.get().getFeedbackMessages().messages( getComponentFeedbackMessageFilter()).size(); if (inError) { return border: red solid 1px; + Utils.noNull(getDefaultStyle()); } return + Utils.noNull(getDefaultStyle()); } /** * @return IFeedbackMessageFilter */ protected IFeedbackMessageFilter getComponentFeedbackMessageFilter() { if (componentFeedbackMessageFilter == null) { componentFeedbackMessageFilter = new ComponentFeedbackMessageFilter( formComponent); } return componentFeedbackMessageFilter; } /** * @return the defaultStyle */ public String getDefaultStyle() { return defaultStyle; } /** * @param defaultStyle * the defaultStyle to set */ public void setDefaultStyle(String defaultStyle) { this.defaultStyle = defaultStyle; } } ** Martin 2009/1/13 walnutmon justin.m.boy...@gmail.com: This leaves one thing out of the problem though. Because FeedbackIndicator is a panel, it still needs some HTML markup, and I am trying to avoid adding a dozens of feedback panels to the markup and java code. However, I'm also confident that there is some way to accomplish this. I was thinking, you could make a custom panel which always includes a feedback component. But that would require me to change all of my add(new TextField(...)); to a add(new FeedbackTextField()); and also have to change some of the corresponding markup to remove the references to input instead converting them all to elements. Thanks! Justin Martin Makundi wrote: Hi! There are: * FormComponentFeedbackBorder * FormComponentFeedbackIndicator ... and you can also make your own, it is easy to react to the feedback message status of a component and just make your own effect. Have a look at the source code within the abovementioned... ** Martin 2009/1/13 walnutmon justin.m.boy...@gmail.com: All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21444965.html Sent from the Wicket - User mailing list archive at Nabble.com
Re: Form Components With Built In Feedback
use IComponentBorder and then simply add it to each form component or subclass formcomponents and add it in the constructor, eg textfield.add(new fieldborder()); -igor public class FieldBorder implements IComponentBorder { public static final IComponentBorder INSTANCE = new FieldBorder(); public void renderAfter(Component component) { final Response out = component.getResponse(); ListFeedbackMessage errors = component.getSession().getFeedbackMessages().messages( new ErrorsFilter(component)); if (errors.size() 0) { out.write(ul class=\errors\); for (FeedbackMessage error : errors) { out.write(li); out.write(error.getMessage().toString()); out.write(/li); } out.write(/ul); } } public void renderBefore(Component component) { component.setOutputMarkupId(true); final Response out = component.getResponse(); final boolean required = isRequired(component); out.write(label for=\); out.write(component.getMarkupId()); out.write(\); if (required) { out.write(strongem*/em); } String label = null; if (component instanceof LabeledWebMarkupContainer) { IModel labelModel = ((LabeledWebMarkupContainer)component).getLabel(); if (labelModel != null) { label = labelModel.getObject().toString(); } } if (label == null) { label = component.getString(component.getId()); } if (!Strings.isEmpty(label)) { out.write(label); if (separator) { out.write(getSeparator()); } } if (required) { out.write(/strong); } out.write(/label); } protected String getSeparator() { return :; } private boolean isRequired(Component component) { if (component instanceof FormComponent) { return ((FormComponent)component).isRequired(); } return false; } private static class ErrorsFilter implements IFeedbackMessageFilter { private final Component target; public ErrorsFilter(Component target) { this.target = target; } public boolean accept(FeedbackMessage message) { if (message.isError() message.getReporter() != null) { if (target == message.getReporter()) { return true; } if (target instanceof MarkupContainer) { if (((MarkupContainer)target).contains(message.getReporter(), true)) { return true; } } } return false; } } } On Tue, Jan 13, 2009 at 12:20 PM, walnutmon justin.m.boy...@gmail.com wrote: All, I have a page with many form components, nearly all of them have some kind of validation associated with them. I have a feedback panel at the top, I'd like to move feedback next to each component. I have thought of some ways to do this without changing a ton of code, however none really work in the end because I would still need to add some kind of HTML in order to display messages. Also, nearly everything like this that I have developed in wicket is usually accompanied by the discovery that wicket already has the functionality I'm looking for out of the box. Searching has given me surprisingly little with regard to this topic though. Can someone point me in the right direction? -- View this message in context: http://www.nabble.com/Form-Components-With-Built-In-Feedback-tp21443674p21443674.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org