我正在运行 Tomcat 7、JSF 2.2、OpenWebBeans 1.6、Omnifaces 1.8 和 Richfaces 3。我最近添加了 Omnifaces CombinedResourceHandler,并注意到它会导致调用数据表的 value 方法,尽管该方法位于未渲染块中,当页面上的表单已提交。
例子:
<h:body styleClass="bdyPage">
<h:form id="form">
<h:commandButton value="test button" />
<h:panelGroup rendered="false">
<h:outputText value="#{testBean.getTestString()}" />
<h:dataTable id="testtable22" value="#{testBean.strings}" var="str"
rowClasses="odd, even">
<h:column>
<f:facet name="header">
test
</f:facet>
<h:outputText value="str" />
</h:column>
</h:dataTable>
</h:panelGroup>
</h:form>
</h:body>
我有一个简单的测试bean:
@Named("testBean")
@RequestScoped
public class TestBean1 implements Serializable {
private static final long serialVersionUID = 1L;
public String getTestString() {
System.out.println("Test string");
return "test string";
}
public List<String> getStrings() {
List<String> strings = new ArrayList<String>();
strings.add("hej");
strings.add("hejsan");
strings.add("hej hej!");
System.out.println("getting strings");
return strings;
}
}
通常,不会调用 getStrings(),因为 panelGroup 设置为不呈现。但是,当我同时运行Omnifaces CombinedResourceHandler 和 Richfaces 时,多次按下提交按钮时会调用 getStrings()。这似乎只影响 h:dataTable 组件的 value 属性。其他 el 表达式不会被调用。
我建立了一个带有以下 maven 依赖项的小示例项目:
<dependencies>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>4.3.7.Final</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>4.3.7.Final</version>
</dependency>
<!-- <dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces</artifactId>
<version>5.0.0.Alpha3</version>
</dependency>
-->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<type>jar</type>
<classifier>sources</classifier>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-impl</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-jsf</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-el22</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.openwebbeans</groupId>
<artifactId>openwebbeans-web</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.6</version>
</dependency>
</dependencies>
我没有在项目或测试页面上使用任何richfaces 组件。我只是将 Richfaces 作为依赖项包括在内。我没有任何组合在一起的javascript。如果我禁用 Omnifaces CRH 或从 pom 文件中删除 Richfaces,它会按预期工作。
我尝试使用 Richfaces 5,但在那里我得到了类似的行为(尽管 getter 被调用的次数更少)。我没有尝试过最新的 Omnifaces 版本,因为它与 OWB 1.6 不兼容。
另一个有趣的地方可能是,如果我用 JSTL 包围数据表<c:if>
,它就可以工作。但我不想这样做,显然......
我在这里做错了吗?这些版本的 Omnifaces CRH 和 Richfaces 之间是否存在兼容性问题?
编辑:从数据表的 getter 调用堆栈
TestBean1.getStrings() line: 33
TestBean1$$OwbNormalScopeProxy0.getStrings() line: not available
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available
Method.invoke(Object, Object...) line: not available
BeanELResolver.getValue(ELContext, Object, Object) line: 87
DemuxCompositeELResolver._getValue(int, ELResolver[], ELContext, Object, Object) line: 176
DemuxCompositeELResolver.getValue(ELContext, Object, Object) line: 203
AstValue.getValue(EvaluationContext) line: 183
ValueExpressionImpl.getValue(ELContext) line: 185
WrappedValueExpression.getValue(ELContext) line: 70
TagValueExpression.getValue(ELContext) line: 109
ComponentStateHelper.eval(Serializable, Object) line: 194
ComponentStateHelper.eval(Serializable) line: 182
HtmlDataTable(UIData).getValue() line: 732
HtmlDataTable(UIData).getDataModel() line: 1822
HtmlDataTable(UIData).setRowIndexWithoutRowStatePreserved(int) line: 484
HtmlDataTable(UIData).setRowIndex(int) line: 473
HtmlDataTable(UIData).visitColumnsAndColumnFacets(VisitContext, VisitCallback, boolean) line: 2104
HtmlDataTable(UIData).visitTree(VisitContext, VisitCallback) line: 1446
HtmlPanelGroup(UIComponent).visitTree(VisitContext, VisitCallback) line: 1701
HtmlForm(UIComponent).visitTree(VisitContext, VisitCallback) line: 1701
HtmlForm(UIForm).visitTree(VisitContext, VisitCallback) line: 371
HtmlBody(UIComponent).visitTree(VisitContext, VisitCallback) line: 1701
UIViewRoot(UIComponent).visitTree(VisitContext, VisitCallback) line: 1701
FaceletViewHandlingStrategy.locateComponentByClientId(FacesContext, String) line: 2082
FaceletViewHandlingStrategy.reapplyDynamicRemove(FacesContext, ComponentStruct) line: 2174
FaceletViewHandlingStrategy.reapplyDynamicActions(FacesContext) line: 2116
FaceletViewHandlingStrategy.buildView(FacesContext, UIViewRoot) line: 966
RenderResponsePhase.execute(FacesContext) line: 99
RenderResponsePhase(Phase).doPhase(FacesContext, Lifecycle, ListIterator<PhaseListener>) line: 101
LifecycleImpl.render(FacesContext) line: 219
FacesServlet.service(ServletRequest, ServletResponse) line: 647
ApplicationFilterChain.internalDoFilter(ServletRequest, ServletResponse) line: 305
ApplicationFilterChain.doFilter(ServletRequest, ServletResponse) line: 210
StandardWrapperValve.invoke(Request, Response) line: 222
StandardContextValve.invoke(Request, Response) line: 123
NonLoginAuthenticator(AuthenticatorBase).invoke(Request, Response) line: 472
StandardHostValve.invoke(Request, Response) line: 171
ErrorReportValve.invoke(Request, Response) line: 99
AccessLogValve.invoke(Request, Response) line: 936
StandardEngineValve.invoke(Request, Response) line: 118
CoyoteAdapter.service(Request, Response) line: 407
Http11Processor(AbstractHttp11Processor).process(SocketWrapper<S>) line: 1004
Http11Protocol$Http11ConnectionHandler(AbstractProtocol$AbstractConnectionHandler).process(SocketWrapper<S>, SocketStatus) line: 589
JIoEndpoint$SocketProcessor.run() line: 312
ThreadPoolExecutor(ThreadPoolExecutor).runWorker(ThreadPoolExecutor$Worker) line: not available
ThreadPoolExecutor$Worker.run() line: not available
TaskThread(Thread).run() line: not available [local variables unavailable]