RE: Conditional validation without overriding isRequired

2012-06-06 Thread Schlärmann , Bob
Thanks for all the comments.

I'm implementing the conditional validation using a custom form processing 
method as suggested by Andrea. 

It's implemented as a form and behavior subclass. The overridden Form#process() 
first visits all form components and executes a special method on the behavior. 
The behavior then calls validate() on the source field and sets the required 
flag of the target component based on the converted input value.

The call to validate() is needed in order to have the converted input value set.

Best regards,

Bob

> You have to use the input or converted input of the field. See
> 
> https://cwiki.apache.org/WICKET/conditional-validation.html
> 
> for inspirations.
> 
> Sven
> 
> "Schlärmann, Bob"  schrieb:
> 
> >Thanks for your reply,
> >
> >> Argh, confused setVisible() with setRequired, my bad ;-)
> >> But nevertheless: call setRequiered(condition) in onConfigure().
> >
> >I've tried this but if I am correct isRequired() gets called before
> onConfigure() during the request cycle (at least this is the behaviour I see
> during debugging).
> >
> >The problem is that the user is then able to submit the form without filling
> in the required field if validation completely succeeds at once. Also the
> required fields "lag" behind one request cycle.
> >
> >
> >>
> >>-Tom
> >>
> >>
> >> Thomas Götz wrote:
> >>
> >> > Yes, you can also push the state instead of pulling it, which besides is
> >> preferrable in terms of efficiency (as onConfigure() is only called once
> per
> >> request whereas isVisible() is potentially called many time):
> >> >
> >> > TextField textField = new TextField("textField") {
> >> >@Override
> >> >protected void onConfigure() {
> >> >super.onConfigure();
> >> >setVisible(condition);
> >> >}
> >> > };
> >> >
> >> > You can also call textField.setVisible(...) in the Page's or Panel's
> >> onConfigure(), but then you need a reference to the textField (property of
> the
> >> page or panel). Or - if possible - you can group your FormComponents into a
> >> WebMarkupContainer an set the visibility there.
> >> >
> >> >   -Tom
> >>
> >>
> >> -
> >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> >> For additional commands, e-mail: users-h...@wicket.apache.org
> >>
> >
> >
> >Think green - keep it on the screen.
> >
> >This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, confidential
> information and/or be subject to legal privilege. It should not be copied,
> disclosed to, retained or used by, any other party. If you are not an intended
> recipient then please promptly delete this e-mail and any attachment and all
> copies and inform the sender. Thank you.
> >
> >
> >
> >-
> >To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> >For additional commands, e-mail: users-h...@wicket.apache.org
> >

Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



RE: Conditional validation without overriding isRequired

2012-06-06 Thread Schlärmann , Bob
Thanks for your reply,

> Argh, confused setVisible() with setRequired, my bad ;-)
> But nevertheless: call setRequiered(condition) in onConfigure().

I've tried this but if I am correct isRequired() gets called before 
onConfigure() during the request cycle (at least this is the behaviour I see 
during debugging). 

The problem is that the user is then able to submit the form without filling in 
the required field if validation completely succeeds at once. Also the required 
fields "lag" behind one request cycle.


> 
>-Tom
> 
> 
> Thomas Götz wrote:
> 
> > Yes, you can also push the state instead of pulling it, which besides is
> preferrable in terms of efficiency (as onConfigure() is only called once per
> request whereas isVisible() is potentially called many time):
> >
> > TextField textField = new TextField("textField") {
> >@Override
> >protected void onConfigure() {
> >super.onConfigure();
> >setVisible(condition);
> >}
> > };
> >
> > You can also call textField.setVisible(...) in the Page's or Panel's
> onConfigure(), but then you need a reference to the textField (property of the
> page or panel). Or - if possible - you can group your FormComponents into a
> WebMarkupContainer an set the visibility there.
> >
> >   -Tom
> 
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 


Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Conditional validation without overriding isRequired

2012-06-05 Thread Schlärmann , Bob
Hello,

A question about form processing: is it possible to do conditional form 
validation without overriding FormComponent#isRequired?

I have a form with about 5 different form components (e.g. textfields, 
dropdown, radiobutton). These fields are only required if a RadioGroup has a 
certain value.

I've read the solution given in 
https://cwiki.apache.org/WICKET/conditional-validation.html. But this means I 
have to subclass all form components  and override isRequired. Is there an 
easier solution?

Currently I'm using an Ajax call and disable the container of the optional 
components, however that doesn't work if Javascript is disabled (also not safe 
presumably).

Best regards,

Bob



Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



RE: Form submit event

2012-03-26 Thread Schlärmann , Bob
Ok I'll try to rephrase my question:

Is there an equivalent to the Behavior class for form submissions? e.g. allow 
external classes to override or extent behavior of form components.

I'm trying to show/hide sections of a form when a user selects a radio button 
which is also part of the form. The transition needs to be done without a page 
reload. 

One way to accomplish this is to add an onClick AJAX behavior to the radio 
component. This AJAX behavior then enables/disables the section that was made 
visible at the server side (on the client side this is done through DHTML). 

However this AJAX call is not really needed if it was possible to set the state 
of the target component just before the form submission.

Note that I can't use Behavior.onConfigure since that method gets called after 
the form submission processes has ended.

Thanks,

Bob

> -Original Message-
> From: Martin Grigorov [mailto:mgrigo...@apache.org]
> Sent: maandag 26 maart 2012 14:13
> To: users@wicket.apache.org
> Subject: Re: Form submit event
> 
> Hi,
> 
> Can you rephrase after what and before what?
> 
> On Mon, Mar 26, 2012 at 1:48 PM, Schlärmann, Bob
>  wrote:
> > Hello List,
> >
> > I'm trying to set the enable state of some form component based on the
> outcome of another form component. This needs to be done after a form request
> is submitted but before the form submitting process is started.
> >
> > Are there any methods to do this?
> >
> > Best regards,
> >
> > Bob
> >
> >
> > Think green - keep it on the screen.
> >
> > This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, confidential
> information and/or be subject to legal privilege. It should not be copied,
> disclosed to, retained or used by, any other party. If you are not an intended
> recipient then please promptly delete this e-mail and any attachment and all
> copies and inform the sender. Thank you.
> >
> 
> 
> 
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 


Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



Form submit event

2012-03-26 Thread Schlärmann , Bob
Hello List,

I'm trying to set the enable state of some form component based on the outcome 
of another form component. This needs to be done after a form request is 
submitted but before the form submitting process is started.

Are there any methods to do this?

Best regards,

Bob


Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



RE: FormTester and components contained in Border

2012-02-23 Thread Schlärmann , Bob
> In the projects I have worked on we have used helper Path objects for
> testing which describe how to find a child of a given Component.
> In first sight it looks like we are duplicating the component tree and
> this is almost true but it helps a lot for such kind of problems
> because the Path helper hides these details from you and if you change
> something in the original component hierarchy then you need to
> fix only the related Path object and all your tests work again.
> Otherwise you have to fix the component path in all tests where you
> use it.

I'm also experiencing this, after making changes to the hierarchy inside a 
component unit tests start to fail because component paths have changed. 

Your suggestions looks interesting and would solve this problem. 


> 
> Another approach is to use MarkupContainer#visitChildren() + IVisitFilter.
> In your example:
> VisitorHelper.getComponentPath(form, "firstname", TextField.class)
> i.e. the helper will find the single child with type TextField and id
> "firstName" down in the hierarchy. From there on is easy to recreate
> the component path back to the root (the form in this case).
> 
> The second approach sounds good enough for me to be included in WicketTester
> ...
> 
> On Thu, Feb 23, 2012 at 1:05 PM, Schlärmann, Bob
>  wrote:
> > Hi list,
> >
> > I have a form with components each contained within an individual border.
> When testing the form with FormTester I have to specify the full component id
> including the intermediate component id's added by the border. Is there any
> easier way to do this, e.g. with wildcard paths or something?
> >
> > For example with a form like:
> >
> > 
> > 
> >   
> > 
> > 
> >
> > The following id needs to be used for FormTester.setValue:
> >
> > "border.borderFirstname:border.borderFistname_body:firstname"
> >
> > Best regards,
> >
> > Bob
> >
> >
> > Think green - keep it on the screen.
> >
> > This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, confidential
> information and/or be subject to legal privilege. It should not be copied,
> disclosed to, retained or used by, any other party. If you are not an intended
> recipient then please promptly delete this e-mail and any attachment and all
> copies and inform the sender. Thank you.
> >
> 
> 
> 
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 


Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



FormTester and components contained in Border

2012-02-23 Thread Schlärmann , Bob
Hi list,

I have a form with components each contained within an individual border. When 
testing the form with FormTester I have to specify the full component id 
including the intermediate component id's added by the border. Is there any 
easier way to do this, e.g. with wildcard paths or something?

For example with a form like:



   



The following id needs to be used for FormTester.setValue:

"border.borderFirstname:border.borderFistname_body:firstname"

Best regards,

Bob


Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



RE: CompoundPropertyModel and FormComponent

2012-01-18 Thread Schlärmann , Bob
Thanks for your response. After some more debugging I've found the cause and 
also found a solution.

The cause is that models of intermediate components, such as the Panel in my 
case, are never initialized if they do not already have a model. 

The parent's model is looked up in Component.initModel(), however this method 
uses a special method for getting the model of the parent that does not 
initialize the parent's model if it is not already initialized. The behaviour 
is intentional as there is a comment on this line:

// Get model
// Don't call the getModel() that could initialize many inbetween
// completely useless models.
// IModel model = current.getModel();
IModel model = current.getModelImpl();

In my case I think this intermediate the inbetween model should get 
initialized. 

The workaround is to initialize the model in onBeforeRender(), before calling 
super.onBeforeRender(), and let the Panel implement the IFormVisitorParticipant 
interface. Then in IFormVisitorParticipant.processChildren() initialize the 
model again (by just calling getDefaultModel()). This last trick is needed in 
order to get the model initialized before it's children are submitted.

The complete class is as follows:

public class AddressPanel extends Panel implements IFormVisitorParticipant {
public AddressPanel(String id) {
super(id);

add(new TextField("street"));
}

protected IModel initModel() {
IModel model = super.initModel();

return new CompoundPropertyModel(model);
}

protected void onBeforeRender() {
getDefaultModel(); // getDefaultModel initialized model if not yet 
initialized

   super.onBeforeRender();
}

public boolean processChildren() {
getDefaultModel();

return true;
}
}

In SomePage.class you can "bind" the panel to an Address property:

Address address; // consists of a single property named street

SomePage() {
   Form form = new Form("form", new 
CompoundPropertyModel(this));
   form.add(new AddressPanel("address"));
   add(form);
}


This solution seems a bit awkward though so I'm using a constructor with model 
solution in my application.

Best regards,

Bob


> At this point I would override/debug method updateModel() inside
> AddressPanel to see if model's object is modified by this method .
> Just my 2 cents...
> >> Yes, I think you are doing it "the Wicket way", but your snippet and
> >> mine should work. Do you modify components' model somewhere else?
> > No, I don't think so. The page to which the component is added is
> constructed as follows:
> >
> > CompoundPropertyModel  model = new
> CompoundPropertyModel(this);
> > Form  form = new Form("form", model);
> > form.add(new TextField("person.firstname"));
> > form.add(new AdresPanel("person.adres"));
> >
> > No other code modifies the model.
> >
> >>> Which model do you get if you call getDefaultModel() inside oninitialize?
> > The result of getDefaultModel() is an instance of
> CompoundPropertyModel$AttachedCompoundPropertyModel, with owner set to the
> AdresPanel and with target set to a CompoundPropertyModel which in turn has
> target HomePage.
> >
> > I noticed that upon initializing the model is set correctly. However when
> inspecting the model in onBeforeRender() during the submit request the target
> of the model of the AddressPanel.street model is set to HomePage.
> >
> >>> Thanks for your reply. I've tried it but it still gave the same error.
> >>>
> >>> However I also tried the following modified version of your idea:
> >>>
> >>> In AddressPanel.java:
> >>>
> >>> @Override
> >>> protected void onInitialize() {
> >>>   super.onInitialize();
> >>>  Object o = getDefaultModelObject();
> >>>
> >>>  setDefaultModel(new
> CompoundPropertyModel(getDefaultModelObject()));
> >>> }
> >>>
> >>> With the above code I can now load the page, also the
> >> getDefaultModelObject() returns the correct Address instance. Unfortunately
> >> upon submitting the form I get the same exception again ("No get method
> >> defined for class: class foo.HomePage expression: street").
> >>> By the way: am I doing things "the Wicket way"? Is this how you would
> reuse
> >> parts of a form in Wicket?
> >>>
> >>>
> >>> Best regards,
> >>>
> >>> Bob
> >>>
> >>
> >> -
> >> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> >> For additional commands, e-mail: users-h...@wicket.apache.org
> >>
> >
> > Think green - keep it on the screen.
> >
> > This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, confidential
> information and/or be subject to legal privilege. It should not be copied,
> disclosed to, retained or used by, any other party. If you are not an intended
> recipient then please promptly delete this e-mail and any attachment and all
> copies and inform the s

RE: CompoundPropertyModel and FormComponent

2012-01-16 Thread Schlärmann , Bob
> Yes, I think you are doing it "the Wicket way", but your snippet and
> mine should work. Do you modify components' model somewhere else? 
No, I don't think so. The page to which the component is added is constructed 
as follows:

CompoundPropertyModel model = new 
CompoundPropertyModel(this);
Form form = new Form("form", model);
form.add(new TextField("person.firstname"));
form.add(new AdresPanel("person.adres"));

No other code modifies the model.

> > Which model do you get if you call getDefaultModel() inside oninitialize?
The result of getDefaultModel() is an instance of 
CompoundPropertyModel$AttachedCompoundPropertyModel, with owner set to the 
AdresPanel and with target set to a CompoundPropertyModel which in turn has 
target HomePage.

I noticed that upon initializing the model is set correctly. However when 
inspecting the model in onBeforeRender() during the submit request the target 
of the model of the AddressPanel.street model is set to HomePage.

> > Thanks for your reply. I've tried it but it still gave the same error.
> >
> > However I also tried the following modified version of your idea:
> >
> > In AddressPanel.java:
> >
> > @Override
> > protected void onInitialize() {
> > super.onInitialize();
> > Object o = getDefaultModelObject();
> >
> > setDefaultModel(new CompoundPropertyModel(getDefaultModelObject()));
> > }
> >
> > With the above code I can now load the page, also the
> getDefaultModelObject() returns the correct Address instance. Unfortunately
> upon submitting the form I get the same exception again ("No get method
> defined for class: class foo.HomePage expression: street").
> >
> > By the way: am I doing things "the Wicket way"? Is this how you would reuse
> parts of a form in Wicket?
> >
> >
> >
> > Best regards,
> >
> > Bob
> >
> 
> 
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 


Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



RE: CompoundPropertyModel and FormComponent

2012-01-16 Thread Schlärmann , Bob
Thanks for your reply. I've tried it but it still gave the same error. 

However I also tried the following modified version of your idea:

In AddressPanel.java:

@Override
protected void onInitialize() {
super.onInitialize();
   Object o = getDefaultModelObject();

   setDefaultModel(new CompoundPropertyModel(getDefaultModelObject()));
}

With the above code I can now load the page, also the getDefaultModelObject() 
returns the correct Address instance. Unfortunately upon submitting the form I 
get the same exception again ("No get method defined for class: class 
foo.HomePage expression: street").

By the way: am I doing things "the Wicket way"? Is this how you would reuse 
parts of a form in Wicket? 



Best regards,

Bob
> Hi,
> 
> I think you need to build a CompoundPropertyModel inside the component
> itself. Override onInitialize method of AddressPanel and try with
> something like this:
> 
> @Override
>  protected void onInitialize() {
>  super.onInitialize();
>  setDefaultModel(new CompoundPropertyModel(getDefaultModel()));
>  }
> 
> 
> > Hi list,
> >
> > I've created a reusable form component for editing an address, called
> AddressPanel. It inherits from FormComponent and consists of multiple text
> fields for inputting data, instances of the component get added to a Form
> instance.
> >
> > How do I use this component together with a CompoundPropertyModel? I'm using
> the following code to add the component to the form:
> >
> > Form  form = new Form("form", new
> CompoundPropertyModel(this)); // HomePage has an instance of Person
> called person
> > form.add(new TextField("person.firstname"));
> > form.add(new AddressPanel("person.address"));
> >
> > However this gives the following exception: "Last cause: No get method
> defined for class: class foo.HomePage expression: street."
> >
> > "street" is a text field that is added to the AddressPanel. Is it possible
> to have the "street" field bound to person.address.street without renaming the
> text field inside AddressPanel? I don't want to rename it since this way I
> can't reuse the component for other entities that have addresses.
> >
> > Best regards,
> >
> > Bob
> >
> >
> > Think green - keep it on the screen.
> >
> > This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, confidential
> information and/or be subject to legal privilege. It should not be copied,
> disclosed to, retained or used by, any other party. If you are not an intended
> recipient then please promptly delete this e-mail and any attachment and all
> copies and inform the sender. Thank you.
> >
> >
> >
> > -
> > 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
> 


Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



CompoundPropertyModel and FormComponent

2012-01-16 Thread Schlärmann , Bob
Hi list,

I've created a reusable form component for editing an address, called 
AddressPanel. It inherits from FormComponent and consists of multiple text 
fields for inputting data, instances of the component get added to a Form 
instance.

How do I use this component together with a CompoundPropertyModel? I'm using 
the following code to add the component to the form:

Form form = new Form("form", new 
CompoundPropertyModel(this)); // HomePage has an instance of Person 
called person
form.add(new TextField("person.firstname"));
form.add(new AddressPanel("person.address"));

However this gives the following exception: "Last cause: No get method defined 
for class: class foo.HomePage expression: street."

"street" is a text field that is added to the AddressPanel. Is it possible to 
have the "street" field bound to person.address.street without renaming the 
text field inside AddressPanel? I don't want to rename it since this way I 
can't reuse the component for other entities that have addresses.

Best regards,

Bob


Think green - keep it on the screen.

This e-mail and any attachment is for authorised use by the intended 
recipient(s) only. It may contain proprietary material, confidential 
information and/or be subject to legal privilege. It should not be copied, 
disclosed to, retained or used by, any other party. If you are not an intended 
recipient then please promptly delete this e-mail and any attachment and all 
copies and inform the sender. Thank you.



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org