...meaning pattern in its general English usage, not specific to OO design patterns. Given a table like the following (using <% %> as generic server-side script tags):
<form action="someUri" method="post">
<table>
<thead>
<tr>
<td>Widget ID</td>
<td>Description</td>
<td>Price</td>
</tr>
</thead>
<tbody>
<% foreach widget in widgets %>
<tr>
<td>
<!-- input ids need to be mangled
to preserve uniqueness -->
<input type="hidden" id="[Some_Mangled_Input_Id]"
value="<%= widget.Id %>" />
<%= widget.Id %>
</td>
<td>
<!-- prefill if exists for widget -->
<input type="text" id="[Some_Mangled_Input_Id]"
value="<%= widget.Description %>" />
</td>
<td>
<!-- prefill if exists for widget -->
<input type="text" id="[Some_Mangled_Input_Id]"
value="<%= widget.Price %>" />
</td>
</tr>
<% end foreach %>
</tbody>
</table>
<input type="submit" value="Save Changes" />
</form>
And on the server at post:
var widgetIdKeys = all keys in forms collection matching pattern of mangled input Id for Widget.Id hidden input foreach widgetIdKey in widgetIdKeys find matching mangled input Id for Widget.Description text input find matching mangled input Id for Widget.Price text input if input changed per comparison to some original persist Description and Price input for current widget Id end if end foreach
This problem has no doubt been solved for a long time but this is the only approach I can think of and it seems hacky. So my question is: is there a better pattern and if so what does it look like? If this is the only or preferred way to do this, are there right and wrong ways to handle the input Id mangling and parsing? What about the comparison to identify which inputs have changed? I can think of ways to solve this on a per row or per cell level, and maybe those ways exist because there is no good way to solve it on a per table level, but I can also think of downsides to those ways.
Or am I missing the appropiate paradigm altogether? Thanks for any insights.