Re: [Wicket 1.2.6] How to get Wizard's form from inside a WizardStep?

2008-01-07 Thread Paolo Di Tommaso
Emh .. not really because that source IS the patch ;)


On Jan 8, 2008 4:52 AM, Timo Rantalaiho <[EMAIL PROTECTED]> wrote:

> On Mon, 07 Jan 2008, Paolo Di Tommaso wrote:
> > I would propose the following patch to AjaxFormSubmitBehavior.
> >
> > Basically adding a form-less constructor so that when the form obejct is
> not
> > specified it will discovered using the findParent(Form.class) method.
>
> Could you get the same event by
>
>  AjaxFormSubmitBehavior behavior =
>  new AjaxFormSubmitBehavior(null, "onchange") {
>  @Override
>  protected Form getForm() {
>  return findParent(Form.class);
>  }
>  ...
>  }
>
> as stated in the source code:
>
> > /* form component cannot be null */
> > if( form == null ) {
> > throw new IllegalStateException("Unable to discover
> parent
> > form object. Try to override getForm() method with different deferred
> > strategy");
>
> Best wishes,
> Timo
>
> --
> Timo Rantalaiho
> Reaktor Innovations Oyhttp://www.ri.fi/ >
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


Re: [Wicket 1.2.6] How to get Wizard's form from inside a WizardStep?

2008-01-07 Thread Timo Rantalaiho
On Mon, 07 Jan 2008, Paolo Di Tommaso wrote:
> I would propose the following patch to AjaxFormSubmitBehavior.
> 
> Basically adding a form-less constructor so that when the form obejct is not
> specified it will discovered using the findParent(Form.class) method.

Could you get the same event by

  AjaxFormSubmitBehavior behavior = 
  new AjaxFormSubmitBehavior(null, "onchange") {
  @Override
  protected Form getForm() {
  return findParent(Form.class);
  }
  ...
  }

as stated in the source code:

> /* form component cannot be null */
> if( form == null ) {
> throw new IllegalStateException("Unable to discover parent
> form object. Try to override getForm() method with different deferred
> strategy");

Best wishes,
Timo

-- 
Timo Rantalaiho   
Reaktor Innovations Oyhttp://www.ri.fi/ >

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Wicket 1.2.6] How to get Wizard's form from inside a WizardStep?

2008-01-07 Thread Igor Vaynberg
jira is a better place for this...

-igor


On Jan 7, 2008 1:32 AM, Paolo Di Tommaso <[EMAIL PROTECTED]> wrote:
> I would propose the following patch to AjaxFormSubmitBehavior.
>
> Basically adding a form-less constructor so that when the form obejct is not
> specified it will discovered using the findParent(Form.class) method.
>
>
> Core developers what do you think about it ?
>
> Paolo
>
>
> abstract public class AjaxFormSubmitBehavior extends AjaxEventBehavior{
>
> private Form form;
>
>
> public LazyFormSubmitBehavior(String event) {
> super(event);
> }
>
> public LazyFormSubmitBehavior( Form form, String event ) {
> super(event);
> this.form = form;
> }
>
> protected Form getForm() {
> if( form == null ) {
> form = (Form) getComponent().findParent(Form.class);
> /* form component cannot be null */
> if( form == null ) {
> throw new IllegalStateException("Unable to discover parent
> form object. Try to override getForm() method with different deferred
> strategy");
> }
> }
>
> return form;
> }
>
> @Override
> protected CharSequence getEventHandler()
> {
> final String formId = getForm().getMarkupId();
> final CharSequence url = getCallbackUrl();
>
>
> AppendingStringBuffer call = new
> AppendingStringBuffer("wicketSubmitFormById('").append(formId).append("',
> '").append(url).append("', ");
>
> if (getComponent() instanceof Button)
> {
> 
> call.append("'").append(((FormComponent)getComponent()).getInputName()).append("'
> ");
> }
> else
> {
> call.append("null");
> }
>
> return getCallbackScript(call, null, null) + ";";
> }
>
> @Override
> protected void onEvent(AjaxRequestTarget target)
> {
> getForm().onFormSubmitted();
> if (!getForm().hasError())
> {
> onSubmit(target);
> }
> else
> {
> onError(target);
> }
> }
>
> protected abstract void onSubmit(AjaxRequestTarget target);
>
> protected void onError(AjaxRequestTarget target)
> {
>
>
> }
>
> }
>
> On Jan 7, 2008 9:45 AM, Fabio Fioretti <[EMAIL PROTECTED]> wrote:
>
> > Thanks everybody for the precious help, a custom lazy
> > AjaxFormSubmitBehavior was the way to go.
> >
> >
> > Fabio Fioretti - WindoM
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Wicket 1.2.6] How to get Wizard's form from inside a WizardStep?

2008-01-07 Thread Paolo Di Tommaso
I would propose the following patch to AjaxFormSubmitBehavior.

Basically adding a form-less constructor so that when the form obejct is not
specified it will discovered using the findParent(Form.class) method.


Core developers what do you think about it ?

Paolo


abstract public class AjaxFormSubmitBehavior extends AjaxEventBehavior{

private Form form;


public LazyFormSubmitBehavior(String event) {
super(event);
}

public LazyFormSubmitBehavior( Form form, String event ) {
super(event);
this.form = form;
}

protected Form getForm() {
if( form == null ) {
form = (Form) getComponent().findParent(Form.class);
/* form component cannot be null */
if( form == null ) {
throw new IllegalStateException("Unable to discover parent
form object. Try to override getForm() method with different deferred
strategy");
}
}

return form;
}

@Override
protected CharSequence getEventHandler()
{
final String formId = getForm().getMarkupId();
final CharSequence url = getCallbackUrl();


AppendingStringBuffer call = new
AppendingStringBuffer("wicketSubmitFormById('").append(formId).append("',
'").append(url).append("', ");

if (getComponent() instanceof Button)
{

call.append("'").append(((FormComponent)getComponent()).getInputName()).append("'
");
}
else
{
call.append("null");
}

return getCallbackScript(call, null, null) + ";";
}

@Override
protected void onEvent(AjaxRequestTarget target)
{
getForm().onFormSubmitted();
if (!getForm().hasError())
{
onSubmit(target);
}
else
{
onError(target);
}
}

protected abstract void onSubmit(AjaxRequestTarget target);

protected void onError(AjaxRequestTarget target)
{

}

}

On Jan 7, 2008 9:45 AM, Fabio Fioretti <[EMAIL PROTECTED]> wrote:

> Thanks everybody for the precious help, a custom lazy
> AjaxFormSubmitBehavior was the way to go.
>
>
> Fabio Fioretti - WindoM
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


Re: [Wicket 1.2.6] How to get Wizard's form from inside a WizardStep?

2008-01-07 Thread Fabio Fioretti
Thanks everybody for the precious help, a custom lazy
AjaxFormSubmitBehavior was the way to go.


Fabio Fioretti - WindoM

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Wicket 1.2.6] How to get Wizard's form from inside a WizardStep?

2008-01-05 Thread Eelco Hillenius
Btw, typically you get the form from the Wizard (getForm). But
obviously, it has to be created before that gives anything other than
null :-)

Eelco

On 1/5/08, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
> Yeah, the form is initialized in the Wizard's init method, not right
> away during construction. You could try patching the wizard and
> creating the form in the constructor instead and see if that solves
> your problem and propose a patch if it does. I wouldn't mind having
> another wizard example in wicket-examples either, so if you want, you
> can make a little test app that plugs in wicket-examples for this :-)
>
> Eelco
>
> On 1/5/08, Paolo Di Tommaso <[EMAIL PROTECTED]> wrote:
> > Let me guess .. you need the form to create a AjaxSubmitLink instance.
> >
> > But the #findParent(Form.class) will return null until the component
> > hierarchy is constructed, being so you cannot invoke it at component
> > construction-time.
> >
> > A possible workaround is to postpone the findParent(Form.class) method
> > invocation instantiating a the AjaxSubmitLink using a form proxy.
> >
> > I've hacked this writing a custom AjaxFormSubmitBehavior that does not
> > require the form instance on its constructor but just discover it - invoking
> > #findParent(Form.class) method - when is required.
> >
> > Me fate sempre lavora.. ;)
> >
> > P
> >
> >
> > On Jan 4, 2008 12:43 PM, Fabio Fioretti <[EMAIL PROTECTED]> wrote:
> >
> > > First of all, many compliments for the great Wicket 1.3 release: we're
> > > looking forward to port our application to the new cool version!
> > >
> > > How can I get the Wizard's form from inside a WizardStep? I need it to
> > > trigger an AjaxSubmitLink which should update a part of my model while
> > > remaining inside that step. What leaves me clueless is the fact that
> > > WizardStep instances are added to the WizardModel instead of the
> > > Wizard, so doing something like this from inside the WizardStep:
> > >
> > > Form form = (Form)WizardStep.this.findParent(Form.class);
> > >
> > > seems to return null; moreover, this makes me wonder how the same
> > > instruction inside WizardStep.AddFormValidatorAction.execute() can
> > > succeed.
> > >
> > > I'm sure I'm missing something really stupid. Please forgive me. :-)
> > >
> > >
> > > Thanks a lot,
> > >
> > > Fabio Fioretti - WindoM
> > >
> > > -
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Wicket 1.2.6] How to get Wizard's form from inside a WizardStep?

2008-01-05 Thread Eelco Hillenius
Yeah, the form is initialized in the Wizard's init method, not right
away during construction. You could try patching the wizard and
creating the form in the constructor instead and see if that solves
your problem and propose a patch if it does. I wouldn't mind having
another wizard example in wicket-examples either, so if you want, you
can make a little test app that plugs in wicket-examples for this :-)

Eelco

On 1/5/08, Paolo Di Tommaso <[EMAIL PROTECTED]> wrote:
> Let me guess .. you need the form to create a AjaxSubmitLink instance.
>
> But the #findParent(Form.class) will return null until the component
> hierarchy is constructed, being so you cannot invoke it at component
> construction-time.
>
> A possible workaround is to postpone the findParent(Form.class) method
> invocation instantiating a the AjaxSubmitLink using a form proxy.
>
> I've hacked this writing a custom AjaxFormSubmitBehavior that does not
> require the form instance on its constructor but just discover it - invoking
> #findParent(Form.class) method - when is required.
>
> Me fate sempre lavora.. ;)
>
> P
>
>
> On Jan 4, 2008 12:43 PM, Fabio Fioretti <[EMAIL PROTECTED]> wrote:
>
> > First of all, many compliments for the great Wicket 1.3 release: we're
> > looking forward to port our application to the new cool version!
> >
> > How can I get the Wizard's form from inside a WizardStep? I need it to
> > trigger an AjaxSubmitLink which should update a part of my model while
> > remaining inside that step. What leaves me clueless is the fact that
> > WizardStep instances are added to the WizardModel instead of the
> > Wizard, so doing something like this from inside the WizardStep:
> >
> > Form form = (Form)WizardStep.this.findParent(Form.class);
> >
> > seems to return null; moreover, this makes me wonder how the same
> > instruction inside WizardStep.AddFormValidatorAction.execute() can
> > succeed.
> >
> > I'm sure I'm missing something really stupid. Please forgive me. :-)
> >
> >
> > Thanks a lot,
> >
> > Fabio Fioretti - WindoM
> >
> > -
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [Wicket 1.2.6] How to get Wizard's form from inside a WizardStep?

2008-01-05 Thread Paolo Di Tommaso
Let me guess .. you need the form to create a AjaxSubmitLink instance.

But the #findParent(Form.class) will return null until the component
hierarchy is constructed, being so you cannot invoke it at component
construction-time.

A possible workaround is to postpone the findParent(Form.class) method
invocation instantiating a the AjaxSubmitLink using a form proxy.

I've hacked this writing a custom AjaxFormSubmitBehavior that does not
require the form instance on its constructor but just discover it - invoking
#findParent(Form.class) method - when is required.

Me fate sempre lavora.. ;)

P


On Jan 4, 2008 12:43 PM, Fabio Fioretti <[EMAIL PROTECTED]> wrote:

> First of all, many compliments for the great Wicket 1.3 release: we're
> looking forward to port our application to the new cool version!
>
> How can I get the Wizard's form from inside a WizardStep? I need it to
> trigger an AjaxSubmitLink which should update a part of my model while
> remaining inside that step. What leaves me clueless is the fact that
> WizardStep instances are added to the WizardModel instead of the
> Wizard, so doing something like this from inside the WizardStep:
>
> Form form = (Form)WizardStep.this.findParent(Form.class);
>
> seems to return null; moreover, this makes me wonder how the same
> instruction inside WizardStep.AddFormValidatorAction.execute() can
> succeed.
>
> I'm sure I'm missing something really stupid. Please forgive me. :-)
>
>
> Thanks a lot,
>
> Fabio Fioretti - WindoM
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


[Wicket 1.2.6] How to get Wizard's form from inside a WizardStep?

2008-01-04 Thread Fabio Fioretti
First of all, many compliments for the great Wicket 1.3 release: we're
looking forward to port our application to the new cool version!

How can I get the Wizard's form from inside a WizardStep? I need it to
trigger an AjaxSubmitLink which should update a part of my model while
remaining inside that step. What leaves me clueless is the fact that
WizardStep instances are added to the WizardModel instead of the
Wizard, so doing something like this from inside the WizardStep:

Form form = (Form)WizardStep.this.findParent(Form.class);

seems to return null; moreover, this makes me wonder how the same
instruction inside WizardStep.AddFormValidatorAction.execute() can
succeed.

I'm sure I'm missing something really stupid. Please forgive me. :-)


Thanks a lot,

Fabio Fioretti - WindoM

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]