Search code examples
submittapestry

Context parameter not working in Tapestry 5.3.2 for Submit


I have a loop displaying records, and I want to add submit buttons to all the rows. The reason they need to be submit is because there is a form at the bottom I would like to have persisted when the user selected one of the buttons.

I've seen the comments about using defer, etc, but nothing seems to work for me. The current submit code I'm trying is:

<input t:id="deleteItem" t:type="submit" t:context="item.number.content"   value="deleteItem" class="deleteItem" />

To expand on the context: The current context I have listed, is just a string within the number object within the item object. In fact, it's being displayed in the code above perfectly fine.

To test this differently, I've replace item.number.content with a getContext() method and had it return a hard-coded 1. I then debug this method and see it being called when the page is SUBMITTED, not when the page is rendered as I would have expected.

The context is never populated until after the button is pushed. Am I misunderstanding something??

Edit:

So my issue is with getting the context value. Take for instance my code:

<t:loop source="itemsList" value="item" formState="none">
<!-- Display info here -->
<input t:id="deleteItem" t:type="submit" t:context="myContext" value="deleteItem"    class="deleteItem" />  
</t:loop>

The definition for getMyContext is:

public String getMyContext() {
    String context = item.getNumber().getContent();
    return context;
}

The problem is, the method is not called until after the submit has been pressed at which time the variable "item" is null. I was expecting getMyContext to be called each time the submit button is rendered, and then when the submit is selected, the event would be triggered with the appropriate context. Does that make sense?


Solution

  • I finally figured out what my problem was:

    formState="none" 
    

    I originally did this because it was having trouble translating between my Objects and a String. When this is selected, the submit buttons don't work properly. I ended up changing it to formState="iteration" and now it is working exactly as I expected it to (and I needed the defer as expected too).