You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Dave Greggory <da...@yahoo.com> on 2009/02/14 01:15:49 UTC

[T5] How to have a N number of select fields in a form

In spring MVC, I would do the following,

<c:forEach items="myList" value="myItem">
   <form:select path="myMap[myItem.name]" items="${myItem.values}"/>
</c:forEach>

How do I do the same in Tapestry?

I tried the following, but obvisously it didn't work because the Select field is not capable of setting a value in a map.

  @Component (parameters = {"source=myList", "value=myItem", "encoder=itemPrimaryKeyEncoder", "index=index"})
  private Loop                      myListLoop;

  @Component (parameters = { "model=itemSelectModel", "encoder=itemValueEncoder", "value=selectedItem[index]"})
  private Select                    myItemSelectField;

  @Property
  private int                       index;

  @Property
  private Item                   myItem;

  @Property
  private Map<Integer, Item>  selectedItem = new HashMap<Integer, Item>();


I took a look at the sources of AjaxFormLoop and also PagedLoop in Chenille Kit, but I couldn't figure it out.

Any thoughts?

Dave



      


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


Re: [T5] How to have a N number of select fields in a form

Posted by Dave Greggory <da...@yahoo.com>.
Ok, I found that this can be achieved using a Submit Notifier.

  @OnEvent(value = "BeginSubmit")
  public void setupForSubmit()
  {
    final List<String> paramNames = request.getParameterNames();
    selectedItem = new HashMap<Integer, Item>();
    for (String paramName : paramNames)
    {
      if (paramName.startsWith("myItemSelectField"))
      {
        final Item item = getItemValueEncoder().toValue(request.getParameter(paramName));
        if (item != null)
        {
          selectedItem.put(item.getId(), item);
        }
      }
    }
  }


It's not exactly a very elegant solution. If this component was used several times in a page inside different FormFragments, this wouldn't exactly work.  Request params would include params that are for versions of the component that is inside a hidden FormFragment.

Any better solutions?




----- Original Message ----
From: Dave Greggory <da...@yahoo.com>
To: Tapestry users <us...@tapestry.apache.org>
Sent: Friday, February 13, 2009 7:15:49 PM
Subject: [T5] How to have a N number of select fields in a form


In spring MVC, I would do the following,

<c:forEach items="myList" value="myItem">
   <form:select path="myMap[myItem.name]" items="${myItem.values}"/>
</c:forEach>

How do I do the same in Tapestry?

I tried the following, but obvisously it didn't work because the Select field is not capable of setting a value in a map.

  @Component (parameters = {"source=myList", "value=myItem", "encoder=itemPrimaryKeyEncoder", "index=index"})
  private Loop                      myListLoop;

  @Component (parameters = { "model=itemSelectModel", "encoder=itemValueEncoder", "value=selectedItem[index]"})
  private Select                    myItemSelectField;

  @Property
  private int                       index;

  @Property
  private Item                   myItem;

  @Property
  private Map<Integer, Item>  selectedItem = new HashMap<Integer, Item>();


I took a look at the sources of AjaxFormLoop and also PagedLoop in Chenille Kit, but I couldn't figure it out.

Any thoughts?

Dave



      


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


      


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