You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Michael Heinen <mh...@recommind.com> on 2007/03/29 17:37:47 UTC

escaping in EL?

I want to express the following Javascript function call via EL:

 

<sometag

 
onclick=#{MyBean.checkA?'doJS('staticvalue','#{beanA.value}');':'alert('
hello'));'}"

</sometag>

 

How can I do this ?

Is there any way to escape this stuff ?

 

Thanks,

Michael


RE: escaping in EL?

Posted by Michael Heinen <mh...@recommind.com>.
Unfortunatedly I am still using jsps instead of facelets.
Escaping with slashes or backslashes does not work.
EL really sucks.

I do now the following:

attribute="#{MyBean.checkA?'realJsFunction':'dummyJsFunction'}('staticvalue','#{beanA.value}');"

Where dummyJS is an empty javascript function.
A disadvanatage is that the dummy stuff is also rendered to the client.


Thanks for any help 
Michael


-----Original Message-----
From: Mike Kienenberger [mailto:mkienenb@gmail.com] 
Sent: Freitag, 30. März 2007 15:36
To: MyFaces Discussion
Subject: Re: escaping in EL?

So what you really want is

#{MyBean.checkA
    ? 'doJS('staticvalue',' + beanA.value + ');'
    : 'alert('hello'));' "

Some of the issues I see

- You need to somehow escape the single quotes in the javascript
- You need to be able to concat the doJS expression.

I've solved the second issue by writing a static concat function in
facelets.   That's only an option if you're using facelets, though.

I don't know if there's a way to escape a single quote in EL.  I'd
probably solve that one with a static function that returns a single
quote in facelets as well.  Either that, or stick it in as a managed
bean.


On 3/30/07, Michael Heinen <mh...@recommind.com> wrote:
> This does not work.
>
> The "?" must be part of the EL expression, or ?
>
> What I want is that if MyBean.checkA is true, then  doJS('staticvalue','#{beanA.value}'); should be printed into the attribute value.
> This expression has to be in single quotes.
> The problem is that the JavaScript parameters in this function call have to be also in single quotes.
>
> Something like your suggestion:
> onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"
> is rendered as
>
> true?'doJS('staticvalue','bla');':'alert('hello'));'
>
> Michael
>
> -----Original Message-----
> From: Mike Kienenberger [mailto:mkienenb@gmail.com]
> Sent: Donnerstag, 29. März 2007 17:42
> To: MyFaces Discussion
> Subject: Re: escaping in EL?
>
> Are you trying to do this?
>
> onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"
>
> Only put #{} around parts you want interpreted by EL.
>
> On 3/29/07, Michael Heinen <mh...@recommind.com> wrote:
> >
> >
> >
> >
> > I want to express the following Javascript function call via EL:
> >
> >
> >
> > <sometag
> >
> > onclick=#{MyBean.checkA?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'}"
> >
> > </sometag>
> >
> >
> >
> > How can I do this ?
> >
> > Is there any way to escape this stuff ?
> >
> >
> >
> > Thanks,
> >
> > Michael
>
>


Re: escaping in EL?

Posted by Mike Kienenberger <mk...@gmail.com>.
So what you really want is

#{MyBean.checkA
    ? 'doJS('staticvalue',' + beanA.value + ');'
    : 'alert('hello'));' "

Some of the issues I see

- You need to somehow escape the single quotes in the javascript
- You need to be able to concat the doJS expression.

I've solved the second issue by writing a static concat function in
facelets.   That's only an option if you're using facelets, though.

I don't know if there's a way to escape a single quote in EL.  I'd
probably solve that one with a static function that returns a single
quote in facelets as well.  Either that, or stick it in as a managed
bean.


On 3/30/07, Michael Heinen <mh...@recommind.com> wrote:
> This does not work.
>
> The "?" must be part of the EL expression, or ?
>
> What I want is that if MyBean.checkA is true, then  doJS('staticvalue','#{beanA.value}'); should be printed into the attribute value.
> This expression has to be in single quotes.
> The problem is that the JavaScript parameters in this function call have to be also in single quotes.
>
> Something like your suggestion:
> onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"
> is rendered as
>
> true?'doJS('staticvalue','bla');':'alert('hello'));'
>
> Michael
>
> -----Original Message-----
> From: Mike Kienenberger [mailto:mkienenb@gmail.com]
> Sent: Donnerstag, 29. März 2007 17:42
> To: MyFaces Discussion
> Subject: Re: escaping in EL?
>
> Are you trying to do this?
>
> onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"
>
> Only put #{} around parts you want interpreted by EL.
>
> On 3/29/07, Michael Heinen <mh...@recommind.com> wrote:
> >
> >
> >
> >
> > I want to express the following Javascript function call via EL:
> >
> >
> >
> > <sometag
> >
> > onclick=#{MyBean.checkA?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'}"
> >
> > </sometag>
> >
> >
> >
> > How can I do this ?
> >
> > Is there any way to escape this stuff ?
> >
> >
> >
> > Thanks,
> >
> > Michael
>
>

Re: escaping in EL?

Posted by Michał 'Gandalf' Stawicki <st...@gmail.com>.
Perhaps escape quotes? \' ?

michał

On 30/03/07, Michael Heinen <mh...@recommind.com> wrote:
> A simpler sample:
>
> attribute="#{ MyBean.checkA ? 'alert('aaa');':'alert ('bbb');'}"
>
> results in org.apache.commons.el.parser.ParseException: Encountered "? \'alert (\' aaa" at line 1, column 52.
>
> Michael
>
>
> -----Original Message-----
> From: Michael Heinen [mailto:mhn@recommind.com]
> Sent: Freitag, 30. März 2007 15:28
> To: MyFaces Discussion
> Subject: RE: escaping in EL?
>
> This does not work.
>
> The "?" must be part of the EL expression, or ?
>
> What I want is that if MyBean.checkA is true, then  doJS('staticvalue','#{beanA.value}'); should be printed into the attribute value.
> This expression has to be in single quotes.
> The problem is that the JavaScript parameters in this function call have to be also in single quotes.
>
> Something like your suggestion:
> onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"
> is rendered as
>
> true?'doJS('staticvalue','bla');':'alert('hello'));'
>
> Michael
>
> -----Original Message-----
> From: Mike Kienenberger [mailto:mkienenb@gmail.com]
> Sent: Donnerstag, 29. März 2007 17:42
> To: MyFaces Discussion
> Subject: Re: escaping in EL?
>
> Are you trying to do this?
>
> onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"
>
> Only put #{} around parts you want interpreted by EL.
>
> On 3/29/07, Michael Heinen <mh...@recommind.com> wrote:
> >
> >
> >
> >
> > I want to express the following Javascript function call via EL:
> >
> >
> >
> > <sometag
> >
> > onclick=#{MyBean.checkA?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'}"
> >
> > </sometag>
> >
> >
> >
> > How can I do this ?
> >
> > Is there any way to escape this stuff ?
> >
> >
> >
> > Thanks,
> >
> > Michael
>
>
>


-- 
stawicki@gmail.com
http://stawicki.jasliska.pl
GG: 3691111
JID: stawicki@gmail.com

RE: escaping in EL?

Posted by Michael Heinen <mh...@recommind.com>.
A simpler sample:

attribute="#{ MyBean.checkA ? 'alert('aaa');':'alert ('bbb');'}"

results in org.apache.commons.el.parser.ParseException: Encountered "? \'alert (\' aaa" at line 1, column 52.

Michael


-----Original Message-----
From: Michael Heinen [mailto:mhn@recommind.com] 
Sent: Freitag, 30. März 2007 15:28
To: MyFaces Discussion
Subject: RE: escaping in EL?

This does not work.

The "?" must be part of the EL expression, or ?

What I want is that if MyBean.checkA is true, then  doJS('staticvalue','#{beanA.value}'); should be printed into the attribute value.
This expression has to be in single quotes.
The problem is that the JavaScript parameters in this function call have to be also in single quotes.

Something like your suggestion:
onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"
is rendered as 

true?'doJS('staticvalue','bla');':'alert('hello'));'

Michael

-----Original Message-----
From: Mike Kienenberger [mailto:mkienenb@gmail.com] 
Sent: Donnerstag, 29. März 2007 17:42
To: MyFaces Discussion
Subject: Re: escaping in EL?

Are you trying to do this?

onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"

Only put #{} around parts you want interpreted by EL.

On 3/29/07, Michael Heinen <mh...@recommind.com> wrote:
>
>
>
>
> I want to express the following Javascript function call via EL:
>
>
>
> <sometag
>
> onclick=#{MyBean.checkA?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'}"
>
> </sometag>
>
>
>
> How can I do this ?
>
> Is there any way to escape this stuff ?
>
>
>
> Thanks,
>
> Michael



RE: escaping in EL?

Posted by Michael Heinen <mh...@recommind.com>.
This does not work.

The "?" must be part of the EL expression, or ?

What I want is that if MyBean.checkA is true, then  doJS('staticvalue','#{beanA.value}'); should be printed into the attribute value.
This expression has to be in single quotes.
The problem is that the JavaScript parameters in this function call have to be also in single quotes.

Something like your suggestion:
onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"
is rendered as 

true?'doJS('staticvalue','bla');':'alert('hello'));'

Michael

-----Original Message-----
From: Mike Kienenberger [mailto:mkienenb@gmail.com] 
Sent: Donnerstag, 29. März 2007 17:42
To: MyFaces Discussion
Subject: Re: escaping in EL?

Are you trying to do this?

onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"

Only put #{} around parts you want interpreted by EL.

On 3/29/07, Michael Heinen <mh...@recommind.com> wrote:
>
>
>
>
> I want to express the following Javascript function call via EL:
>
>
>
> <sometag
>
> onclick=#{MyBean.checkA?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'}"
>
> </sometag>
>
>
>
> How can I do this ?
>
> Is there any way to escape this stuff ?
>
>
>
> Thanks,
>
> Michael


Re: escaping in EL?

Posted by Mike Kienenberger <mk...@gmail.com>.
Are you trying to do this?

onclick=#{MyBean.checkA}?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'"

Only put #{} around parts you want interpreted by EL.

On 3/29/07, Michael Heinen <mh...@recommind.com> wrote:
>
>
>
>
> I want to express the following Javascript function call via EL:
>
>
>
> <sometag
>
> onclick=#{MyBean.checkA?'doJS('staticvalue','#{beanA.value}');':'alert('hello'));'}"
>
> </sometag>
>
>
>
> How can I do this ?
>
> Is there any way to escape this stuff ?
>
>
>
> Thanks,
>
> Michael