Cimlman
Cimlman

Reputation: 3824

Prepare for submit event not called in Tapestry

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. ... and it works fine.

However, an exception is thrown in production environment occasionally. I am not able to reproduce it. It happens in scope of 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.

How is that possible? How can the property formData be uninitialized? Can this rare (but regular) exception be caused by malformed value of t:formdata parameter of POST request?

Thanks for any help.

Upvotes: 1

Views: 326

Answers (1)

Tamas Rev
Tamas Rev

Reputation: 7166

Based on this much I can see, I would try two things to narrow down the problem:

  1. I would remove the component = "searchForm" qualifier

    @OnEvent(value = EventConstants.PREPARE_FOR_SUBMIT)
    void prepareForSubmit()
    {
        formData = new ServiceSearchFormData();
    }
    
  2. I would remove all the other @OnEvent annotations to see if any of those swallows this event:

    //@OnEvent(...) 
    void foo() {...}
    

Upvotes: 1

Related Questions