You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by pokkie <po...@gmail.com> on 2006/05/31 14:01:25 UTC

SelectManyPicklist component , can't set selected values

Hello all,

For some reason, when my page loads up, the selected items (righthand select
box), doesn't seem to be displayed for some reason. 

JSP Code :

   <s:selectManyPicklist
            size="10" valueChangeListener="#{agentBean.selectionChanged}"
            value="#{agentBean.stringValues}" id="agentSelectManyPickList">

           <f:selectItems
                   value="#{agentBean.selectItemValues}"
id="agentSelectItem"/>

    </s:selectManyPicklist>

Java Code :

    List<SelectItem> selectItemValues = new ArrayList();
    String[] stringValues = new String[10];

    public void setSelectItemValues(List<SelectItem> selectItemValues) {
        this.selectItemValues = selectItemValues;
    }

    public List<SelectItem> getSelectItemValues() {
        selectItemValues.clear();
        selectItemValues.add(new SelectItem("New York"));
        selectItemValues.add(new SelectItem("Chicago"));
        selectItemValues.add(new SelectItem("Seattle"));
        selectItemValues.add(new SelectItem("Miami"));
        return selectItemValues;
    }

    public void setStringValues(String[] stringValues) {
        this.stringValues = stringValues;
    }

    public String[] getStringValues() {
        stringValues[0]= "Bob";
        stringValues[1]= "John";
        stringValues[2]= "Peter";
        stringValues[3]= "Simon";
        return stringValues;
    }

I have tried using 1.1.3 and 1.1.4 SNAPSHOTS from the maven repository but
haven't had any luck. 

Any help would be greatly appreciated. 

-- Pokkie
--
View this message in context: http://www.nabble.com/SelectManyPicklist+component+%2C+can%27t+set+selected+values-t1710201.html#a4643071
Sent from the MyFaces - Users forum at Nabble.com.


Re: SelectManyPicklist component , can't set selected values

Posted by octoberdan <da...@october5th.net>.
This is how I'm getting two lists syncing:

<h:outputText value="Assignees: "/>
<s:selectManyPicklist id="assignees" value="#{projectSaver.assignees}"
size="5">
    <f:selectItems value="#{projectSaver.workerItems}"/>
 </s:selectManyPicklist>
 <t:message for="assignees"/>


        private List<Integer> assignees;
        private List<SelectItem> workerItems;

	public Integer[] getAssignees() {
		
		if (null == assignees) {
			assignees = new ArrayList<Integer>();
			
			//fill it...
		}

		return (Integer[]) assignees.toArray(new Integer[assignees.size()]);
	}

	public List<SelectItem> getWorkerItems() {
		if (null == workerItems) {
			workerItems = new ArrayList<SelectItem>();
			
			//fill it full of items that have an Integer for a value
		}
		
		return workerItems;
	}

I think you can safely swap between Integer, String, Dog, etc... just as
long as the value types match.

--
View this message in context: http://www.nabble.com/SelectManyPicklist+component+%2C+can%27t+set+selected+values-t1710201.html#a4643827
Sent from the MyFaces - Users forum at Nabble.com.