Foren

Boolean preferences

J S, geändert vor 12 Jahren.

Boolean preferences

Junior Member Beiträge: 31 Beitrittsdatum: 11.04.12 Neueste Beiträge
Hi,

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

		<portlet-preferences>
			<preference>
				<name>isItOn</name>
				<value>true</value>
			</preference>
		</portlet-preferences>


In my edit xhtml I have :

        <h:form>
            <f:ajax render="@form" execute="@form">
                <h:selectbooleancheckbox id="isItOn" value="#{mutablePortletPreferencesValues['isItOn'].value}">
                    <f:converter for="isItOn" converterId="javax.faces.Boolean" />
                </h:selectbooleancheckbox>
                <h:outputlabel for="isItOn" value="Is it On?" />
                <br>
                <h:commandbutton actionListener="#{portletTestBean.savePrefs}" value="Submit" />
            </f:ajax>
        </h:form>


but when I select the checkbox I get this exception:

Caused 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'.
	at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:139)
	at javax.faces.component.UIInput.updateModel(UIInput.java:818)
	... 145 more
Caused 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
thumbnail
Neil Griffin, geändert vor 12 Jahren.

RE: Boolean preferences

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Boolean preferences

Junior Member Beiträge: 31 Beitrittsdatum: 11.04.12 Neueste Beiträge
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.

	public boolean isIsItOn() {
		Map<string, preference> mutablePreferenceMap = getPrefMap();
		return Boolean.parseBoolean(mutablePreferenceMap.get("isItOn").getValue());
	}

	public void setIsItOn(boolean isItOn) {
		try {
			Map<string, preference> mutablePreferenceMap = getPrefMap();
			Preference isItOnPref = mutablePreferenceMap.get("isItOn");
			isItOnPref.setValue(Boolean.toString(isItOn));
		} catch (ReadOnlyException e) {
			throw new FacesException(e);
		}
	}

	private Map<string, preference> getPrefMap() {
		FacesContext facesContext = FacesContext.getCurrentInstance();
		ELResolver elResolver = facesContext.getApplication().getELResolver();
		@SuppressWarnings("unchecked")
		Map<string, preference> mutablePreferenceMap = (Map<string, preference>) elResolver.getValue(facesContext.getELContext(), null,
				"mutablePortletPreferencesValues");
		return mutablePreferenceMap;
	}
</string,></string,></string,></string,></string,>


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
thumbnail
Neil Griffin, geändert vor 12 Jahren.

RE: Boolean preferences

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
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?