Interesting approach. I don't think we'll support this out of the box, as
it is very basic, and your approach is very easy to implement by other
users. If you don't mind, I've created a wiki page with your description
for your usecase.
I think the current solution of Wicket is pretty good for the general case,
but could be improved by supplying default messages in the Wicket package,
so you don't have to create them yourself all the time. I believe there is already
an effort under way for this.
Martijn
On 10/15/05, Ralf Ebert <[EMAIL PROTECTED]> wrote:
Hi,
I just changed some of my forms to show form validation results
without messages (I was fed of writing these property files). I just
want form fields with validation errors getting a special css class
(for eye catching formatting) and a general message like "check the
marked fields". I got that working in a general way, just thought I
should tell you about this use case and how I got that working
because I think it's a quite common technique and Wicket could
support it out of the box...
I think the fact that the Validators know about messages currently is
not the greatest approach because validation doesn't depend on
messages in general. Maybe validation and reacting on validation
errors could be separated a bit more.
=== Ok, at first I got rid of the need to supply a message for each
form field:
getSettings().addStringResourceLoader(new
IStringResourceLoader() {
public String loadStringResource(Component component,
String key, Locale locale, String style) {
if (key.endsWith("Validator"))
return "Please enter a valid value for
"+component.getId()+"!";
return null;
}
});
=== Second thing: A form class that adds a AttributeModifier to all
form components:
public class HighlightForm extends Form {
private final static AttributeModifier
highlightAttributeModifier = new AttributeModifier("class", true, new
AbstractReadOnlyModel() {
public Object getObject(Component component) {
if (component.hasErrorMessage())
return "error";
return null;
}
});
@Override
protected void onBeginRequest() {
visitFormComponents(new FormComponent.IVisitor() {
public void formComponent(FormComponent formComponent) {
formComponent.add(highlightAttributeModifier);
}
});
}
public HighlightForm(String id, IModel model) {
super(id, model);
}
public HighlightForm(String id) {
super(id);
}
}
=== Third thing, a feedback markup container that is shown only when
there was a validation error (message can be specified in the markup
this way)
public class SimpleFeedbackPanel extends WebMarkupContainer
{
/**
* @see wicket.Component#Component(String)
*/
public SimpleFeedbackPanel(final String id)
{
super(id);
setModel(new FeedbackMessagesModel());
}
@Override
public boolean isVisible() {
return !((List) getModelObject()).isEmpty();
}
}
-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop
