Re your first point: I'd say you need to register your own converter.
This will remove the need for a special component. Converters are not
the most beautiful part of wicket (yet), but it is not that hard to
accomplish.
in Application#init() :
applicationSettings.setConverterFactory(new MyConverterFactory());
in your own converter factory:
DateFormat dateFormat = new
SimpleDateFormat("dd-MM-yyyy");
Locale nl = new Locale("nl", "NL");
DateConverter dateConverter = new DateConverter();
dateConverter.setDateFormat(nl, dateFormat);
StringConverter stringConverter = new StringConverter();
DateToStringConverter dateToStringConverter = new
DateToStringConverter();
dateToStringConverter.setDateFormat(nl, dateFormat);
// voeg alle java.util.Date afgeleidingen toe,
aangezien onze
// grote Hibernate vriend van alles terug kan geven.
stringConverter.set(java.util.Date.class,
dateToStringConverter);
stringConverter.set(java.sql.Date.class,
dateToStringConverter);
stringConverter.set(java.sql.Timestamp.class,
dateToStringConverter);
// voeg alle java.util.Date afgeleidingen toe,
aangezien onze
// grote Hibernate vriend van alles terug kan geven.
Converter converter = new Converter(locale);
converter.set(java.sql.Timestamp.class, dateConverter);
converter.set(java.sql.Date.class, dateConverter);
converter.set(java.util.Date.class, dateConverter);
converter.set(String.class, stringConverter);
return converter;
Re your second point: you can create your own (form) validator that
performs your check (provides great reuse if you need it elsewhere).
This will hook into the population/validation mechanism provided by
wicket, so your bean won't be contaminated with invalid values from
the GUI.
An other option is to invoke: 'error("My horrifying error message");'
in your onsubmit handler, and just redisplay the page (i.e. don't set
the response page).
on success: setResponsePage(new MySuccessPage());
On 6/21/06, Stefan Arentz <[EMAIL PROTECTED]> wrote:
> I have two simple use cases that I can't figure out how to implement with
> Wicket.
>
> Example form. Pretty basic and works.
>
> public class CreateAdministratorPage extends WebPage
> {
> @SpringBean
> private CreateAdministratorFacade mCreateAdministratorFacade;
>
> public CreateAdministratorPage()
> {
> add(new FeedbackPanel("feedback"));
> add(new AdministratorForm("administratorForm", new
> Administrator()));
> }
>
> class AdministratorForm extends Form
> {
> public AdministratorForm(String name, Administrator administrator)
> {
> super(name, new
> CompoundPropertyModel(administrator));
> add(new RequiredTextField("name"));
> add(new
> RequiredTextField("emailAddress").add(EmailAddressPatternValidator.getInstance()));
> }
>
> @Override
> protected void onSubmit()
> {
> Administrator administrator = (Administrator) getModelObject();
>
> mCreateAdministratorFacade.createAdministrator(administrator);
> }
> }
> }
>
> 1. Checking a confirmationField.
>
> I want to add an emailConfirmation field to the form. But, I don't want to
> add this field to the Administrator object. What is common practice to
> implement this? Create a new AdministratorModel like this:
>
> public class AdministratorModel {
> public Administrator administrator;
> public String emailConfirmation;
> }
>
> together with:
>
> public AdministratorForm(String name, AdministratorModel
> administrator)
> {
> super(name, new
> CompoundPropertyModel(administrator));
> add(new RequiredTextField("administrator.name"));
> add(new
> RequiredTextField("administrator.emailAddress").add(EmailAddressPatternValidator.getInstance()));
> add(new
> RequiredTextField("emailAddressConfirmation").add(EmailAddressPatternValidator.getInstance
> ()));
> }
>
> Or is there an easier way?
>
> 2. Doing validation on submit.
>
> The code above works, but what I really need to do is something like this:
>
> protected void onSubmit()
> {
> Administrator administrator = (Administrator) getModelObject();
> result =
> mCreateAdministratorFacade.createAdministrator(administrator);
> if (result == SUCCESS) {
> REDIRECT TO A SUCCESS PAGE BASED ON THE EMAIL ADDRESS
> } else {
> SET A GLOBAL FORM ERROR, SHOW THE FORM AGAIN
> }
> }
>
> I read the Form documentation but it is not really clear how the Form
> workflow is setup and where I need to plugin.
>
> S.
>
>
>
>
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>
>
>
--
Download Wicket 1.2 now! Write Ajax applications without touching JavaScript!
-- http://wicketframework.org
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user