voyent
How to refresh an ice:selectManyListbox  XML
Forum Index -> JBoss Seam Integration
Author Message
telnetproject

Joined: 02/Mar/2012 04:15:03
Messages: 3
Offline


I need to build a pick list, I used two ice:selectManyListbox and two button "left" "right". My problem is, when I pass list item from left to right that I find myself obliged to refresh the page to see the change.
Is that it is possible to see the changes without refreshing the page ?
Help me please.

The pick list code :

Code:
 
 <ice:selectManyListbox size="10" style="width: 150px;"  
 rendered="true" partialSubmit="true" value="#{EventForm.selectedLeftContact}">
 								<s:selectItems value="#{contactLeftList}" 
 									var="contact" label="#{contact.name}" />
 								<s:convertEntity />
 							</ice:selectManyListbox>
 
 							<ice:panelGrid columns="1">
 
 
 								<ice:commandButton value=" > "
 									action="#{EventForm.toRight}" />
 								<ice:commandButton value=" < " action="#{EventForm.toLeft}" />
 
 							</ice:panelGrid>
 
 
 
 
 							<ice:selectManyListbox size="10" style="width: 150px;" 
 								rendered="true" partialSubmit="true"
 								value="#{EventForm.selectedRightContact}">
 								<s:selectItems value="#{EventForm.contactRightList}"
 									var="contact" label="#{contact.name}" />
 								<s:convertEntity />
 							</ice:selectManyListbox>
 
 							<ice:commandButton value=" Sort left column"
 								action="#{EventForm.sortLeft()}" />
 							<ice:panelGroup></ice:panelGroup>
 							<ice:commandButton value=" Sort right column"
 								action="#{EventForm.sortRight()}" />
 
 						</ice:panelGrid>
 
 


The managed bean code :

Code:
 List<Contact> contactLeftList = new  ArrayList<Contact>(); 
 
 	private List<Contact> selectedLeftContact = new  ArrayList<Contact>();  
 
 
 	private List<Contact> selectedRightContact = new  ArrayList<Contact>(); 
 	
 	
 	private List<Contact> contactRightList = new  ArrayList<Contact>(); 
 
 
 
 	
 	@Factory("contactLeftList")
 	public List<Contact> initContactLeftList() { 
 
 		contactLeftList = em
 		.createQuery("select contact from Contact contact")
 		.getResultList();
 		
 		return contactLeftList;
 	} 
 		
 	
 	public void toRight() {
 		
 		Iterator<Contact> selected = selectedLeftContact.iterator();
 		while (selected.hasNext()) {
 
 			Object o;
 			Object item = selected.next();
 
 			Iterator<Contact> iterator = contactLeftList.iterator();
 			while (iterator.hasNext()) {
 				o = iterator.next();
 				if (((Contact) o).equals(item)) {
 					contactLeftList.remove(o);
 					contactRightList.add((Contact) o);
 					break;
 				}
 			}
 		}
 
 		selectedLeftContact = null;
 
 	}
 
 	public void toLeft() {
 
 		Iterator<Contact> selected = selectedRightContact.iterator();
 		while (selected.hasNext()) {
 
 			Object o;
 			Object item =  selected.next();
 
 			Iterator<Contact> iterator = contactRightList.iterator();
 			while (iterator.hasNext()) {
 				o = iterator.next();
 				if (((Contact) o).equals(item)) {
 					contactRightList.remove(o);
 					contactLeftList.add((Contact) o);
 					break;
 				}
 			}
 		}
 
 		selectedRightContact = null;
 
 	}
 
judy.guglielmin

Joined: 20/Feb/2007 00:00:00
Messages: 1396
Offline


Try checking out the <ice:setEventPhase> component in the component-showcase (or seam-comp-showcase) example. It will allow you to update the value you want to reflect the next render within the same jsf lifecycle.
telnetproject

Joined: 02/Mar/2012 04:15:03
Messages: 3
Offline


judy.guglielmin wrote:
Try checking out the <ice:setEventPhase> component in the component-showcase (or seam-comp-showcase) example. It will allow you to update the value you want to reflect the next render within the same jsf lifecycle. 


Thanks Judy for your respose. I solved my problem by using "ItemSelect"
this is the code in my .xhtml :

Code:
 
 <ice:panelGrid columns="3">
 
 	<ice:selectManyListbox style="width: 150px;" size="10"value="#{SelectionBean.selectedItemsLeft}">
              <f:selectItems value="#{itemsLeft}" />
         </ice:selectManyListbox>
 						
 <ice:panelGrid columns="1">
 							
 <ice:commandButton image="img/rightAll.bmp" action="#{SelectionBean.toRightAll()}" />
 <ice:commandButton image="img/right.bmp"
 	action="#{SelectionBean.toRight()}" />
 	<ice:commandButton image="img/left.bmp"
 action="#{SelectionBean.toLeft()}" />
 	<ice:commandButton image="img/leftAll.bmp"
 action="#{SelectionBean.toLeftAll()}" />
 </ice:panelGrid>
 <ice:selectManyListbox style="width: 150px;" size="10"
 value="#{SelectionBean.selectedItemsRight}">
 <f:selectItems value="#{SelectionBean.itemsRight}" />
 			</ice:selectManyListbox>
 
  <ice:commandButton value=" Sort left column" action="#{SelectionBean.sortLeft}"/>
 <ice:panelGroup></ice:panelGroup>
               <ice:commandButton value=" Sort right column" action="#{SelectionBean.sortRight}"/>
 	</ice:panelGrid>
 
 



Code in the managed bean side :

Code:
 
 
 	@PersistenceContext
 	private EntityManager em;
     
     private List<SelectItem> selectedItemsLeft;
     private List<SelectItem>  selectedItemsRight = new ArrayList<SelectItem> ();
     private List<SelectItem>  itemsLeft = new ArrayList<SelectItem>() ;
     private List<SelectItem>  itemsRight = new ArrayList<SelectItem>();
 
     private String value;
 
     public void selectionBean()
     {
     	
   
         // implement your business logic here
         log.info("SelectionBean.selectionBean() action called with: #{SelectionBean.value}");
         statusMessages.add("selectionBean #{SelectionBean.value}");
     }
     
     
     @Factory("itemsLeft")
 	public List<SelectItem> initItemsLeft() {
     	
     	List<Contact> contacts = em
 		.createQuery("select contact from Contact contact")
 		.getResultList();
     	
 
     	
     	for (int i =0;i<contacts.size();i++){
     		SelectItem item  = new SelectItem (contacts.get(i),contacts.get(i).getName());
     		itemsLeft.add(item);
     	}
 
     	
 		return itemsLeft;
 	}
     
     
     public String toRight() {
 
         Iterator selected = selectedItemsLeft.iterator();
         while (selected.hasNext()) {
 
             Object o;
             String item = selected.next().toString();
 
             Iterator<SelectItem>  iterator = itemsLeft.iterator();
             while (iterator.hasNext()) {
                 o = iterator.next();
                 if (((SelectItem) o).getValue().toString().equals(item)) {
                     itemsLeft.remove(o);
                     itemsRight.add((SelectItem) o);
                     break;
                 }
             }
         }
 
         selectedItemsLeft = null;
         return null;
     }
 
     /**
      * Moves the selected item(s) in the right list to the left list.
      * It iterates through the list object that is bound to the value of 
      * the ice:selectManyListbox component removing each item from the right list
      * and adding it to the left list.
      * 
      * @return  null
      */
     public String toLeft() {
 
         Iterator selected = selectedItemsRight.iterator();
         while (selected.hasNext()) {
 
             Object o;
             String item = selected.next().toString();
 
             Iterator<SelectItem>  iterator = itemsRight.iterator();
             while (iterator.hasNext()) {
                 o = iterator.next();
                 if (((SelectItem) o).getValue().toString().equals(item)) {
                     itemsRight.remove(o);
                     itemsLeft.add((SelectItem) o);
                     break;
                 }
             }
         }
 
         selectedItemsRight = null;
         return null;
     }
 
     /**
      * Iterates through all the elements in the left list removing each item
      * from the list and adding it to the right list. 
      * 
      * @return  null
      */
     public String toRightAll() {
 
         Object o;
         int size = itemsLeft.size();
         if (size > 0) {
             for (int i = 0; i < size; i++) {
                 o = itemsLeft.get(0);
                 itemsLeft.remove(o);
                 itemsRight.add((SelectItem) o);
             }
             selectedItemsLeft = null;
         }
 
         return null;
     }
 
     /**
      * Iterates through all the elements in the right list removing each item
      * from the list and adding it to the left list. 
      * 
      * @return  null
      */
     public String toLeftAll() {
 
         Object o;
         int size = itemsRight.size();
         if (size > 0) {
             for (int i = 0; i < size; i++) {
                 o = itemsRight.get(0);
                 itemsRight.remove(o);
                 itemsLeft.add((SelectItem) o);
             }
             selectedItemsRight = null;
         }
 
         return null;
     }
 
 
 
Forum Index -> JBoss Seam Integration
Go to:   
Powered by JForum 2.1.7ice © JForum Team