开发者

How to call Javascript function in JSF EL conditionally?

开发者 https://www.devze.com 2022-12-26 00:51 出处:网络
I have to call JavaScript function based on the bean value. i use the following code onmouseover=\"#{occasionBean.user.userPreference.defaultPreview==true?\'\':\'Tip()\'})\"

I have to call JavaScript function based on the bean value. i use the following code

onmouseover="#{occasionBean.user.userPreference.defaultPreview==true?'':'Tip()'})"

I need to send some parameters in Tip() like this

Tip('<img src="pics/image.jpg" width="60">')

Error i am getting is javax.servlet.jsp.JspException: javax.faces.el.EvaluationException: com.sun.faces.el.impl.parser.ParseException: Encountered "test" at line 1, column 60. Was expecting one of: "}" ... "." ... ">" ... "gt" ... "<" ... "lt" ... "==" ... "eq" ... "<=" ... "le" ... ">=" ... "ge" ... "!=" ... "ne" ... "[" ... "+" ... "-" ... "*" ... 开发者_JAVA百科 "/" ... "div" ... "%" ... "mod" ... "and" ... "&&" ... "or" ... "||" ... "?" ... '


First, get rid of the final closing parenthesis:

onmouseover="#{occasionBean.user.userPreference.defaultPreview==true?'':'Tip()'}"

Then I'd advise against passing HTML constructs as arguments. You'd better use something like:

Tip(\'img\', \'pics/image.jpg\', 60)

and construct the html in the Tip method, which may be overloaded for different types of tips.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号