开发者

How to call javascript from backingbean jsf

ClientScript.RegisterStartupScript(
    this.GetType(),
    "ReturnScript", 
    "<script language='javascript'> alert('" + ErrorMsg + "');&l开发者_Python百科t;/script>");

alternate in java (JSF)


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" />

You can even get it as a bean property:

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

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

See also:

  • Communication between Java/JSP/JSF and JavaScript
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜