在给定的情况下,我想使用具有不同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>
我将创建操作作为参数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
代替。使用Mojarra JSF 2.1.26和Seam 2.3.1.CR1。没有嵌套的复合组件。将复合组件参数替换为#{myOneCreateAction.removeRating}
时,它的工作方式与预期相同。
以前有人见过这个吗?我瞎了吗?任何已知的解决方法......?提前谢谢!
答案 0 :(得分:0)
我遇到了同样的问题,发现它已在2.2.15版中修复: https://github.com/javaserverfaces/mojarra/issues/4271