aspose file tools*
The moose likes JSF and the fly likes Preselection on Pick List? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Preselection on Pick List?" Watch "Preselection on Pick List?" New topic
Author

Preselection on Pick List?

Knolf Moervenson
Greenhorn

Joined: Jul 25, 2008
Posts: 12
Hi!
I have a problem using Pick List. Is it possible to preload the result list and display it on the Pick List as a preselection? If so, could anybody please post an example? Pre-Filling the result list in the backing bean had no effect.
Thanks a lot for any help!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

http://www.coderanch.com/t/414506/JSF/java/set-default-selection-selectOneMenu


Customer surveys are for companies who didn't pay proper attention to begin with.
Knolf Moervenson
Greenhorn

Joined: Jul 25, 2008
Posts: 12
Hi Tim!
Thanks for quick help. I already discovered the post about SelectOneMenu (SOM), but using picklist differs from SOM.
Now, there are two lists for the rich:picklist, the selection (typed <SelectItem>) and the resultlist (typed <String>). Filling the result list with databse info on initializing the picklist seem to have no effect, the preselection is not shown!?!?

Knolf Moervenson
Greenhorn

Joined: Jul 25, 2008
Posts: 12
Now it works. It was just a problem with the binding-method. Using "value" instead helped.
Thanks
Pedro Baptista
Greenhorn

Joined: Aug 22, 2008
Posts: 1
Hi, i'm having the same problem and i can't solve it could you send your resolution?

thanks
Knolf Moervenson
Greenhorn

Joined: Jul 25, 2008
Posts: 12
Sorry Pedro, once there was a time I managed to preload the PickList but with that solution came another problem. So I am still getting more and more frustrated by using that PickListNightmare.. I will post a solution if there is one. Even if all the lists are filled with correct values, the result list is still not shown (empty) and I can not find a solution for that weird problem. Maybe it is a matter of inconsistency with the lists, but if so, what are the richfaces rules for using those lists dynamically?
Knolf Moervenson
Greenhorn

Joined: Jul 25, 2008
Posts: 12
Ok, problem is solved now!!!
The trick is to fill the selectItemList with ALL possible data including the matches for the result list. The framework first renders the result list and removes those matches from the SelectItemList automatically, but only if there is that object to match! So fill your SelectItemList with all possible matches and use a converter for switching from SelectItems and Strings (the pick lists) to the objects.

Hope this will help you. If not, just write a line and I will post my code here..



btw: sorry for bad english, it is not my native language.. ;-)
anandram venkataswamy
Greenhorn

Joined: Oct 03, 2007
Posts: 9
Dear Knolf Moervenson ,

Ok, problem is solved now!!!
The trick is to fill the selectItemList with ALL possible data including the matches for the result list. The framework first renders the result list and removes those matches from the SelectItemList automatically, but only if there is that object to match! So fill your SelectItemList with all possible matches and use a converter for switching from SelectItems and Strings (the pick lists) to the objects.

Hope this will help you. If not, just write a line and I will post my code here..


Can you please post me an example for the above explanation.

Thankyou in advance.

with warm regards,
Anandram.V
anandramv@gmail.com
Knolf Moervenson
Greenhorn

Joined: Jul 25, 2008
Posts: 12
so here's an example code for preloading the result list for a pickList:


in your.jsp:


added for editing selected Items directly in data table below the picklist:


in your backing bean:



And the converter:



Hope it'll help..
Notice: If your left list is filled by an other database-entity than the result list you should use an own wrapper class for collecting all attributs to one class. Then: In the converter change the type from Your_Database_Object to Your_Wrapper_Object and also adjust the type of the result list in the backingBean to that wrapper class. Be careful with the Getter of the leftPickList, it may cause problems without exceptions if you use the new-operator for your wrapper class in the Getter-method. All wrapper-objects may be correct, but the memory-adress changes with the new-operator. So store a complete list of all wrapper objects in the bean when preloading. The lower part of the getter should look like this:


[ August 29, 2008: Message edited by: Knolf Moervenson ]
shweta ambulkar
Greenhorn

Joined: Jan 08, 2009
Posts: 1
Hi Knolf ,

I tried the picklist example given by you.

The requirement i have is as below- My picklist contains list of available favorites in the left list and some preselected favorites in the right list which will be populated from the user preferences table .I should be able to edit the favorites..i.e. add /remove items into the result list which should be saved on form submit.

My problem is that though it is displaying the preselected list in the right and the available selection list in the left list, when i submit the form by clicking on save it gives the following error


javax.faces.component.UISelectItems.getValue(UISelectItems.java:144)
javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:147)
javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:60)
javax.faces.component.UISelectMany.matchValue(UISelectMany.java:497)
javax.faces.component.UISelectMany.validateValue(UISelectMany.java:466)
javax.faces.component.UIInput.validate(UIInput.java:875)
javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
javax.faces.component.UIInput.processValidators(UIInput.java:672)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1046)
javax.faces.component.UIForm.processValidators(UIForm.java:235)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1046)
javax.faces.component.UIInput.processValidators(UIInput.java:670)
org.ajax4jsf.component.AjaxViewRoot$3.invokeContextCallback(AjaxViewRoot.java:439)
org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:455)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:177)
org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:380)


and this happend only when i move any item in the left list to right list and then select save. it does not even go to the save method in the backing bean which has to be invoked thru' action .When i don't select anything and then click save or when i move the item from right list to left and then select save, i don't get any error and i am able to print the values in the list.Please can you suggest what can be the possible cause for this? If reqd i can post the code also.

Thanks in advance.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
shweta ambulkar wrote:it gives the following error
You forgot to post the first line which tells us about the exception type and exception message. The stacktrace is fairly worthless without that information.

If there are any "root cause" or "caused by" parts at the end of the stacktrace, you should post that as well.
monalisa smile
Greenhorn

Joined: Apr 25, 2009
Posts: 1
to Knolf Moervenson :
can you more explain this code, i have a problem with pickList (explain :getAvailableSelectionListFromDatabase() and getPreselectionListFromDB())

thank you.
Marcos Muniz
Greenhorn

Joined: Oct 27, 2009
Posts: 1
I have the same problem that shweta ambulkar is having

Caused by: java.lang.IllegalArgumentException: could not set field value: yourBean. leftPickList
at org.jboss.seam.Component.setFieldValue(Component.java:1927)
at org.jboss.seam.Component.access$600(Component.java:126)
at org.jboss.seam.Component$BijectedField.set(Component.java:2940)
at org.jboss.seam.Component.injectAttributes(Component.java:1736)
at org.jboss.seam.Component.inject(Component.java:1554)
at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:61)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.ConversationInterceptor.aroundInvoke(ConversationInterceptor.java:65)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:280)
at org.jboss.el.parser.AstMethodSuffix.getValue(AstMethodSuffix.java:59)
at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)

I tried to debug the code and my list of objects are of the Type Object instead of List, that is the problem
s burgula
Greenhorn

Joined: Oct 27, 2009
Posts: 3
Could you describe the methods getPreSelectionListfromDB() and getAvailableSelectionListfromDB() methods. The code you posted does really help. Kindly do add these methods as well. Looking forward to hearing from you soon.

thanks
Sai
s burgula
Greenhorn

Joined: Oct 27, 2009
Posts: 3
Could you please also add the method updateSelection()

thanks
Sai
s burgula
Greenhorn

Joined: Oct 27, 2009
Posts: 3
I able to display the picklist by putting in the same code as you have displayed, but it displays the default list on the right side instead of the left side of the list.
Deeps Prav
Greenhorn

Joined: Mar 16, 2010
Posts: 9
hi Knolf ,
Can I use the converter method in seam also.Because I have tried using the converter method.But it is saying that converter not found?Can this be because I am using it in seam?Please help.
Thanks,
Deeps.
 
 
subject: Preselection on Pick List?