a4j:param 不调用值属性指向的我的 javascript
我愿意采用不同的方法来做到这一点,但我所拥有的似乎应该适用于 RichFaces4 和 JSF2 的文档。
用户流程如下:
- 1) 有一个使用 h:outputLink 实现的“签出”文档链接
- 2) 用户单击它,并收到一个对话框提示,要求输入使用 rich:popupPanel 实现的签出注释
- 3) 用户输入评论并单击使用 h:link 实现的 rich:popupPanel 上的“继续”按钮(也尝试过 h:commandLink 和 a4j:commandLink)
- 4) 弹出一个新窗口,其中内容设置为h:link 结果属性
在我的破损案例中,除了从 h:link 传递参数时,一切正常 使用 a4j:param,其 value 属性无法正确解析它指向的 javascript。
<h:outputLink id="promptForCommentsLink"
onclick="#{rich:component('commentsDlg')}.show();return false;"
value="#"> Check Out </h:outputLink>
<rich:popupPanel id="commentsDlg" modal="true">
<h:inputTextarea id="commentsId"/>
<h:link id="continueLink"
outcome="editorPage" <!-- editor for making changes to document -->
target="_blank" <!-- open in it;s own indow -->
value="Continue Check Out"
onclick="#{rich:component('commentsDlg')}.hide();">
<!-- these params get assignd to backing bean properties -->
<a4j:param name="dataId"
value="#{ithRow.id}" assignTo="#{myController.dataId}"/>
<a4j:param name="checkedOut"
value="true" assignTo="#{myController.checkedOut}"/>
<!-- this one is broken. assigns chars 'document.getElementById('..
to #{myController.checkOutComment} -->
<a4j:param name="checkOutComment"
assignTo="#{myController.checkOutComment}"
noEscape="true"
value="document.getElementById('myForm:dataTable:0:commentsId').value"
/>
</h:link>
</rich:popupPanel>
我在想也许
document.getElementById('myForm:dataTable:0:commentsId').value
没有指向我在文本区域中输入的内容,但是通过在 dlg 上放置另一个按钮并将其 onclick 指向相同的元素 id,它确实提醒了我它输入的内容。
当我停止在服务器端视图作用域 myController.setCheckOutComment(String s) 方法时,它会传递字符串“document.getElementById('myForm:dataTable:0:commentsId').value”
根据 RF4 文档:
除了 Ajax 组件之外,a4j:param 标签还可以与非 Ajax 组件一起使用。这包括通过 GET 请求工作的组件,例如 h:link
和
JavaScript 函数中的变量可用于 value 属性。在这样的实现中,noEscape 属性应设置为 true。使用 noEscape="true",value 属性可以包含任何 JavaScript 表达式或 JavaScript 函数调用,结果将作为 value 属性发送到服务器。
因为我似乎遵循 jsf/rf4 规则,我以为这样就可以了。
需要注意的一件事是,如果我使用 a4j:commandLink 而不是 h:link,它确实 发送 javascript 评估的结果,但是,这会破坏其自己窗口中的打开 以及其他一些问题。
对可能发生的事情有什么想法,或者有更好的方法吗?
I am open to a different way to do this, but what I have seems like it should work from the documentation for RichFaces4 and JSF2.
The user flow is like this:
- 1) There is a 'Check Out' document link implemented with h:outputLink
- 2) The user clicks it and gets prompted with a dialog to enter check out comments implemented with rich:popupPanel
- 3) The user enters comments and clicks 'Continue' Button on the rich:popupPanel implemented with h:link (tried h:commandLink and a4j:commandLink also)
- 4) A new window pops up with the contents set to the h:link outcome attribute
In my broken case, everything works except when I pass a parameter from h:link
with a4j:param, whose value attribute does not resolve the javascript it points to correctly.
<h:outputLink id="promptForCommentsLink"
onclick="#{rich:component('commentsDlg')}.show();return false;"
value="#"> Check Out </h:outputLink>
<rich:popupPanel id="commentsDlg" modal="true">
<h:inputTextarea id="commentsId"/>
<h:link id="continueLink"
outcome="editorPage" <!-- editor for making changes to document -->
target="_blank" <!-- open in it;s own indow -->
value="Continue Check Out"
onclick="#{rich:component('commentsDlg')}.hide();">
<!-- these params get assignd to backing bean properties -->
<a4j:param name="dataId"
value="#{ithRow.id}" assignTo="#{myController.dataId}"/>
<a4j:param name="checkedOut"
value="true" assignTo="#{myController.checkedOut}"/>
<!-- this one is broken. assigns chars 'document.getElementById('..
to #{myController.checkOutComment} -->
<a4j:param name="checkOutComment"
assignTo="#{myController.checkOutComment}"
noEscape="true"
value="document.getElementById('myForm:dataTable:0:commentsId').value"
/>
</h:link>
</rich:popupPanel>
I was thinking maybe
document.getElementById('myForm:dataTable:0:commentsId').value
didn't point to what I typed into the textarea, but by putting another button on the dlg and pointing it's onclick to the same element id, it did indeed alert me with what it typed.
When I stop on the server side view scoped myController.setCheckOutComment(String s) method, it gets passed the string "document.getElementById('myForm:dataTable:0:commentsId').value"
According to RF4 documentation:
The a4j:param tag can be used with non-Ajax components in addition to Ajax components. This includes components which are working through the GET request, such as the h:link
and
Variables from JavaScript functions can be used for the value attribute. In such an implementation, the noEscape attribute should be set to true. Using noEscape="true", the value attribute can contain any JavaScript expression or JavaScript function invocation, and the result will be sent to the server as the value attribute.
Since I seem to be playing by the jsf/rf4 rules, I thought this would be okay.
One thing to note, if I use a4j:commandLink instead of h:link, it does indeed
send the result of javascript evaluated, however, that breaks the opening in its own window
and a few other issues.
Any thoughts on what might be happening, or even a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 a4j:jsFunction 与您需要的参数一起使用。然后从 h:link 标记中的 onclick 调用该函数,例如 setParams(#{ithRow.id}, true)。问题仍然是您无法将值作为参数传递给 javascript 函数。不过,您可以使用“execute”将 inputArea 的值保存到支持 bean 并让后端处理该值。
所以是的,我会采取不同的做法。我认为您可以在后端处理其他两个参数,我将使用“执行”来存储 inputArea 的值。
磁力,
米洛·范德泽
You could use a a4j:jsFunction with the parameters you need. Then call that function from the onclick in the h:link tag like setParams(#{ithRow.id}, true). Problem remain that you can't pass the value as a parameter to the javascript function. You could though use 'execute' to save the value of the inputArea to a backing bean and let the backend handle the value.
So yes, I would do it differently. I think you could handle the two other params at the backend and I would use 'execute' to store the value of the inputArea.
MAG,
Milo van der Zee