Problems with TriStateSelectManyCheckboc

Community Driven Extensions Project
Post Reply
beer
Posts: 8
Joined: 15 Nov 2011, 15:40

06 Jul 2012, 11:12

Hi All,

I'm currently trying to get the TriStateSelectManyCheckbox to work and I used the converter example as an information source.
So instead the State object within the Map I have my own TestObject in the Map as value. It implements Serializable and has a toString() method and it is a POJO.
I also implemented a converter for the TestObject class.

The big difference to the example is, that I do not put provide String values as f:selectItems but a List of TestObjects:

Code: Select all

<f:selectItems value="#{facetController.availableEntries}" var="entry" itemDescription="#{entry.description}" itemLabel="#{entry.label}" itemValue="#{entry}" />
And I think this is the problem which rises the following error:

Code: Select all

java.lang.ClassCastException: de.l3s.dlg.bi2son.view.controller.TestObject cannot be cast to java.lang.String
	at org.primefaces.extensions.component.tristatemanycheckbox.TriStateManyCheckboxRenderer.encodeOption(TriStateManyCheckboxRenderer.java:169)
Which will lead me to a code line which makes a hard String cast:

Code: Select all

String itemValue = (String) option.getValue();

So am I right, that this is my problem? And is there any possibility not having simple String values as f:selectItems?

Bests,
Beer
Eclipse Indigo | Tomcat 7.0.22 | Hibernate | Primefaces 3.0M4

User avatar
Oleg
Expert Member
Posts: 3803
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

06 Jul 2012, 11:25

And is there any possibility not having simple String values as f:selectItems
Not sure. I normally use array of SelectItem instances for f:selectItems. E.g. in case of p:selectOneRadio (pe:triState... should be same):

Java.

Code: Select all

private List<SelectItem> changeSecretItems;
private int changeSecret = 0;

public List<SelectItem> getChangeSecretItems() {
    if (changeSecretItems == null) {
        changeSecretItems = new ArrayList<SelectItem>();
            
        changeSecretItems.add(new SelectItem("-1", "Initial Change Secret"));
        changeSecretItems.add(new SelectItem("0", "Don't Change Secret"));
        changeSecretItems.add(new SelectItem("1", "Change Secret"));
    }
        
    return changeSecretItems;
}
XHTML.

Code: Select all

<p:selectOneRadio value="#{bean.changeSecret}">
    <f:selectItems value="#{bean.changeSecretItems}"/>
</p:selectOneRadio>
have you tried p:selectManyCheckbox? Does it work with your approach?
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

beer
Posts: 8
Joined: 15 Nov 2011, 15:40

06 Jul 2012, 11:44

Oleg wrote: have you tried p:selectManyCheckbox? Does it work with your approach?
Yes I just did and I get the "same" error but from the SelectManyCheckboxRenderer...
So you think if I "cast" my object somehow into a SelectItem it will work? So I will try this approach.... But would it not be nice haveing the possibility to add any object there? Just by implementing an interface for example?
Eclipse Indigo | Tomcat 7.0.22 | Hibernate | Primefaces 3.0M4

User avatar
Oleg
Expert Member
Posts: 3803
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

06 Jul 2012, 12:08

So you think if I "cast" my object somehow into a SelectItem it will work?
This is an JSF question and not a PrimeFaces' one. You can use any Object as value in SelectItem and only String as label. If you use some object as value you need your own JSF converter to convert object to string and visa versa. Please look how to write JSF converters.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

beer
Posts: 8
Joined: 15 Nov 2011, 15:40

09 Jul 2012, 09:58

Hi,

so I checked again everything and now I am pretty sure that there is a "bug" in the TriStateSelectMany Renderer...
When I use a h:selectManyCheckbox everything works fine... If I change to pe:triStateManyCheckbox I still get this strange exception form the Renderer...

So what I have:

Code: Select all

				<pe:triStateManyCheckbox id="checkbox_year"
					value="#{facetService.selectedEntries}"
					converter="triStateFacetConverter" layout="pageDirection"
					stateOneIcon="${unselectedIcon}" stateTwoIcon="${includeIcon}"
					stateThreeIcon="${excludeIcon}">
					<f:converter converterId="testConverter" />
					<f:selectItems value="#{facetService.availableEntries}" var="entry" itemLabel="#{entry.label}" itemValue="#{entry}"/>
				</pe:triStateManyCheckbox>
The problem seems, that the f:convetrer is not called when using a triStateManyCheckbox, because I always get the error:

Code: Select all

java.lang.ClassCastException: de.l3s.dlg.bi2son.view.facet.StringBasedFacetEntry cannot be cast to java.lang.String
	at org.primefaces.extensions.component.tristatemanycheckbox.TriStateManyCheckboxRenderer.encodeOption(TriStateManyCheckboxRenderer.java:169)
	at org.primefaces.extensions.component.tristatemanycheckbox.TriStateManyCheckboxRenderer.encodeSelectItems(TriStateManyCheckboxRenderer.java:153)
	at org.primefaces.extensions.component.tristatemanycheckbox.TriStateManyCheckboxRenderer.encodeMarkup(TriStateManyCheckboxRenderer.java:121)
	at org.primefaces.extensions.component.tristatemanycheckbox.TriStateManyCheckboxRenderer.encodeEnd(TriStateManyCheckboxRenderer.java:103)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
And this can only be, because the converter is not called! As I said, when I change it to h:selectManyCheckbox the converter is called and the "entry" is converted to a string and no exception at all.

Any ideas?!
Eclipse Indigo | Tomcat 7.0.22 | Hibernate | Primefaces 3.0M4

User avatar
Oleg
Expert Member
Posts: 3803
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

09 Jul 2012, 10:09

Please create an issue in our issue tracker. http://code.google.com/p/primefaces-ext ... ssues/list and put a link to this post. Maybe we forgot something or didn't synchronize the code with PF.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

Post Reply

Return to “Extensions”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest