You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by bu...@apache.org on 2004/04/13 10:28:01 UTC

DO NOT REPLY [Bug 28359] New: - Multiple Forms on one page can conflict with each other

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=28359>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=28359

Multiple Forms on one page can conflict with each other

           Summary: Multiple Forms on one page can conflict with each other
           Product: Tapestry
           Version: 3.0
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Framework
        AssignedTo: tapestry-dev@jakarta.apache.org
        ReportedBy: petter.mahlen@chello.se


The case I ran into consisted of a Foreach, with a component being included at 
each iteration of the Foreach. Each of the included components consisted of a 
Form with a ListEdit. Since the ListEdits all have the same names of the 
ListEditMaps, the final HTML comes out something like this (irrelevant stuff 
cut out):

<form method="post" name="Form0" action="/timer/app">
<input type="hidden" name="service" 
value="direct/1/Report/newReports.$WorkDayReport.form"/>
<input type="hidden" name="sp" value="S0"/>
<input type="hidden" name="Form0" 
value="$Checkbox,tasks,hours,miscSelect,miscHours"/>
<input type="hidden" name="tasks" value="1"/>

<snip/>

</form>

<form method="post" name="Form1" action="/timer/app">
<input type="hidden" name="service" 
value="direct/1/Report/newReports.$WorkDayReport.form"/>
<input type="hidden" name="sp" value="S1"/>
<input type="hidden" name="Form1" 
value="$Checkbox,tasks,hours,hours$0,miscSelect,miscHours"/>
<input type="hidden" name="tasks" value="2"/>
<input type="hidden" name="tasks" value="3"/>

When one of the forms is submitted, all the 'tasks' in each of the forms on 
the page are submitted to that form, not just the 'tasks' related to that 
particular form instance. I believe I have traced the problem down to the 
following method in ListEdit:

    protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
    {
        Iterator i = null;

        IForm form = getForm(cycle);

        boolean cycleRewinding = cycle.isRewinding();

        // If the cycle is rewinding, but not this particular form,
        // then do nothing (don't even render the body).

        if (cycleRewinding && !form.isRewinding())
            return;

        String name = form.getElementId(this);

        if (!cycleRewinding)
        {
            i = Tapestry.coerceToIterator(getSourceBinding().getObject());
        }
        else
        {
            RequestContext context = cycle.getRequestContext();
            String[] submittedValues = context.getParameters(name);

            i = Tapestry.coerceToIterator(submittedValues);
        }
        ...

The 'context.getParameters(name)' will return the values for all the fields 
called 'tasks', irrespective of which form they are in.

My proposed solution is to make the following change in Form.java:

    public String getElementId(IFormComponent component, String baseId)
    {
-       String result = _elementIdAllocator.allocateId(baseId);
+       String result = _elementIdAllocator.allocateId(getName() + baseId);

        if (_rewinding)

That way, field names should be unique to the forms they occur in.

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