Question

I encounter this issue when I am trying to update a zone of a component in a handled event (onValueChanged of a select box).

[ERROR] TapestryModule.RequestExceptionHandler Processing of request failed with uncaught exception: Failure writing parameter 'value' of component calendar/Stereotype:daycomponent.selectcategoryactivity: Property 'day' (within property expression 'day.category', of com.hb.craproject.web.components.calendar.stereotype.AddDayStereotypeComponent@3a6b9a8a) is null.
org.apache.tapestry5.ioc.internal.OperationException: Failure writing parameter 'value' of component calendar/Stereotype:daycomponent.selectcategoryactivity: Property 'day' (within property expression 'day.category', of com.hb.craproject.web.components.calendar.stereotype.AddDayStereotypeComponent@3a6b9a8a) is null. [at classpath:com/hb/craproject/web/components/calendar/stereotype/AddDayStereotypeComponent.tml, line 24]

"Day" is a parameter defined like this :

@Parameter(required=true)
@Property
private DayStereotypeBean day

And when the component is rendering for the first time, all works fine. It's only when I try to change the selected value that it crashes and given that error message.

My DayComponents are declared like this in my tml page :

<t:loop source="week" value="dayBean">
  <tr style="border :0.1em solid blue; border-radius : 0.5em">
    <t:day t:id="dayComponent" day="dayBean" /></tr></t:loop>

So this is a List of Day beans. This list is feeded in the setuprender event handler of the page.

I don't understand why the Day parameter lost his reference in the event handler of the select component :

public Object onValueChangedFromSelectDuree(String duree)
{    
//throwing exception, day.Day is a String, this line is just for showing you that the object doesn't exist anymore in the method, if this line is not here, the exception is throwed too because my select tml component use (like many oher components) that object
    day.getDay(); 
    return request.isXHR() ? zoneDuree.getBody() : null;
}

And now you can see the select tml component :

<t:zone t:id="zoneDuree">
        <t:select t:id="selectDuree"
            model="literal:journée,demi-journée,définir" value="day.duree"  zone="zoneDuree" /> <!-- here some fields depending of the select value --></t:zone>

Any idea should be appreciated.

(sorry for my bad english ;) )

Was it helpful?

Solution

The "setuprender" event only fires when your page is initially rendered. Anything initialized in setupRender() will be null in the subsequent event requests.

Here's a few options:

  1. Use the context of the event to pass all the required contextual information. You'll need to initialize any @Parameters needed by your ajax block in the event before the template renders.
  2. Initialize your fields in onActivate() instead of setupRender() as onActivate() is fired before page render AND before event handlers
  3. Use @Persist to persist values in the HTTPSession between requests. I personally hate this approach and avoid HTTPSession usage at all costs.

You might find that the builtin select / ajax update is not sufficient since you can't provide multiple context values. Take a look at the onEvent mixin here which allows you to customise what gets passed from the client to the serverside event when a clientside event (eg change) occurs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top