Context parameter not working in Tapestry 5.3.2 for Submit

Go To StackoverFlow.com

0

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?

2012-04-04 21:22
by DSmyte
What do you mean by never populated? How are you retrieving the context in your event handlers? Can you add that code to the question - joostschouten 2012-04-05 06:20
Thanks, I added the following: 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 - DSmyte 2012-04-05 21:58



3

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).

2012-04-09 19:03
by DSmyte


1

Try adding the following to the page/component you add this t:submit to:

@OnEvent(component = "deleteItem")
private void handleSubmit(Integer contextValue) {
     //Do whatever you need to do with the passed context value here.
     //Most commonly you would store the context in a java page/component field to 
     //be used by the form eventhandler to do some sort of CRUD
}

The context value will not get written out while rendering the page, it will be passed as a parameter to your event handler while submitting the form. So what you are seeing is correct behavior.

2012-04-06 06:40
by joostschouten
Thanks for the response, however it's not the handling of the event thats the problem - it's the fact that it gets the context when I submit the button. I'll add more in the question to explain what I mean, thanks for the help - DSmyte 2012-04-07 18:03
I'm pretty sure the context should be persisted in the form and passed along when you hit submit. I had a look at the source and in your case you do need a t:defer="false" since your submit is in a loop. Check it out at: http://tapestry.apache.org/5.3.1/apidocs/org/apache/tapestry5/corelib/components/Submit.htm - joostschouten 2012-04-07 21:03
That's exactly what I thought - but it's not happening, my context method is not called until after the page is rendered and a submit button is pressed. I'm really quite confused, it seems very straight-forward and I'm not that new to Tapestry - DSmyte 2012-04-09 17:42
Ads