I have a multi select component similar in functionality to the Palette
component, but with a very different presentation.

I have everything working like I want it except for a problem retrieving
the selected values. Just like Palette this component accepts a List
called selected and I make sure to update the selected object on rewind,
but my page doesn't seem to see the changes.

Here is my renderComponent method:
  protected void renderComponent(IMarkupWriter writer, IRequestCycle
cycle)
  {
      IForm form = Form.get(getPage().getRequestCycle());

      if (form == null)
          throw new ApplicationRuntimeException(
              "MultSelectTable component must be wrapped by a Form.",
              this,
              null,
              null);

      setForm(form);

      setName(form.getElementId(this));

      if (form.isRewinding())
        handleSubmission(cycle);
      
      super.renderComponent(writer, cycle);
  }

Notice the handleSubmission code just like Palette. Here is the
handleSubmission method:
  private void handleSubmission(IRequestCycle cycle)
  {
      RequestContext context = cycle.getRequestContext();
      String[] values = context.getParameters("select_array_id_" +
getName());

      int count = Tapestry.size(values);

      if (count == 0)
          return;

      System.out.println("selected table values: " + values[0]);
      
      List selected = new ArrayList();
      IPropertySelectionModel model = getModel();

      //Transform the incoming "}}"-delimited string to an array using
SPLIT
      String[] valueArray = StringUtils.split(values[0], "}}");
      for (int i = 0; i < valueArray.length; i++)
      {
          System.out.println("value " + i + ": " + valueArray[i]);
          String value = valueArray[i];
          Object option = model.translateValue(value);

          selected.add(option);
      }

      setSelected(selected);
  }

Where setSelected is abstract and my .jwc has an IN parameter defined
just like the Palette. This all seems to work just fine. My System.out
calls show that the selected values are being submitted correctly. Now
in my page java code I have:

        public void submit(IRequestCycle cycle) {
            
           
                System.out.println("start of submit");
                Visit visit = (Visit)getVisit();
                
                List list = getList();
                HashMap hash = new HashMap();
                
                //set all selected items recid and 
                for(int i =0;i<list.size();i++){
                    ParameterBean b = (ParameterBean) list.get(i);

                    hash.put(""+b.getRecid(),"Y");
                  System.out.println("selected field " + i + ": " +
b.getName());
                }
                ...
        }

This happens to use an implementation of IPropertySelectionModel that
uses our custom ParameterBean. The list object is our List that we have
passed to the component in the .page file. This exact same code worked
just fine with Palette, but doesn't work with the new component. The
list only has the preselected entries in it when it gets to the submit
listener. My system.out calls show that handleSubmission from the
component is finished before the start of the submit.

Any ideas?

David

--------------------------------------
David Ethell
CTO, Vital Assets, Inc.
Phone: 800.860.0607 Ex: 102
Email: [EMAIL PROTECTED] 
2020 Pennsylvania Avenue NW
Suite 648
Washington, DC 20006
--------------------------------------  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to