JSF将ui:param与复合组件结合起来 [英] JSF Combine ui:param with composite component
问题描述
您以前在这个论坛上救过我很多次,但现在我真的很困,现在不再在哪里搜索...
you have saved me many times ago with this forum, but now I am really stuck and don't now where to search any longer...
我总是收到以下错误消息(警告级别,但方法也未正确执行):
I always get the following error message (warning level, but method is also not executed correctly):
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'editor' resolved to null: javax.faces.FacesException: #{cc.attrs.selectionListener}
我已将问题隔离为几行代码:
I have isolated the problem to a few lines of code:
这是我的主文件:
<c:forEach items="#{myBean.getEditors()}" var="currentEditor" >
<ui:include src="#{currentEditor.getPanel()} >
<ui:param name="editor" value="#{currentEditor} />
</ui:include>
</c:forEach>
bean.getEditors()(会话作用域)现在仅返回一个列表,其中包含一个条目. 编辑器"是具有一些简单属性和两个侦听器方法的POJO.侦听器方法仅写入日志条目. (将来当然应该做更多的事情)
The bean.getEditors() (session scoped) just returns a list with one single entry at the moment. The 'editor' is a POJO with some simple attributes and two listener methods. The listener method does only write a log entry. (Should of course do more in future)
包含的文件如下:
<h:selectOneMenu value="#{editor.menuValue}>
<f:selectItem itemValue="Value 1" />
<f:selectItem itemValue="Value 2" />
<a4j:ajax event="change" listener="#{editor.menutListener()}" />
</h:selectOneMenu>
<myComponent:treeComponent id="tree" selectionListener="#{editor.treeListener()} />
我创建的组件由一张richfaces树组成,单击节点时,将调用以下方法:
The component I created consists of a richfaces tree and when clicking on a node the following method is called:
<a4j:jsFunction name="performSelection" action="#{cc.attrs.selectionListener} />
我非常有信心构图本身还可以,因为我也在不同的地方使用它.当我从a4j:jsFunction中删除操作时,它也可以完美运行.
I am quite confident that the composition itself is ok because I use it also at different places. When I remove the action from the a4j:jsFunction it also works perfect.
对我来说,它闻起来有点像 JSF 1223错误
For me it smells a bit like the bug JSF 1223
该解决方法对我不起作用-可能是因为我在forEach中创建了参数.
The workaround does not work for me - probably because I create the param in the forEach.
我以前也遇到过类似的问题(ui:param +组件),但是能够通过将完整路径作为属性而不是参数来解决它们.但这在这里不起作用,因为它被用在太多不同的地方.
I had similar problems (ui:param + component) before, but was able to solve them with giving the full path as attribute instead of a parameter. But this does not work here because it is used in too many different places.
请帮助,我不是唯一一个遇到此问题的人,但我只是没有找到其他与此相关的线程.
Please help, I cannot be the only one with this problem, but I simply do not find any other threads for this.
今天,我有了一个崭新的想法,甚至更加接近这个问题.您可能会忘记整个include/forEach的所有内容...
Today with a fresh mind I came even closer to the problem. You can forget the whole include/ forEach stuff...
<myComponent:treeComponent id="tree" selectionListener="#{myBean.getSingleEditor().treeListener()} />
可以,而
<ui:param name="editor" value="#{myBean.getSingleEditor()} />
<myComponent:treeComponent id="tree" selectionListener="#{editor.treeListener()} />
不起作用. 可以很好地执行JAVA代码,但是将错误写入日志,并且jsFunction的render和oncomplete方法不起作用. 我还尝试使用数据"而不是动作"进行测试.没有错误写入日志,但是甚至没有调用JAVA方法.
does not work. Well the JAVA code is performed, but the error is written to the log and the render and oncomplete method of the jsFunction do not work. I also tried to use "data" instead of "action" for testing. No error is written to log, but JAVA method is not even called.
推荐答案
经过几天的尝试和错误,我发现了一个对我有用的解决方案:
After many days of try&error I found a solution that is working for me:
我将侦听器方法分为JAVA类的一个参数和方法名(作为简单String)的一个参数
I splitted up the listener method to one parameter with the JAVA class and one parameter with the the method name (as simple String)
操作方法现在看起来像:
The action method now looks like:
<a4j:jsFunction name="performSelection" action="#{cc.attrs.listenerClass[cc.attrs.listenerMethodName]}" />
不好但是可以工作...也许对某人有帮助-或任何人都可以解释更多...
Not nice but working... Perhaps it helps someone - or anybody can explain more...
顺便说一句,以下内容对我不起作用:
By the way, the following was not working for me:
<a4j:jsFunction name="performSelection" action="#{cc.attrs.listenerClass[staticMethodName]}" />
虽然还可以...
<a4j:jsFunction name="performSelection" action="#{cc.attrs.listenerClass.staticMethodName()}" />
不知道-也许我的头一次又一次地在同一堵墙上奔跑...
Don't know - perhaps my head is running agains the same wall again and again...
这篇关于JSF将ui:param与复合组件结合起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!