• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Preselection on Pick List?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://coderanch.com/t/414506/JSF/java/set-default-selection-selectOneMenu
 
Knolf Moervenson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now it works. It was just a problem with the binding-method. Using "value" instead helped.
Thanks
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'm having the same problem and i can't solve it could you send your resolution?

thanks
 
Knolf Moervenson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.. ;-)
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to Knolf Moervenson :
can you more explain this code, i have a problem with pickList (explain :getAvailableSelectionListFromDatabase() and getPreselectionListFromDB())

thank you.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please also add the method updateSelection()

thanks
Sai
 
s burgula
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic