-
1. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
fazi Oct 25, 2011 1:26 PM (in response to kwutzke)Actually, I discovered that:
<rich:pickList value=
expression should return List/array you want to get on the RIGHT side (selected items)
<f:selectItems value=
expression shall return WHOLE List/array (that is, both selected and unselected items)
This way it works for me.
Hope this helps.
Regards,
Maciek
-
2. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
bleathem Oct 25, 2011 1:32 PM (in response to fazi)fazi has described it correctly Karsten. If you continue to have problems, please post back, and we'll see if we can get to the bottom of it.
-
3. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
kwutzke Oct 27, 2011 7:18 PM (in response to bleathem)Thanks for the tips guys, however it doesn't work.
What does the pickList expect as type? List<SelectItem> or List<AnyEntity>?
Karsten
-
4. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
bleathem Oct 27, 2011 7:23 PM (in response to kwutzke)Karsten,
The generic type of the list bound to the value of the pickList should be the same type used to populate the select items.
Have a look at the pickList sample in the recently publsihed 4.1.0.M3 showcase:
http://showcase1104558964.prod.rhcloud.com/richfaces/component-sample.jsf?demo=pickList
Also, try moving your converter definition out of the attribute, and into a nested <f:converter> tag. (If that is the root cause of your problem, please file a bug! It *should* work the way you did it)
Brian
-
5. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
kwutzke Oct 28, 2011 2:28 AM (in response to bleathem)Hello,
thanks so much for helping. Indeed passing lists of entities works (when the list of pickList value="..." is contained in the selectItems value="..."). And yes the lists need to have the same generic type. That wasn't the case with my original code.
Now that the entities are present, what gets displayed on screen (no columns used) is the result of the toString() method, in my case something rather cryptic/unusable. Note when omitting the converter="..." attribute entirely, the result is exactly the same.
My companyConverter is based upon the following:
It's not an @FacesConverter, but as suggested for any service bean to be injected made an @Named (I'm using CDI, but I could probably use @ManagedBean here, too).
Here's the converter code:
{code}
import javax.enterprise.context.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.inject.Inject;
import javax.inject.Named;
@Named
@RequestScoped
public class CompanyConverter implements Converter
{
@Inject
private CompanyService companyService;
@SuppressWarnings("unused")
@Override
public Object getAsObject(FacesContext arg0, UIComponent arg1, String str)
{
System.out.println("getAsOject!");
return companyService.findCompanyByName(str);
}
@SuppressWarnings("unused")
@Override
public String getAsString(FacesContext arg0, UIComponent arg1, Object obj)
{
System.out.println("getAsString!");
return ((Company)obj).getName();
}
}{code}
When using the converter with the pickList converter="#{companyConverter}" attribute the getAsString! output is printed to the console. But on the GUI it's not the company name that's displayed.
The problem I have now is that I don't know how to specify the above converter using the f:converter tag, given that it only has a converterId attribute...
What do I need to specify in the f:converter tag to get the converter hooked? After all, I need an EJB in the converter...
Many thanks
Karsten
-
6. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
kwutzke Oct 28, 2011 2:33 AM (in response to bleathem)BTW, it would be helpful to also post the code for pickListBean and CapitalsConverter in the new showcase example.
Karsten
-
7. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
bleathem Oct 28, 2011 11:27 AM (in response to kwutzke)Hi Karsten,
Good idea! In the mean time, you can view them on gihub:
Brian
-
8. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
kwutzke Oct 28, 2011 1:18 PM (in response to bleathem)OK, thanks.
What's with the converter attribute issue? Can you have a look please?
Karsten
-
9. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
bleathem Oct 28, 2011 1:33 PM (in response to kwutzke)Hmm, I've never tried it without a FacesConverter - I don't think it'll work. Try making it a FacesConverter, and since you are already using CDI, try using Seam Faces to allow Injection into FacesConverters.
Brian
-
10. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
sknabil Jun 12, 2012 2:12 AM (in response to kwutzke)Hi,
I faced similar type of problem while showing an object in picklist. Selected object list doesn't appear on the target/right side list. I tried according to the showcase example. Finally i solved the problem by overriding the hashCode and equals method in Capital.java class like following:
@Override public int hashCode() { return (this.name.hashCode()*this.state.hashCode()); } @Override public boolean equals(Object obj) { if (this == obj) return true; else if(obj == null || obj.getClass()!= this.getClass()) return false; Capital capital = (Capital) obj; return this.name.equals(capital.getName()) && this.state.equals(capital.getState()); }
Now the selected list is appearing on the target list and picklist is working exactly as it was expected.
Regards,
Nabil -
11. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
ahsan4her Jun 12, 2012 2:30 AM (in response to sknabil)Nice finding! Seems we were missing very basic thing of POJO.
Thanks.
-
12. Re: RF 4 rich:pickList: how to prepopulate the target/right side?
ealonso04 Jul 9, 2012 3:33 PM (in response to kwutzke)Hi guys!
Right now Im testing this component, I'm new to richfaces. So when I send to print the size of both lists source and target, I'm getting the same number of items, no matter if I have been adding and removing items from one list to another one.
Let's say the source list started with 3 items and the target list started with 2 items, this last two items taken from the source list, thus, the source list only shows one item, the missing item. But if I add that missing item to the target list and print both lists size it prints the original sizes: 3 and 2.
I don't understand why I'm getting that. How can I get both lists updated after I was adding and removing items?
I will appreciate any help. Thanks!