You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Mat Gessel <ma...@gmail.com> on 2006/05/17 01:53:23 UTC

For + TextField bug?

I have a trivial app which consists of a Form, a Submit and one
TextField wrapped by a For loop. The For component binds the TextField
to a mutable
String wrapper class (Value.java).

The Problem:
Every other time I submit the form the TextField value is reset to
it's initial value.

On the 1st submit, the For component binds the TextField to the Value
object which I have specified (a page property) and it is updated
properly in the rewind.

On the 2nd submit, the For component binds the TextField to a Value
object which it deserializes. This duplicate Value object is then
updated. My page property never gets updated and it's default value is
rendered in the response.

The behavior alternates every other submit.

Should I submit this as a bug?

Is there another way to collect the values of fields generated by a for loop?

-= Mat


Home.html
----------------
<html>
<body>
<form jwcid="@Form">
<table>
        <tr>
                <td
                        jwcid="@For"
                        element="td"
                        source="ognl:values"
                        value="ognl:currentValue">

                        <input
                                jwcid="@TextField"
                                value="ognl:currentValue.value"/>
                </td>
        </tr>
</table>
<p><input jwcid="@Submit" listener="listener:onSubmit"/></p>
</form>
</body>
</html>


Home.java
---------------
public abstract class Home extends BasePage implements PageBeginRenderListener
{
        public abstract Value getCurrentValue();
        public abstract Value[] getValues();
        public abstract void setValues(Value[] values);
        public void pageBeginRender(PageEvent event)
        {
                Value[] values = getValues();
                if (values == null)
                {
                        System.out.println("\nHome.pageBeginRender()
{instansiating values}");
                        values = new Value[] { new Value("a") };
                        setValues(values);
                }
        }
        public void onSubmit(IRequestCycle cycle)
        {
                System.out.println("Home.onSubmit() {values[0].value=" +
getValues()[0].getValue() + ", values[0]=" + getValues()[0] + "}");
                System.out.flush();
        }
}


Value.java
---------------
public class Value implements Serializable
{
        private static final long serialVersionUID = 3631215785425922895L;
        private String m_value;
        public Value(String value)
        {
                System.out.println("Value.<init>(" + value + ")");
                m_value = value;
        }
        public String getValue()
        {
                return m_value;
        }
        public void setValue(String value)
        {
                System.out.println("Value.setValue(" + value + ")
{value=" + m_value
+ ", this=" + this + "}");
                m_value = value;
        }
}


Debug output
-------------------
Home.pageBeginRender() {instansiating values}
Value.<init>(a)

Home.pageBeginRender() {instansiating values}
Value.<init>(a)
Value.setValue(b) {value=a, this=Value@11b7a14}
Home.onSubmit() {values[0].value=b, values[0]=Value@11b7a14}

Home.pageBeginRender() {instansiating values}
Value.<init>(a)
Value.setValue(c) {value=b, this=Value@bd4570}
Home.onSubmit() {values[0].value=a, value=Value@1b2351e}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org