java - 丰富的 javascript 函数 findComponent

标签 java jsf richfaces el

我正在尝试使用 rich:findComponent 添加动态 onclick 事件:

<font class="topFirstTablehdCategory2" style="font-size: 12px; cursor: pointer;" onclick="#{rich:findComponent('benchmarkEndDate').value = channelPerformanceController.resetDate}">
    RESET
</font>

但是我得到了

com.sun.el.parser.ParseException: Encountered "=" at line 1, column 48.

我愿意做的是将字符串值设置为 rich:calender ,其 id 是从字段 resetDate 提供的 benchmarkEndDate ChannelPerformanceController 类。

我还在jsp页面中写了一个javascript方法:

function setResetDate(id, date) {
    #{rich:findComponent('benchmarkEndDate').value} = date;
}

不工作。它的调用方式为:onclick="setResetDate('benchmarkEndDate', '#{channelPerformanceController.resetDate}')"

它在浏览器中呈现为:

function setResetDate(id, date) {
        2011-03-24 00:00:00.0 = date;
}

这个方法:

function setResetDate(id, date) {
        document.getElementById(#{rich:clientId(id)}) = date;
}

更改为:

function setResetDate(id, date) {
        document.getElementById() = date;
}

我做错了什么?我怎样才能实现这个目标?

最佳答案

  • JavaScript 由客户端执行。
  • 在将标记发送到浏览器之前,先在服务器上计算表达式语言表达式。
<小时/>

#{foo = bar} 不是有效的 EL 表达式。 = 不是 EL 中的有效运算符。 EL 没有赋值运算符。通过 EL 分配值的唯一方法是在支持它们的属性中使用值绑定(bind)(几乎完全通过 JSF 输入控件)。

<小时/>

如果计算此表达式:

#{rich:clientId(id)}

此表达式将搜索 request , sessionapplication使用 getAttribute("id") 查找范围,使用托管 bean 机制来创建这样的 bean(如果使用此 id 定义)。当它被求值并返回 null 时,不会渲染任何内容。

<小时/>

如果计算此表达式:

#{rich:clientId(id)}

然后它被放置在模板文本中(可能在 JSP 2.0/J2EE 1.4 中。)

EL 表达式有两种类型:

  • #{foo} - 延迟表达式:仅在允许它们的属性中进行计算
  • ${foo} - 立即表达式:模板文本中允许

从 JSP 2.1 开始,模板文本中存在延迟表达式会导致翻译错误。来自 JSP 2.1 规范:

When used in template text in a JSP page, the #{ character sequence triggers a translation error, unless specifically allowed through a configuration setup. This is because the #{} syntax is associated exclusively with deferred-evaluation in JSP 2.1 and does not make sense in the context of template text (only immediate evaluation using the ${expr} syntax makes sense in template text).

In a tag file, #{expr} in template text is handled according to the tag file’s JSP version: If the tag file’s JSP version is 2.0 or less, #{expr} in template text will not cause any error. If the tag file’s JSP version is equal to or greater than 2.1, #{expr} in template text must cause an error, unless it has been escaped or the tag file contains a deferredSyntaxAllowedAsLiteral tag directive attribute set to TRUE.

通常,#{foo} 表达式必须仅出现在 JSF 控件属性中(对于 JSP View )。

<小时/>

如果您想更改服务器端值,请使用表单提交和操作绑定(bind)。这可以通过AJAX来完成在 RichFaces 中。

关于java - 丰富的 javascript 函数 findComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7120925/

相关文章:

java - 并发标记和清除算法

java - JSF 中文件浏览的替代方案是什么?

java - 如果请求超过 1.5 秒,则不会显示 RichFaces 建议框

java - Jar 文件在 Windows 上完美运行,但在 Rasp Pi 内的 Ubuntu 上运行失败

java - 为什么 war :exploded make no difference to the output of my Maven build?

java - Maven 将属性文件添加到 jar 文件

javascript - 当鼠标在jsf中结束时如何突出显示扩展数据表的行?

javascript - 如何使用 <a4j :jsFunction><a4j:actionparam>

java - 在 JSF 中选择 "switch"bean 的最佳方法

java - a4j :support to be embedded to be working? 在哪里