Hi Volker, thanks for responding to my posting. Books
do not talk about UISelectMany much. And I was unable
to find much information about it on the internet.
Yes, exactly. I am trying to provide a UISelectMany
and render it as a list box in the browser.
Thank you for the example provided. I am going to
follow and test the example when I go to office
tomorrow morning.
Meanwhile, would you mind advising:
1. How do I deliver each element of the Object[]
selectedItems into this method:
public void clear(ActionEvent e)
{
FacesContext facesContext =
FacesContext.getCurrentInstance();
UIViewRoot uiViewRoot =
facesContext.getViewRoot();
// Here, I want to iterating through the Object[]
if (selectedItems[i] instanceof
EditableValueHolder)
{
EditableValueHolder evh = (EditableValueHolder)
selectedItems[i];
evh.setSubmittedValue(null);
}
}
The code snippet above is a draft. I am uncertain if
I am doing it right.
2. The multiple selections made by user are in an
Object array (i.e. Object[] selectedItems). How do I
retrieve the values from this Object array (I think
that the values retrieved will be a String[] if I am
not terribly wrong.) to be sent to the database?
Regards,
Caroline
--- Volker Weber <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> i'm a bit confused about what you want to do.
>
> Lets clear up by consructing an example:
>
> If i understand you correct you want your
> application to provide a
> component (UISelectMany) which is rendered as a
> listbox
> (<select size=5 ...> <option ... >label</option>+
> </select>).
>
> The items should created by application and put into
> the component.
>
>
> The Bean class:
>
===============================================================================
> package org.apache.myfaces.examples;
>
> import javax.faces.component.UISelectMany;
> import javax.faces.component.UISelectItems;
> import javax.faces.model.SelectItem;
> import java.util.List;
> import java.util.ArrayList;
>
> public class TestBean {
>
> private UISelectMany selectMany;
>
> private Object[] selectedItems;
>
> public TestBean() {
> selectMany = new UISelectMany();
> selectMany.setId("selectMany");
>
> UISelectItems items = new UISelectItems();
> items.setId("selectManyItems");
> items.setValue(createSelectItems());
>
> selectMany.getChildren().add(items);
> }
>
> private Object createSelectItems() {
> List items = new ArrayList();
> for (int i = 0; i < 10; i++){
> items.add(new SelectItem("item" + i, "Item No.
> " + i));
> }
> return items;
> }
>
> public UISelectMany getSelectMany() {
> return selectMany;
> }
>
> public void setSelectMany(UISelectMany selectMany)
> {
> this.selectMany = selectMany;
> }
>
> public Object[] getSelectedItems() {
> return selectedItems;
> }
>
> public void setSelectedItems(Object[]
> selectedItems) {
> this.selectedItems = selectedItems;
> }
> }
>
===============================================================================
>
> and the jsp page:
>
===============================================================================
> <%@ page
> import="org.apache.myfaces.examples.TestBean"%>
> <%@ taglib uri="http://java.sun.com/jsf/html"
> prefix="h"%>
> <%@ taglib uri="http://java.sun.com/jsf/core"
> prefix="f"%>
>
> <%
> Object testbean = pageContext.getAttribute(
> "TestBean", PageContext.SESSION_SCOPE);
> if (testbean == null) {
> pageContext.setAttribute(
> "TestBean", new TestBean(),
> PageContext.SESSION_SCOPE);
> }
> %>
>
> <html>
> <body>
> <f:view>
> <h:form>
>
> <h:selectManyListbox id="selectMany"
> binding="#{TestBean.selectMany}"
> value="#{TestBean.selectedItems}" />
>
> <h:commandButton value="Submit"/>
>
> </h:form>
> </f:view>
> </body>
> </html>
>
===============================================================================
>
>
> If this is what you want to do, it should be easy to
> adapt it to your needs.
>
> If not you shoud explain a bit clearer what you
> want.
>
> Regards
>
> Volker Weber
>
> Caroline Jen wrote:
> > I understand what you are talking about. I
> created
> > select one and select many long time ago without
> any
> > problem.
> >
> > I think the conclusion is that it is NOT POSSIBLE
> to
> > supply a UISelectMany to render a list box. Is it
> > correct?
> >
>
> --
> Don't answer to From: address!
> Mail to this account are droped if not recieved via
> mailinglist.
> To contact me direct create the mail address by
> concatenating my forename to my senders domain.
>
>
__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/