如何获取当前视图HTML源代码并将其作为字符串传递给JSF ManagedBean [英] How to get current view HTML source and pass it JSF ManagedBean as String

查看:120
本文介绍了如何获取当前视图HTML源代码并将其作为字符串传递给JSF ManagedBean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取当前视图的HTML源代码,并将其作为参数传递给JSF托管bean。 JSF中是否有这样的功能?

I want to get current view HTML source and pass it to JSF managed bean as a parameter. Is there anyway in JSF I can do this?

推荐答案

在JSF中无法执行它,因为它无法运行网页浏览器。

You can't do it in JSF as it doesn't run in the webbrowser at all.

你最好的选择是使用JavaScript。下面的示例在点击提交按钮时用HTML源代码设置一个隐藏的输入值:

Your best bet is using JavaScript. The below example sets a hidden input value with the HTML source code when the submit button is clicked:

<h:form id="form">
    <h:inputHidden id="source" value="#{bean.source}" />
    <h:commandButton value="submit" action="#{bean.submit}" 
        onclick="document.getElementById('form:source').value=document.getElementsByTagName('html')[0].outerHTML"
    />
</h:form>

在action方法中,它在特定的例子中,然后由属性。

In the action method, it's in the particular example then just available by the source property.

这篇关于如何获取当前视图HTML源代码并将其作为字符串传递给JSF ManagedBean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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