这里是 javascript 的新手。尝试使用我在网络上找到的示例访问 RichFaces 组件的内部结构,但运气不佳。
RichFaces 3.3 和 JSF 1.2、jboss 服务器、Chrome、ant。
我见过这样的例子
#{rich:component(formId)}
RichFaces.$(stHourId)
但执行时都无法识别。 那么我如何使用这些或以其他方式访问它们......
- 这些在 RichFaces 3.3 中不可用吗?如果没有,有没有办法做下面3.3的例子?
- 我的 xhtml 文件中是否需要一些特殊的东西才能使用它们,或者在 web.xml 或 faces-config.xml 或 ?
这是具体的例子:
在 javascript 中访问 rich:comboBox 的值列表 - 在网上找到一个例子
var valueArray = #{rich:component(formId)}.comboList.itemsValue;
页面加载时出现错误:Uncaught SyntaxError: Unexpected token 。 当我查看开发人员工具控制台中的代码时,#{rich:component(formid)} 完全缺失(这会导致其他问题)
var valueArray = .comboList.itemsValue;
如果我删除该行但中断代码,并尝试在控制台中手动使用#{rich:component...},
#{rich:component('form:recurStartMincomboboxField')}
我得到:Uncaught SyntaxError: Unexpected token ILLEGAL 或
RichFaces.$('form:recurStartMincomboboxField')
一个不同的错误:Uncaught TypeError: RichFaces.$ is not a function
我知道表单 ID 是正确的,因为下面的工作,但我似乎无法从这里访问值列表
document.getElementById('form:recurStartMincomboboxField')
如果您想在上下文中查看它,相关部分:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<head>
<script>
function checkMinute(formId, defaultVal) {
alert('validateMinute');
var minuteStr = document.getElementById(formId).value;
// get list of values allowed for the combobox
var valueArray = #{rich:component(formId)}.comboList.itemsValue;
}
</script>
</head>
<body>
<h:form id="form">
......
<rich:comboBox id="recurStartMin" value="#{filterManagerBean.recurStartMin}" required="false"
selectFirstOnUpdate="true" defaultLabel="" enableManualInput="true" width="50"
onchange="checkMinute('form:recurStartMincomboboxField', '00')"
>
<f:selectItems value="#{filterManagerBean.minuteOptions}" />
</rich:comboBox>
......
</h:form>
</body>
</html>
整天都在尝试各种事情和搜索,非常沮丧:(
最佳答案
#{rich:component('recurStartMincomboboxField')}
这是表达式语言 (EL) 而不是 JavaScript,请参阅 tutorial .
您不能在客户端执行 EL,因为它供服务器使用(有点像内联 Java 代码)。 EL 表达式在页面加载时执行,所以如果你想使用它,你必须事先知道 id,或者 id 必须在服务器上可用。或者您可以使用纯 JavaScript:
document.getElementById('form:recurStartMincomboboxField').component
RichFaces.$
在 RichFaces 3 中不可用。
关于javascript - 无法使用 #{rich :component(Id)} or RichFaces. $(Id) 访问 javascript 中的丰富组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32150612/