You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by ab...@genuone.com on 2006/06/01 16:01:26 UTC

PropertySelection

Hello, 
In a page that display a query form and query results together, 
I want to remember the property selected by the user for the last query.  I store this value in a page property, but I cannot get the PropertySelection to render using the previous value for the default value.  It reverts to the value of index 0.
My current solution below use LabeledPropertySelectionModel and results in duplicate option in the pull-down.
  
Any help appreciated,
Alex./

from Search.html
           <tr>

             <td><strong><span key="po-component">PO Component</span></strong></td>

             <td><select jwcid="sg_po_component_filter">

                     <option value="0">****Select Label ****</option>

             </select></td>

           </tr>

from the Search.page
    <component id="sg_po_component_filter" type="PropertySelection">
        <binding name="model" value="possibleComponents"/>
        <binding name="value" value="poComponent"/>
    </component>

public abstract class SearchPage extends BasePage implements PageBeginRenderListener {

    @Persist("session")
    public abstract Component getPoComponent();
    public abstract void      setPoComponent(Component poComponent);
    public abstract IPropertySelectionModel getPossibleComponents();
    public abstract void                    setPossibleComponents(IPropertySelectionModel model);

    public void pageBeginRender(PageEvent event) {
        if (getPoComponent() != null)
        	setPossibleComponents(new LabeledPropertySelectionModel(getPossibleComponents(), 
        		getPoComponent().getName(), getPoComponent()));
       }
}

public class SelectionModel<T extends Option> implements IPropertySelectionModel, Serializable {
     private static final long serialVersionUID = 1L;
    private List<T> options;
        this.options = new ArrayList<T>();
        for (T obj: options) {
            this.options.add(obj);
        }
    }
    
    public int getOptionCount() {
        return options.size()+1;
    }

    public Object getOption(int index) {
        return getOptionObj(index);
    }
    public String getLabel(int index) {
        return getOptionObj(index).getName();
    }
    public String getValue(int index) {
        return getOptionObj(index).getCode();
    }
    public Object translateValue(String value) {
        for (T obj : options) 
            if (obj.getCode().equals(value))
                return obj;
        return null;
    }
}

    private Option getOptionObj(int index) {
        return (Option) options.get(index);
    }



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


Re: PropertySelection

Posted by Alexandre Buer <ab...@genuone.com>.
Hi Stephane,

My ComponentImpl object did implement equals() as detailed below, but  the
Option interface included only getCode() and getName(), causing the
comparison to somehow complete incorrectly.  I added the getId() also used
in equals() to the Option interface and it worked.  

Thank you,
Alex./

public class ComponentImpl extends DataObjectImpl implements Component{
   private static final long serialVersionUID = 1L;
   private int     id;
   private String  code         = NULL_STRING;
   private String  name         = NULL_STRING;
   public boolean equals(Object o) {
      if (this == o) {
         return true;
      }

      if (o == null || !(o instanceof ComponentImpl)) {
         return false;
      }

      ComponentImpl component = (ComponentImpl) o;

      if (component.getId() == this.getId()) {
         return true;
      }

      // If both component have their code set up, then it's quite a simple
check....
      if (component.getCode() != null && this.getCode() != null &&
this.getCode() != NULL_STRING ) {
         return component.getCode().equals(this.getCode());
      }

      return false;
   }
--
View this message in context: http://www.nabble.com/PropertySelection-t1716999.html#a4667056
Sent from the Tapestry - User forum at Nabble.com.


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


Re: PropertySelection

Posted by Stephane Decleire <sd...@cariboo-networks.com>.
It seems your T class does not implement a correct comparison operator ...
Have you coorectly define the "equals" function ?

abuer@genuone.com a écrit :
> Hello, 
> In a page that display a query form and query results together, 
> I want to remember the property selected by the user for the last query.  I store this value in a page property, but I cannot get the PropertySelection to render using the previous value for the default value.  It reverts to the value of index 0.
> My current solution below use LabeledPropertySelectionModel and results in duplicate option in the pull-down.
>   
> Any help appreciated,
> Alex./
>
> from Search.html
>            <tr>
>
>              <td><strong><span key="po-component">PO Component</span></strong></td>
>
>              <td><select jwcid="sg_po_component_filter">
>
>                      <option value="0">****Select Label ****</option>
>
>              </select></td>
>
>            </tr>
>
> from the Search.page
>     <component id="sg_po_component_filter" type="PropertySelection">
>         <binding name="model" value="possibleComponents"/>
>         <binding name="value" value="poComponent"/>
>     </component>
>
> public abstract class SearchPage extends BasePage implements PageBeginRenderListener {
>
>     @Persist("session")
>     public abstract Component getPoComponent();
>     public abstract void      setPoComponent(Component poComponent);
>     public abstract IPropertySelectionModel getPossibleComponents();
>     public abstract void                    setPossibleComponents(IPropertySelectionModel model);
>
>     public void pageBeginRender(PageEvent event) {
>         if (getPoComponent() != null)
>         	setPossibleComponents(new LabeledPropertySelectionModel(getPossibleComponents(), 
>         		getPoComponent().getName(), getPoComponent()));
>        }
> }
>
> public class SelectionModel<T extends Option> implements IPropertySelectionModel, Serializable {
>      private static final long serialVersionUID = 1L;
>     private List<T> options;
>         this.options = new ArrayList<T>();
>         for (T obj: options) {
>             this.options.add(obj);
>         }
>     }
>     
>     public int getOptionCount() {
>         return options.size()+1;
>     }
>
>     public Object getOption(int index) {
>         return getOptionObj(index);
>     }
>     public String getLabel(int index) {
>         return getOptionObj(index).getName();
>     }
>     public String getValue(int index) {
>         return getOptionObj(index).getCode();
>     }
>     public Object translateValue(String value) {
>         for (T obj : options) 
>             if (obj.getCode().equals(value))
>                 return obj;
>         return null;
>     }
> }
>
>     private Option getOptionObj(int index) {
>         return (Option) options.get(index);
>     }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>   

-- 
Stéphane Decleire

05 56 57 99 20
06 63 78 69 06