如何从BackingBean JSF调用JavaScript [英] How to call javascript from backingbean jsf

查看:95
本文介绍了如何从BackingBean JSF调用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ClientScript.RegisterStartupScript(
    this.GetType(),
    "ReturnScript", 
    "<script language='javascript'> alert('" + ErrorMsg + "');</script>");

Java的替代版本(JSF)

alternate in java (JSF)

推荐答案

只需按原样在JSF视图中打印JS代码. JS在客户端计算机上运行,​​而不是在服务器计算机上运行.您可以为此使用<h:outputText>.

Just print the JS code as-is in the JSF view. The JS runs at client machine, not at server machine. You can use <h:outputText> for this.

<h:outputText value="<script>alert('foo');</script>" escape="false" />

您甚至可以将其作为bean属性获得:

You can even get it as a bean property:

<h:outputText value="#{bean.script}" escape="false" />

escape="false"用于防止值的(默认)HTML转义.

The escape="false" is there to prevent the (default) HTML-escaping of the value.

另请参见:

这篇关于如何从BackingBean JSF调用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆