Details
-
Bug
-
Status: Resolved
-
Resolution: Incomplete
-
3.0
-
None
-
None
-
Operating System: Other
Platform: Other
-
28359
Description
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.