You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jaroslav Ciml <ja...@jpower8.cz> on 2016/05/23 15:57:37 UTC

Prepare for submit handler seems to be not called

Hi,

I am getting a strange exception during submit of a Tapestry form that I cannot explain. It happens just rarely (but regularily) in the production environment. I cannot even reproduce the exception.

I have a form in tml file of a Tapestry component.

...
<t:form t:id="searchForm" clientValidation="none">
    ....
    <t:select t:id="globalSport" model="globalSportModel" value="formData.globalSportId" blankOption="never"/>
    ....
</t:form>
..

And here is the important part of corresponding Java file:

...
@Property(read = true, write = false)
private ServiceSearchFormData formData;
...
@OnEvent(value = EventConstants.PREPARE_FOR_SUBMIT, component = "searchForm")
void prepareForSubmit()
{
    formData = new ServiceSearchFormData();
}
...

It seems to be pretty straightforward. ServiceSearchFormData is a DTO with few attributes and getter / setter methods. It encapsulates data submitted in the form. An instance is created on "prepare for submit" event.

The exception occurs in scope of a POST request that submits data to this form. The exception message states:

Failure writing parameter 'value' of component MyPortal:portalindex.portalsearchform.globalsport: Property 'formData' (within property expression 'formData.globalSportId', of cz.ftm.fitsoftware.webapp.components.PortalSearchForm@3262579e) is null.

I have no idea how this happens. How can the property formData be uninitialized? It seems that the method prepareForSubmit is not called.

Thanks for help.
Jarda
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Prepare for submit handler seems to be not called

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Thu, 26 May 2016 05:51:11 -0300, Jaroslav Ciml  
<ja...@jpower8.cz> wrote:

>  Hi, Thiago!

Hi!

> Thanks for your reply.
> Is there a way to validate the t:formdata parameter please? Can I detect  
> whether this parameter contains some meaningful value or not?

I'm sorry, I don't know.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Prepare for submit handler seems to be not called

Posted by Jaroslav Ciml <ja...@jpower8.cz>.
 Hi, Thiago!

Thanks for your reply.
Is there a way to validate the t:formdata parameter please? Can I detect whether this parameter contains some meaningful value or not?

Best wishes
Jarda


> On May25, 2016, at 16:50, Thiago H de Paula Figueiredo <th...@gmail.com> wrote:
> 
> On Wed, 25 May 2016 08:48:17 -0300, Jaroslav Ciml <ja...@jpower8.cz> wrote:
> 
>> Hi Barry,
> 
> Hello, Jaroslav!
> 
>> This pattern (form data groupped in DTO, simple initialization for POST requests in prepare for submit handler, more complex initialization for GET requests in prepare for render handler) is used about hundred times in our app but it produces this rare exception just in case of this form.
>> 
>> I wonder, how can such error occur anyway. I can even hardly think of some hypothesis that would explain such behavior.
>> 
>> Is it possible, that the parameter t:formdata is malformed in the POST request and "prepare for render" event is not triggered? However, I am in doubt whether this hypothesis makes  sense.
> 
> Actually, it makes a lot of sense. The actions to be taken in a form submission are put into objects, serialized and put into t:formdata. So, if t:formdata is malformed, you shouldn't expect anything happening correctly.
> 
>> I have reproduced the issue in a very strange way. I have filled the form in the browser and submitted but I have also manually modified the POST request parameters before sending it to the server (via Firefox plugin Tamper Data). I have replaced the value of t:formdata (I know the parameter values of the request that caused the exception in production environment as our app reports exceptions via email in such case) and I have also removed the value of the parameter t:submit.
> 
> 
> -- 
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Prepare for submit handler seems to be not called

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 25 May 2016 08:48:17 -0300, Jaroslav Ciml  
<ja...@jpower8.cz> wrote:

> Hi Barry,

Hello, Jaroslav!

> This pattern (form data groupped in DTO, simple initialization for POST  
> requests in prepare for submit handler, more complex initialization for  
> GET requests in prepare for render handler) is used about hundred times  
> in our app but it produces this rare exception just in case of this form.
>
> I wonder, how can such error occur anyway. I can even hardly think of  
> some hypothesis that would explain such behavior.
>
> Is it possible, that the parameter t:formdata is malformed in the POST  
> request and "prepare for render" event is not triggered? However, I am  
> in doubt whether this hypothesis makes  sense.

Actually, it makes a lot of sense. The actions to be taken in a form  
submission are put into objects, serialized and put into t:formdata. So,  
if t:formdata is malformed, you shouldn't expect anything happening  
correctly.

> I have reproduced the issue in a very strange way. I have filled the  
> form in the browser and submitted but I have also manually modified the  
> POST request parameters before sending it to the server (via Firefox  
> plugin Tamper Data). I have replaced the value of t:formdata (I know the  
> parameter values of the request that caused the exception in production  
> environment as our app reports exceptions via email in such case) and I  
> have also removed the value of the parameter t:submit.


-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Prepare for submit handler seems to be not called

Posted by Jaroslav Ciml <ja...@jpower8.cz>.
Hi Barry,

thanks for nice hint.
I cannot fix it so simply just by adding this one-line method but it shows the way to go anyway.

This pattern (form data groupped in DTO, simple initialization for POST requests in prepare for submit handler, more complex initialization for GET requests in prepare for render handler) is used about hundred times in our app but it produces this rare exception just in case of this form.

I wonder, how can such error occur anyway. I can even hardly think of some hypothesis that would explain such behavior.

Is it possible, that the parameter t:formdata is malformed in the POST request and "prepare for render" event is not triggered? However, I am in doubt whether this hypothesis makes  sense.

I have reproduced the issue in a very strange way. I have filled the form in the browser and submitted but I have also manually modified the POST request parameters before sending it to the server (via Firefox plugin Tamper Data). I have replaced the value of t:formdata (I know the parameter values of the request that caused the exception in production environment as our app reports exceptions via email in such case) and I have also removed the value of the parameter t:submit.

Jarda


> On May25, 2016, at 12:37, Barry Books <tr...@gmail.com> wrote:
> 
> It's difficult to say why it might be null but changing the code to
> 
> public SearchFormData getFormData() {
>   return new SearchFormData();
> }
> 
> should fix it
> 
> On Monday, May 23, 2016, Jaroslav Ciml <ja...@jpower8.cz> wrote:
> 
>> Hi,
>> 
>> I am getting a strange exception during submit of a Tapestry form that I
>> cannot explain. It happens just rarely (but regularily) in the production
>> environment. I cannot even reproduce the exception.
>> 
>> I have a form in tml file of a Tapestry component.
>> 
>> ...
>> <t:form t:id="searchForm" clientValidation="none">
>>    ....
>>    <t:select t:id="globalSport" model="globalSportModel"
>> value="formData.globalSportId" blankOption="never"/>
>>    ....
>> </t:form>
>> ..
>> 
>> And here is the important part of corresponding Java file:
>> 
>> ...
>> @Property(read = true, write = false)
>> private ServiceSearchFormData formData;
>> ...
>> @OnEvent(value = EventConstants.PREPARE_FOR_SUBMIT, component =
>> "searchForm")
>> void prepareForSubmit()
>> {
>>    formData = new ServiceSearchFormData();
>> }
>> ...
>> 
>> It seems to be pretty straightforward. ServiceSearchFormData is a DTO with
>> few attributes and getter / setter methods. It encapsulates data submitted
>> in the form. An instance is created on "prepare for submit" event.
>> 
>> The exception occurs in scope of a POST request that submits data to this
>> form. The exception message states:
>> 
>> Failure writing parameter 'value' of component
>> MyPortal:portalindex.portalsearchform.globalsport: Property 'formData'
>> (within property expression 'formData.globalSportId', of
>> cz.ftm.fitsoftware.webapp.components.PortalSearchForm@3262579e) is null.
>> 
>> I have no idea how this happens. How can the property formData be
>> uninitialized? It seems that the method prepareForSubmit is not called.
>> 
>> Thanks for help.
>> Jarda
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> <javascript:;>
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> <javascript:;>
>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Prepare for submit handler seems to be not called

Posted by Jaroslav Ciml <ja...@jpower8.cz>.
Hi,

there are just two assignments to formData:

@OnEvent(value = EventConstants.PREPARE_FOR_RENDER, component = "searchForm")
void prepareForRender()
{
    formData = new ServiceSearchFormData();
    // more initialization here, i.e. calling setters like formData.setCity(DEFAULT_CITY_NAME);
}

...

@OnEvent(value = EventConstants.PREPARE_FOR_SUBMIT, component = "searchForm")
void prepareForSubmit()
{
    formData = new ServiceSearchFormData();
}


Cheers
Jarda

> On May25, 2016, at 13:51, Cezary Biernacki <ce...@gmail.com> wrote:
> 
> Hi,
> @Barry, yes, your solution should fix null pointer exception, but probably
> it would break the application. A better way:
> 
> public SearchFormData getFormData() {
>   if (formData == null) {
>       formData = new SearchFormData();
>   }
>   return formData;
> }
> 
> However, it is still interesting that formData is null (assuming that there
> is no other code explicitly assigning a value to this field).
> 
> On Wed, May 25, 2016 at 12:37 PM, Barry Books <tr...@gmail.com> wrote:
> 
>> It's difficult to say why it might be null but changing the code to
>> 
>> public SearchFormData getFormData() {
>>   return new SearchFormData();
>> }
>> 
>> should fix it
>> 
>> On Monday, May 23, 2016, Jaroslav Ciml <ja...@jpower8.cz> wrote:
>> 
>>> Hi,
>>> 
>>> I am getting a strange exception during submit of a Tapestry form that I
>>> cannot explain. It happens just rarely (but regularily) in the production
>>> environment. I cannot even reproduce the exception.
>>> 
>>> I have a form in tml file of a Tapestry component.
>>> 
>>> ...
>>> <t:form t:id="searchForm" clientValidation="none">
>>>    ....
>>>    <t:select t:id="globalSport" model="globalSportModel"
>>> value="formData.globalSportId" blankOption="never"/>
>>>    ....
>>> </t:form>
>>> ..
>>> 
>>> And here is the important part of corresponding Java file:
>>> 
>>> ...
>>> @Property(read = true, write = false)
>>> private ServiceSearchFormData formData;
>>> ...
>>> @OnEvent(value = EventConstants.PREPARE_FOR_SUBMIT, component =
>>> "searchForm")
>>> void prepareForSubmit()
>>> {
>>>    formData = new ServiceSearchFormData();
>>> }
>>> ...
>>> 
>>> It seems to be pretty straightforward. ServiceSearchFormData is a DTO
>> with
>>> few attributes and getter / setter methods. It encapsulates data
>> submitted
>>> in the form. An instance is created on "prepare for submit" event.
>>> 
>>> The exception occurs in scope of a POST request that submits data to this
>>> form. The exception message states:
>>> 
>>> Failure writing parameter 'value' of component
>>> MyPortal:portalindex.portalsearchform.globalsport: Property 'formData'
>>> (within property expression 'formData.globalSportId', of
>>> cz.ftm.fitsoftware.webapp.components.PortalSearchForm@3262579e) is null.
>>> 
>>> I have no idea how this happens. How can the property formData be
>>> uninitialized? It seems that the method prepareForSubmit is not called.
>>> 
>>> Thanks for help.
>>> Jarda
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> <javascript:;>
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>> <javascript:;>
>>> 
>>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Prepare for submit handler seems to be not called

Posted by Cezary Biernacki <ce...@gmail.com>.
Hi,
@Barry, yes, your solution should fix null pointer exception, but probably
it would break the application. A better way:

public SearchFormData getFormData() {
   if (formData == null) {
       formData = new SearchFormData();
   }
   return formData;
}

However, it is still interesting that formData is null (assuming that there
is no other code explicitly assigning a value to this field).

On Wed, May 25, 2016 at 12:37 PM, Barry Books <tr...@gmail.com> wrote:

> It's difficult to say why it might be null but changing the code to
>
> public SearchFormData getFormData() {
>    return new SearchFormData();
> }
>
> should fix it
>
> On Monday, May 23, 2016, Jaroslav Ciml <ja...@jpower8.cz> wrote:
>
> > Hi,
> >
> > I am getting a strange exception during submit of a Tapestry form that I
> > cannot explain. It happens just rarely (but regularily) in the production
> > environment. I cannot even reproduce the exception.
> >
> > I have a form in tml file of a Tapestry component.
> >
> > ...
> > <t:form t:id="searchForm" clientValidation="none">
> >     ....
> >     <t:select t:id="globalSport" model="globalSportModel"
> > value="formData.globalSportId" blankOption="never"/>
> >     ....
> > </t:form>
> > ..
> >
> > And here is the important part of corresponding Java file:
> >
> > ...
> > @Property(read = true, write = false)
> > private ServiceSearchFormData formData;
> > ...
> > @OnEvent(value = EventConstants.PREPARE_FOR_SUBMIT, component =
> > "searchForm")
> > void prepareForSubmit()
> > {
> >     formData = new ServiceSearchFormData();
> > }
> > ...
> >
> > It seems to be pretty straightforward. ServiceSearchFormData is a DTO
> with
> > few attributes and getter / setter methods. It encapsulates data
> submitted
> > in the form. An instance is created on "prepare for submit" event.
> >
> > The exception occurs in scope of a POST request that submits data to this
> > form. The exception message states:
> >
> > Failure writing parameter 'value' of component
> > MyPortal:portalindex.portalsearchform.globalsport: Property 'formData'
> > (within property expression 'formData.globalSportId', of
> > cz.ftm.fitsoftware.webapp.components.PortalSearchForm@3262579e) is null.
> >
> > I have no idea how this happens. How can the property formData be
> > uninitialized? It seems that the method prepareForSubmit is not called.
> >
> > Thanks for help.
> > Jarda
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > <javascript:;>
> > For additional commands, e-mail: users-help@tapestry.apache.org
> > <javascript:;>
> >
> >
>

Re: Prepare for submit handler seems to be not called

Posted by Barry Books <tr...@gmail.com>.
It's difficult to say why it might be null but changing the code to

public SearchFormData getFormData() {
   return new SearchFormData();
}

should fix it

On Monday, May 23, 2016, Jaroslav Ciml <ja...@jpower8.cz> wrote:

> Hi,
>
> I am getting a strange exception during submit of a Tapestry form that I
> cannot explain. It happens just rarely (but regularily) in the production
> environment. I cannot even reproduce the exception.
>
> I have a form in tml file of a Tapestry component.
>
> ...
> <t:form t:id="searchForm" clientValidation="none">
>     ....
>     <t:select t:id="globalSport" model="globalSportModel"
> value="formData.globalSportId" blankOption="never"/>
>     ....
> </t:form>
> ..
>
> And here is the important part of corresponding Java file:
>
> ...
> @Property(read = true, write = false)
> private ServiceSearchFormData formData;
> ...
> @OnEvent(value = EventConstants.PREPARE_FOR_SUBMIT, component =
> "searchForm")
> void prepareForSubmit()
> {
>     formData = new ServiceSearchFormData();
> }
> ...
>
> It seems to be pretty straightforward. ServiceSearchFormData is a DTO with
> few attributes and getter / setter methods. It encapsulates data submitted
> in the form. An instance is created on "prepare for submit" event.
>
> The exception occurs in scope of a POST request that submits data to this
> form. The exception message states:
>
> Failure writing parameter 'value' of component
> MyPortal:portalindex.portalsearchform.globalsport: Property 'formData'
> (within property expression 'formData.globalSportId', of
> cz.ftm.fitsoftware.webapp.components.PortalSearchForm@3262579e) is null.
>
> I have no idea how this happens. How can the property formData be
> uninitialized? It seems that the method prepareForSubmit is not called.
>
> Thanks for help.
> Jarda
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> <javascript:;>
> For additional commands, e-mail: users-help@tapestry.apache.org
> <javascript:;>
>
>