You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Caroline Jen <ji...@yahoo.com> on 2005/10/13 20:30:45 UTC
Re: UISelectMany (Problem Resolved). Mr. Weber, Regarding Cleaning Multiple Selections
Hi Volker,
Thanks a lot. I have an answer to the question
that I posted earlier.
In the submit() method that is invoked by an
action, I nullify the selectedItems after the
StringBuffer is created. This way, the multiple
selections that were made previously will not show up
(not be highlighted) on the screen when I re-run the
application.
Thanks again. Have a nice day.
Warm Regards,
Caroline
--- Caroline Jen <ji...@yahoo.com> wrote:
> Hi Volker,
>
> I asked a wrong question in my previous post.
> Sorry.
>
> Your code works fine. It cleans the multiple
> selections "internally".
>
> I observe a problem:
>
> After a user submits his/her multiple selections,
> which is an action (instead of an action listener),
> I
> display the files that he/she has selected. Then, I
> close the browser.
>
> While the server is still running, I run the
> same
> application again. And I see the previously
> selected
> items are highlighted in the list box on my screen.
>
> What should I do to resolve this problem? I
> mean
> how to erase the selections visually after the
> 'action' takes place? See
>
> <h:commandButton value="View Data Files ..."
> type="submit" style="width: 180px"
>
action="#{fileManagementBean.displaySelectedFiles}"/>
>
> The "type' attribute in the commandButton has to
> have
> a value "submit".
>
> The cleaning multiple selections is easier.
> the
> command button that has an action listener to invoke
> the clear( ActionEvent e ) method can have a 'type'
> attibute with its value being "reset" to clean the
> previous selections visually.
>
> --Caroline
>
> --- Volker Weber <us...@weber-oldenburg.de>
> wrote:
>
> > Hi Caroline,
> >
> >
> >
> > Caroline Jen wrote:
> > ...
> > > Meanwhile, would you mind advising:
> > >
> >
> > You want to clear the selected Items?
> >
> > just clear or null the field in the bean.
> > public void clear(ActionEvent e)
> > {
> > FacesContext facesContext =
> > FacesContext.getCurrentInstance();
> > ValueBinding vb =
> > e.getComponent().getValueBinding();
> > if (vb != null) {
> > vb.setValue(facesContext, null);
> > }
> > }
> >
> >
> >
> > > 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)
> > > {
> >
> > this can never happen, selectedItems[i] is not an
> > instance of
> > EditableValueHolder !
> > selectedItems[i] is the first argument of
> SelectItem
> > constructor:
> > String in my example.
> >
> > > EditableValueHolder evh =
> > (EditableValueHolder)
> > > selectedItems[i];
> > > evh.setSubmittedValue(null);
> >
> > This has no effect in application phase.
> > just setting a variable to null and throwing away
> > afterwards.
> >
> > > }
> > > }
> > >
> > > 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
> >
> > Just fetch them from your bean or via ValueBinding
> > from your Component.
> >
> > > that the values retrieved will be a String[] if
> I
> > am
> > > not terribly wrong.) to be sent to the database?
> >
> > The type is the array type of the objects used to
> > create the
> > selectItems, in my example Strings.
> >
> > I attached updated TestBean.java and test.jsp with
> > examples.
> >
> > Regards
> > Volker Weber
> > --
> > 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.
> > > package org.apache.myfaces.examples;
> >
> > import javax.faces.component.UISelectMany;
> > import javax.faces.component.UISelectItems;
> > import javax.faces.model.SelectItem;
> > import javax.faces.event.ActionEvent;
> > import javax.faces.context.FacesContext;
> > import javax.faces.el.ValueBinding;
> > 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) {
>
=== message truncated ===
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com