Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
J S
Boolean preferences
April 19, 2012 8:16 AM
Answer

J S

Rank: Junior Member

Posts: 31

Join Date: April 11, 2012

Recent Posts

Hi,

I'm trying to use a boolean value as a preference. In portlet.xml I have

1        <portlet-preferences>
2            <preference>
3                <name>isItOn</name>
4                <value>true</value>
5            </preference>
6        </portlet-preferences>


In my edit xhtml I have :

 1        <h:form>
 2            <f:ajax render="@form" execute="@form">
 3                <h:selectBooleanCheckbox id="isItOn" value="#{mutablePortletPreferencesValues['isItOn'].value}">
 4                    <f:converter for="isItOn" converterId="javax.faces.Boolean"/>
 5                </h:selectBooleanCheckbox>
 6                <h:outputLabel for="isItOn" value="Is it On?" />
 7                <br/>
 8                <h:commandButton actionListener="#{portletTestBean.savePrefs}" value="Submit" />
 9            </f:ajax>
10        </h:form>


but when I select the checkbox I get this exception:

1Caused by: javax.el.ELException: /views/testPortlet/options.xhtml @18,113 value="#{mutablePortletPreferencesValues['isItOn'].value}": Can't set property 'value' on class 'com.liferay.faces.bridge.preference.PreferenceImpl' to value 'true'.
2    at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:139)
3    at javax.faces.component.UIInput.updateModel(UIInput.java:818)
4    ... 145 more
5Caused by: java.lang.IllegalArgumentException: argument type mismatch


In the debugger I can see it trying to set a Boolean rather than a string value. It doesn't seem to invoke the converter when it is setting values, only when the page is being rendered.

Any ideas? I've only found preferences examples that use h:inputText.

I am using 3.0.0-BETA1 and liferay 6.1

Thanks

John
Neil Griffin
RE: Boolean preferences
April 19, 2012 8:26 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2041

Join Date: July 26, 2005

Recent Posts

I ran into something similar the other day with FACES-1179 but I didn't have time to stop and figure out the cause. I should be able to revisit again soon -- perhaps later today or tomorrow. For now, I would ask that you try your portlet in Liferay 6.0.6 (Tomcat 6) and see if the problem goes away.
J S
RE: Boolean preferences
April 19, 2012 9:12 AM
Answer

J S

Rank: Junior Member

Posts: 31

Join Date: April 11, 2012

Recent Posts

I've dug into it a bit more and I think it's an issue with h:selectBooleanCheckbox . It will only accept a Boolean value. I've worked around it by having a getter/setter in a backing bean that get/sets the value in the mutablePreferenceMap i.e.

 1    public boolean isIsItOn() {
 2        Map<String, Preference> mutablePreferenceMap = getPrefMap();
 3        return Boolean.parseBoolean(mutablePreferenceMap.get("isItOn").getValue());
 4    }
 5
 6    public void setIsItOn(boolean isItOn) {
 7        try {
 8            Map<String, Preference> mutablePreferenceMap = getPrefMap();
 9            Preference isItOnPref = mutablePreferenceMap.get("isItOn");
10            isItOnPref.setValue(Boolean.toString(isItOn));
11        } catch (ReadOnlyException e) {
12            throw new FacesException(e);
13        }
14    }
15
16    private Map<String, Preference> getPrefMap() {
17        FacesContext facesContext = FacesContext.getCurrentInstance();
18        ELResolver elResolver = facesContext.getApplication().getELResolver();
19        @SuppressWarnings("unchecked")
20        Map<String, Preference> mutablePreferenceMap = (Map<String, Preference>) elResolver.getValue(facesContext.getELContext(), null,
21                "mutablePortletPreferencesValues");
22        return mutablePreferenceMap;
23    }


It would be nice not to have to do that though, but I think that's a core JSF issue and not a Liferay issue.

John
Neil Griffin
RE: Boolean preferences
April 19, 2012 9:29 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2041

Join Date: July 26, 2005

Recent Posts

Makes sense -- glad you found a workaround. Was the problem in javax.faces.component.html.HtmlSelectBooleanCheckbox or javax.faces.component.UISelectBoolean or perhaps somewhere else?