You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by laredotornado <la...@gmail.com> on 2009/10/01 17:19:16 UTC
Trouble converting String to boolean in JSF
Hi,
I'm using MyFaces 1.1 for a web app deployed in Resin 3.0.19. This is the
expression I have ...
<h:selectBooleanCheckbox value="#{emailController.fields.addToENews ==
'true'}" />
but when I submit my page containing this, I get the error
Parsed Expression of unsupported type for this operation. Expression class:
org.apache.commons.el.BinaryOperatorExpression. Expression:
'#{emailController.fields.addToENews == 'true'}'
Any ideas how I can rewrite the expression to produce the desired result?
Essentially I'm trying to convert a string to a boolean within JSF.
Thanks, - Dave
--
View this message in context: http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25696928.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Trouble converting String to boolean in JSF
Posted by Mike Kienenberger <mk...@gmail.com>.
First off, booleanConverter is already defined in the standard
faces-config.xml file, so you don't need to define it again.
The problem is that <h:selectBooleanCheckbox> expects the getter to
return a boolean already, not a String.
I know I hit this problem years ago in the past, but I don't remember
how I solved it.
But one creative alternative might be this, assuming that this is a
display-only control, not something that will allow the value to be
changed:
<h:selectBooleanCheckbox
rendered="#{emailController.fields.addToENews=='true'}"
value="#{true}"/>
<h:selectBooleanCheckbox rendered="#{emailController.fields.addToENews!='true'}"
value="#{false}"/>
I don't know if that will work any better, though.
The easiest, but probably not the cleanest, solution is to create
public boolean getAddToENewsAsBoolean()
{
String x = this.addToENews());
if (x ....) return true;
else return false;
}
Then
<h:selectBooleanCheckbox value="#{emailController.fields.addToENewsAsBoolean}"/>
You might also take a look at the sandbox:convertBoolean tag.
http://wiki.apache.org/myfaces/ConvertBoolean
The problem is that an html checkbox is an input that doesn't take a
standard value=true/false. Instead, it takes a checked=checked value
if true or nothing if false. So I'm not certain what a converter
would have to return to feed it values.
Normally a converter takes arbitrary java data and converts it to a
String representation that is used by the html value attribute, then
reverses that transformation to submit the value back to the
application. You'd probably have to look at the
<h:selectBooleanCheckbox> source to see what it does and if there's a
way to provide a non-boolean input to it.
Maybe a facelets function to convert your strings into booleans could
help, but again, that's probably a read-only value provider, and you'd
get the same error you had in the first place.
On Thu, Oct 1, 2009 at 5:30 PM, laredotornado <la...@gmail.com> wrote:
>
> I see that myfaces includes a BooleanConverter, but when I add this to my
> faces-config.xml file ...
>
> <converter>
> <converter-id>booleanConverter</converter-id>
> <converter-class>javax.faces.convert.BooleanConverter</converter-class>
> </converter>
>
> and my selectBooleanCheckbox element is
>
> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews}"
> converter="booleanConverter" />
>
> but I'm still getting this error upon visiting my page
> (emailController.fields.addToENews returns a string) ...
>
> java.lang.IllegalArgumentException: Expected submitted value of type Boolean
> for Component : {Component-Path : [Class:
> javax.faces.component.UIViewRoot,ViewId:
> /contactInfo.jsp][Class: javax.faces.component.html.HtmlForm,Id:
> contactInfo][Class:
> javax.faces.component.html.HtmlSelectBooleanCheckbox,Id: _idJsp1]}
> at
> org.apache.myfaces.shared_impl.renderkit.RendererUtils.getBooleanValue(RendererUtils.java:157)
> at
> org.apache.myfaces.shared_impl.renderkit.html.HtmlCheckboxRendererBase.encodeEnd(HtmlCheckboxRendererBase.java:62)
> at
> javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
> at javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:498)
> at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:366)
> at _jsp._contactInfo__jsp._jspService(contactInfo.jsp:106)
> at com.caucho.jsp.JavaPage.service(JavaPage.java:60)
> at com.caucho.jsp.Page.pageservice(Page.java:579)
> at
> com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:175)
> at
> com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:115)
> at
> com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
> at
> com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:277)
> at
> com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:106)
> at
> org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
> at
> org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
> at
> org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
> at
> org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
> at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
> at
> com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
> at
> org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
> at
> com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:70)
> at
> com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
> at
> com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
> at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
> at com.caucho.server.port.TcpConnection.run(TcpConnection.java:389)
> at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:507)
> at com.caucho.util.ThreadPool.run(ThreadPool.java:433)
> at java.lang.Thread.run(Thread.java:613)
>
>
>
> How do converters work? - Dave
>
>
>
>
> Mike Kienenberger wrote:
>>
>> I realize now that I ignored the whole "addToENews is a string" part
>> of the email.
>> What I said is still true, but you probably need a boolean converter
>> on your <h:selectBooleanCheckbox>.
>>
>> On Thu, Oct 1, 2009 at 4:27 PM, Mike Kienenberger <mk...@gmail.com>
>> wrote:
>>> "x == y" is a read-only expression, and probably isn't allowed for a
>>> value in <h:selectBooleanCheckbox>.
>>>
>>> Why not use value="#{emailController.fields.addToENews}"?
>>>
>>> This assumes that 'fields' has a getter for an addToENews property.
>>>
>>> On Thu, Oct 1, 2009 at 1:14 PM, laredotornado <la...@gmail.com>
>>> wrote:
>>>>
>>>> Thanks for your reply but that didn't work. I changed to what you
>>>> specified
>>>> but still get the error
>>>>
>>>> Parsed Expression of unsupported type for this operation. Expression
>>>> class:
>>>> org.apache.commons.el.BinaryOperatorExpression. Expression:
>>>> '#{emailController.fields.addToENews == true}'
>>>>
>>>> upon submitting my form. Any other advice is appreciated, - Dave
>>>>
>>>>
>>>>
>>>> Anton Gavazuk wrote:
>>>>>
>>>>> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews
>>>>> ==true}"
>>>>> />
>>>>>
>>>>> 2009/10/1 laredotornado <la...@gmail.com>
>>>>>
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I'm using MyFaces 1.1 for a web app deployed in Resin 3.0.19. This is
>>>>>> the
>>>>>> expression I have ...
>>>>>>
>>>>>> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews ==
>>>>>> 'true'}" />
>>>>>>
>>>>>> but when I submit my page containing this, I get the error
>>>>>>
>>>>>> Parsed Expression of unsupported type for this operation. Expression
>>>>>> class:
>>>>>> org.apache.commons.el.BinaryOperatorExpression. Expression:
>>>>>> '#{emailController.fields.addToENews == 'true'}'
>>>>>>
>>>>>> Any ideas how I can rewrite the expression to produce the desired
>>>>>> result?
>>>>>> Essentially I'm trying to convert a string to a boolean within JSF.
>>>>>>
>>>>>> Thanks, - Dave
>>>>>> --
>>>>>> View this message in context:
>>>>>> http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25696928.html
>>>>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25703041.html
>>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25706851.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
Re: Trouble converting String to boolean in JSF
Posted by laredotornado <la...@gmail.com>.
I see that myfaces includes a BooleanConverter, but when I add this to my
faces-config.xml file ...
<converter>
<converter-id>booleanConverter</converter-id>
<converter-class>javax.faces.convert.BooleanConverter</converter-class>
</converter>
and my selectBooleanCheckbox element is
<h:selectBooleanCheckbox value="#{emailController.fields.addToENews}"
converter="booleanConverter" />
but I'm still getting this error upon visiting my page
(emailController.fields.addToENews returns a string) ...
java.lang.IllegalArgumentException: Expected submitted value of type Boolean
for Component : {Component-Path : [Class:
javax.faces.component.UIViewRoot,ViewId:
/contactInfo.jsp][Class: javax.faces.component.html.HtmlForm,Id:
contactInfo][Class:
javax.faces.component.html.HtmlSelectBooleanCheckbox,Id: _idJsp1]}
at
org.apache.myfaces.shared_impl.renderkit.RendererUtils.getBooleanValue(RendererUtils.java:157)
at
org.apache.myfaces.shared_impl.renderkit.html.HtmlCheckboxRendererBase.encodeEnd(HtmlCheckboxRendererBase.java:62)
at
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:539)
at javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:498)
at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:366)
at _jsp._contactInfo__jsp._jspService(contactInfo.jsp:106)
at com.caucho.jsp.JavaPage.service(JavaPage.java:60)
at com.caucho.jsp.Page.pageservice(Page.java:579)
at
com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:175)
at
com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:115)
at
com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
at
com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:277)
at
com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:106)
at
org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
at
org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
at
org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
at
org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
at
com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
at
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
at
com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:70)
at
com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
at
com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:389)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:507)
at com.caucho.util.ThreadPool.run(ThreadPool.java:433)
at java.lang.Thread.run(Thread.java:613)
How do converters work? - Dave
Mike Kienenberger wrote:
>
> I realize now that I ignored the whole "addToENews is a string" part
> of the email.
> What I said is still true, but you probably need a boolean converter
> on your <h:selectBooleanCheckbox>.
>
> On Thu, Oct 1, 2009 at 4:27 PM, Mike Kienenberger <mk...@gmail.com>
> wrote:
>> "x == y" is a read-only expression, and probably isn't allowed for a
>> value in <h:selectBooleanCheckbox>.
>>
>> Why not use value="#{emailController.fields.addToENews}"?
>>
>> This assumes that 'fields' has a getter for an addToENews property.
>>
>> On Thu, Oct 1, 2009 at 1:14 PM, laredotornado <la...@gmail.com>
>> wrote:
>>>
>>> Thanks for your reply but that didn't work. I changed to what you
>>> specified
>>> but still get the error
>>>
>>> Parsed Expression of unsupported type for this operation. Expression
>>> class:
>>> org.apache.commons.el.BinaryOperatorExpression. Expression:
>>> '#{emailController.fields.addToENews == true}'
>>>
>>> upon submitting my form. Any other advice is appreciated, - Dave
>>>
>>>
>>>
>>> Anton Gavazuk wrote:
>>>>
>>>> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews
>>>> ==true}"
>>>> />
>>>>
>>>> 2009/10/1 laredotornado <la...@gmail.com>
>>>>
>>>>>
>>>>> Hi,
>>>>>
>>>>> I'm using MyFaces 1.1 for a web app deployed in Resin 3.0.19. This is
>>>>> the
>>>>> expression I have ...
>>>>>
>>>>> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews ==
>>>>> 'true'}" />
>>>>>
>>>>> but when I submit my page containing this, I get the error
>>>>>
>>>>> Parsed Expression of unsupported type for this operation. Expression
>>>>> class:
>>>>> org.apache.commons.el.BinaryOperatorExpression. Expression:
>>>>> '#{emailController.fields.addToENews == 'true'}'
>>>>>
>>>>> Any ideas how I can rewrite the expression to produce the desired
>>>>> result?
>>>>> Essentially I'm trying to convert a string to a boolean within JSF.
>>>>>
>>>>> Thanks, - Dave
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25696928.html
>>>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25703041.html
>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>
>
--
View this message in context: http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25706851.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Trouble converting String to boolean in JSF
Posted by Mike Kienenberger <mk...@gmail.com>.
I realize now that I ignored the whole "addToENews is a string" part
of the email.
What I said is still true, but you probably need a boolean converter
on your <h:selectBooleanCheckbox>.
On Thu, Oct 1, 2009 at 4:27 PM, Mike Kienenberger <mk...@gmail.com> wrote:
> "x == y" is a read-only expression, and probably isn't allowed for a
> value in <h:selectBooleanCheckbox>.
>
> Why not use value="#{emailController.fields.addToENews}"?
>
> This assumes that 'fields' has a getter for an addToENews property.
>
> On Thu, Oct 1, 2009 at 1:14 PM, laredotornado <la...@gmail.com> wrote:
>>
>> Thanks for your reply but that didn't work. I changed to what you specified
>> but still get the error
>>
>> Parsed Expression of unsupported type for this operation. Expression class:
>> org.apache.commons.el.BinaryOperatorExpression. Expression:
>> '#{emailController.fields.addToENews == true}'
>>
>> upon submitting my form. Any other advice is appreciated, - Dave
>>
>>
>>
>> Anton Gavazuk wrote:
>>>
>>> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews
>>> ==true}"
>>> />
>>>
>>> 2009/10/1 laredotornado <la...@gmail.com>
>>>
>>>>
>>>> Hi,
>>>>
>>>> I'm using MyFaces 1.1 for a web app deployed in Resin 3.0.19. This is
>>>> the
>>>> expression I have ...
>>>>
>>>> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews ==
>>>> 'true'}" />
>>>>
>>>> but when I submit my page containing this, I get the error
>>>>
>>>> Parsed Expression of unsupported type for this operation. Expression
>>>> class:
>>>> org.apache.commons.el.BinaryOperatorExpression. Expression:
>>>> '#{emailController.fields.addToENews == 'true'}'
>>>>
>>>> Any ideas how I can rewrite the expression to produce the desired result?
>>>> Essentially I'm trying to convert a string to a boolean within JSF.
>>>>
>>>> Thanks, - Dave
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25696928.html
>>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>>
>>
>> --
>> View this message in context: http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25703041.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>
Re: Trouble converting String to boolean in JSF
Posted by Mike Kienenberger <mk...@gmail.com>.
"x == y" is a read-only expression, and probably isn't allowed for a
value in <h:selectBooleanCheckbox>.
Why not use value="#{emailController.fields.addToENews}"?
This assumes that 'fields' has a getter for an addToENews property.
On Thu, Oct 1, 2009 at 1:14 PM, laredotornado <la...@gmail.com> wrote:
>
> Thanks for your reply but that didn't work. I changed to what you specified
> but still get the error
>
> Parsed Expression of unsupported type for this operation. Expression class:
> org.apache.commons.el.BinaryOperatorExpression. Expression:
> '#{emailController.fields.addToENews == true}'
>
> upon submitting my form. Any other advice is appreciated, - Dave
>
>
>
> Anton Gavazuk wrote:
>>
>> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews
>> ==true}"
>> />
>>
>> 2009/10/1 laredotornado <la...@gmail.com>
>>
>>>
>>> Hi,
>>>
>>> I'm using MyFaces 1.1 for a web app deployed in Resin 3.0.19. This is
>>> the
>>> expression I have ...
>>>
>>> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews ==
>>> 'true'}" />
>>>
>>> but when I submit my page containing this, I get the error
>>>
>>> Parsed Expression of unsupported type for this operation. Expression
>>> class:
>>> org.apache.commons.el.BinaryOperatorExpression. Expression:
>>> '#{emailController.fields.addToENews == 'true'}'
>>>
>>> Any ideas how I can rewrite the expression to produce the desired result?
>>> Essentially I'm trying to convert a string to a boolean within JSF.
>>>
>>> Thanks, - Dave
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25696928.html
>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25703041.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>
Re: Trouble converting String to boolean in JSF
Posted by laredotornado <la...@gmail.com>.
Thanks for your reply but that didn't work. I changed to what you specified
but still get the error
Parsed Expression of unsupported type for this operation. Expression class:
org.apache.commons.el.BinaryOperatorExpression. Expression:
'#{emailController.fields.addToENews == true}'
upon submitting my form. Any other advice is appreciated, - Dave
Anton Gavazuk wrote:
>
> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews
> ==true}"
> />
>
> 2009/10/1 laredotornado <la...@gmail.com>
>
>>
>> Hi,
>>
>> I'm using MyFaces 1.1 for a web app deployed in Resin 3.0.19. This is
>> the
>> expression I have ...
>>
>> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews ==
>> 'true'}" />
>>
>> but when I submit my page containing this, I get the error
>>
>> Parsed Expression of unsupported type for this operation. Expression
>> class:
>> org.apache.commons.el.BinaryOperatorExpression. Expression:
>> '#{emailController.fields.addToENews == 'true'}'
>>
>> Any ideas how I can rewrite the expression to produce the desired result?
>> Essentially I'm trying to convert a string to a boolean within JSF.
>>
>> Thanks, - Dave
>> --
>> View this message in context:
>> http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25696928.html
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25703041.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.
Re: Trouble converting String to boolean in JSF
Posted by Anton Gavazuk <an...@gmail.com>.
<h:selectBooleanCheckbox value="#{emailController.fields.addToENews ==true}"
/>
2009/10/1 laredotornado <la...@gmail.com>
>
> Hi,
>
> I'm using MyFaces 1.1 for a web app deployed in Resin 3.0.19. This is the
> expression I have ...
>
> <h:selectBooleanCheckbox value="#{emailController.fields.addToENews ==
> 'true'}" />
>
> but when I submit my page containing this, I get the error
>
> Parsed Expression of unsupported type for this operation. Expression class:
> org.apache.commons.el.BinaryOperatorExpression. Expression:
> '#{emailController.fields.addToENews == 'true'}'
>
> Any ideas how I can rewrite the expression to produce the desired result?
> Essentially I'm trying to convert a string to a boolean within JSF.
>
> Thanks, - Dave
> --
> View this message in context:
> http://www.nabble.com/Trouble-converting-String-to-boolean-in-JSF-tp25696928p25696928.html
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>
>