在给定的情况下,我希望使用具有不同ManagedBeans的facelet,因此可以将有关action-bean作为参数:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html" >
<h:body>
<ui:include src="ratings.xhtml" >
<ui:param name="createAction" value="#{myOneCreateAction}" />
<ui:param name="ratings" value="#{context.ratings}" />
</ui:include>
</h:body>
</html>我将create操作作为参数value="#{myOneCreateAction}"。
在这个facelet中,还有一个组件也在其他页面上使用过几次--所以我尝试在复合组件中重构它。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:io="http://java.sun.com/jsf/composite/inoutComponents">
<ui:composition>
<rich:dataTable id="ratingTblId"
value="#{ratings}"
var="rating">
<rich:column>
<io:removeButton
id="removeButton"
actionMethod="#{createAction.removeRating}"
immediate="true"
render=":#{rich:clientId('ratingTblId')}" />
<h:commandButton
id="removeButton2"
actionListener="#{createAction.removeRating}"
immediate="true" >
<f:ajax render="ratingTblId" />
</h:commandButton>
</rich:column>
</rich:dataTable>
</ui:composition>
</html>参见如何将该方法作为actionMethod="#{createAction.removeRating}"提供给组件。该组件本身如下所示:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:cc="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<cc:interface>
<cc:attribute
name="actionMethod"
targets="remove"
method-signature="void f(javax.faces.event.ActionEvent)"/>
<cc:attribute name="render" required="false" />
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
<h:commandButton
id="remove"
actionListener="#{cc.attrs.actionMethod}"
onclick="if (!confirm('Do you really?')) { return false; }">
<f:ajax execute="@this" render="#{cc.attrs.render}" />
</h:commandButton>
</cc:implementation>
</ui:composition>最后但并非最不重要的是,托管bean
Name("myOneCreateAction")
@Scope(ScopeType.CONVERSATION)
public class MyOneCreateAction {
...
public void removeRating(ActionEvent ev) {
// do something
}
...
}令人惊讶的是,当removeButton2正确跳入正确的函数时,复合组件版本返回
javax.faces.event.AbortProcessingException: Target Unreachable,
identifier 'createAction' resolved to null而不是。我正在使用带有Seam 2.3.1.CR1的Mojarra JSF 2.1.26。没有嵌套的复合组件。当将复合组件参数替换为#{myOneCreateAction.removeRating}时,它的工作方式与预期的一样。
有人见过这个吗?我瞎了吗?任何已知的工作.?提前感谢!
发布于 2013-12-16 14:33:36
作为一种解决方案,我重写了组件,将action bean和action方法作为两个单独的参数进行解析,如下所示
xhtml:
<io:removeButton
id="removeButton"
actionBean="#{createAction}"
actionMethod="removeRating"
immediate="true"
render=":#{rich:clientId('ratingTblId')}" />复合构件:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:cc="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<cc:interface>
<cc:attribute name="actionBean" />
<cc:attribute name="actionMethod" />
<cc:attribute name="render" required="false" />
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
<h:commandButton
id="remove"
action="#{cc.attrs.actionBean[cc.attrs.actionMethod]}"
onclick="if (!confirm('Do you really?')) { return false; }">
<f:ajax execute="@this" render="#{cc.attrs.render}" />
</h:commandButton>
</cc:implementation>
</ui:composition>还将操作方法签名更改为返回String而不是void。那看起来不再那么性感了,但是很管用。*-/
发布于 2019-06-20 20:22:08
我也有同样的问题,发现它已经在版本2.2.15:https://github.com/javaserverfaces/mojarra/issues/4271上被修复了
https://stackoverflow.com/questions/20219326
复制相似问题