Hi Mark,

Nothing special in my code. I was just following sample of AjaxFormLoop on
Tapestry Jumpstart (
http://jumpstart.doublenegative.com.au/jumpstart/examples/tables/ajaxformloop1)
and combined it with your suggestion on thread: "Update Zone inside
AjaxFormLoop".
Here is the snippet from my source:

------------------
* I have master-detail form in my .tml file:

<!-- this is the master (there is one T5.2 Select Component) -->
<t:label for="locationId"/>
<t:select t:id="locationId" t:value="record.locationId"
t:model="locationModel" t:zone="machineZone"/>

<!-- details is using AjaxFormLoop (there is one Select component where the
options is based on master's Select component) -->
<fieldset t:type="AjaxFormLoop" t:id="detail" t:source="detailHolderList"
t:value="detailHolder" t:encoder="encoder">
    <t:unless t:test="detailHolder.deletedRecord">
       <t:submitnotifier>
         <legend>Machine</legend>
         <t:label for="machineId"/>
         <t:zone t:id="machineZone" id="${machineZoneId}">
             <t:select t:id="machineId"
t:value="detailHolder.machine.machineId" t:model="machineModel"
t:validate="required"/>
         </t:zone>
        <t:removerowlink>remove</t:removerowlink>
       </t:submitnotifier>
    </t:unless>
    <p:addRow>
       <t:addrowlink>Add Machine</t:addrowlink>
     </p:addRow>
</fieldset>
--------------------------
* on Java file:
On this snippet, I use @Persist to persist into session, but of course we
can use session.setAttribute() and session.getAttribute() if we want to have
more control about session keys and stored information.

@InjectComponent
private Zone machineZone;

// this detailHolderList contains key of records on AjaxFormLoop. We use
these keys in MultiZoneUpdate.
@Persist
private List<DetailHolder> detailHolderList;

@Persist
private SelectModel machineModel;

public String getMachineZoneId() {
    return "detailHolder-" + detailHolder.getKey();
}

CsActivityHolder onAddRowFromDetail() {
    Machine newMachine = new Machine();
    DetailHolder newDetailHolder = new DetailHolder(newMachine, true, 0 -
System.nanoTime());
    detailHolderList.add(newDetailHolder);
    return newDetailHolder;
}

void onRemoveRowFromDetail(DetailHolder detailHolder) {
    int index = detailHolderList.indexOf(detailHolder);
    DetailHolder holder = detailHolderList.get(index);
    if (holder.isNewRecord()) {
        holderList.remove(detailHolder);
    } else {
        holder.setDeletedRecord(true);
    }
}

@OnEvent(value = EventConstants.VALUE_CHANGED, component = "locationId")
public Object onValueChanged(Long locationId)
{
        machineModel =
machineManager.getMachineSelectModelByLocationId(locationId);
        MultiZoneUpdate result = null;

        for (CsActivityHolder holder : csActivityHolderList) {
            String idOfDetailSelect = "machineZone-" + holder.getKey();

            if (result == null) {
                result = new MultiZoneUpdate(idOfDetailSelect, machineZone);
            } else {
                result = result.add(idOfDetailSelect, machineZone);
            }
        }
        return result;
}

Using above code, when user change master's Select component, then all
detail's Select component (inside ajaxformloop) is being updated.

Best regards,
Yohan Yudanara

On Tue, Feb 8, 2011 at 8:38 PM, Mark <mark-li...@xeric.net> wrote:

> On Tue, Feb 8, 2011 at 2:46 AM, Yohan Yudanara <yohan.yudan...@gmail.com>
> wrote:
>
> > In AddRow/RemoveRow, I save zone ids in AjaxFormLoop into session.
> > So, when the onValueChanged of Select component occured, I can retrieve
> this
> > value from session.
>
> Interesting.  Could you share an example of how you are doing this?
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to