tapestry-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh Canfield <joshcanfi...@gmail.com>
Subject Re: Handling form events inside components
Date Fri, 04 Mar 2011 18:47:06 GMT
> But when I change the data in the submit event like
> "onSelectedFromMoveUpButton". the sorting is overwritten by the form
> submission values.

How is it getting overwritten? How are you doing the ordering? What
you've described could work, here is a really simple example:

The Component class:

public class StringListEditor {

    @Parameter
    @Property
    private List<String> list;

    @Property
    private String value;

    @Component
    @Property
    private Loop<String> loop;

    void onSelectedFromUp(int index) {
        if (index == 0) return;
        list.add(index - 1, list.remove(index));
    }

    void onSelectedFromDown(int index) {
        if (index + 1 >= list.size()) return;
        list.add(index + 1, list.remove(index));
    }
}

The component tml

<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
    <h3>Strings</h3>
    <t:loop t:id="loop" source="list" value="value">
        ${loop.index}:
        <t:textfield value="value"/>
        <t:submit t:id="up" context="[loop.index]" defer="false" value="up"/>
        <t:submit t:id="down" context="[loop.index]" defer="false"
value="down"/>
        <br/>
    </t:loop>
</div>

In the page:

<t:form t:id="editor">
    <t:textfield t:id="sometext"/>
    <t:stringlisteditor list="strings"/>
    <t:submit t:id="save"/>
</t:form>

Josh

On Fri, Mar 4, 2011 at 6:57 AM, Stephan Windmüller
<stephan.windmueller@tu-dortmund.de> wrote:
> On 04.03.2011 13:57, Thiago H. de Paula Figueiredo wrote:
>
>>> But the component itself does not contain a form. Is it possible to call
>>> methods during submission of this component without triggering it using
>>> the outside page? For example, onSuccess is not called in the component
>>> because it does not contain the form.
>> Events bubble up (from the origin to its parent and so on until it reaches
>> the containing page) and just up.
>> Could you post your component tree? It's a little bit hard to figure it
>> out from your description . . .
>
> Of course. I have a page like this
>
> ---
>
> <t:layout>
>  <t:form>
>  <t:textfield t:id="name">
>  <t:anothercomponent value="otherdata"/>
>  <t:userlist source="users"/>
>  </t:form>
> </t:layout>
>
> ---
>
> The userlist is my component. It contains an editable list of users.
>
> Now I want to add buttons for actions like "move up" or "delete". When
> the surrounding form is submitted, the userlist component should perform
> the selected action. The data should be saved by the surrounding page
> afterwards.
>
> But when I change the data in the submit event like
> "onSelectedFromMoveUpButton". the sorting is overwritten by the form
> submission values.
>
> - Stephan
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message