如何将动作结果传递给 jsf 组合?
How to pass around action outcome to jsf composition?
我有这个 JSF 片段,它运行良好。单击命令按钮时,它应该通过重定向到自身来重新加载页面。
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, module)}"
**action="mypage.jsf?faces-redirect=true"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
因为我想在多个页面中重复使用它,所以我尝试制作这个 JSF 模板并通过 ui:include
包含它。唯一的问题是我需要根据使用的页面来配置操作。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, module)}"
**action="#{redirectTo}"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
</ui:composition>
包含
<ui:include src="moduleSettingImportDialog.xhtml">
<ui:parameter name="redirectTo" value="mypage.jsf?faces-redirect=true"/>
</ui:include>
我得到的错误类似于
javax.el.ELException: Not a Valid Method Expression: #{redirectTo}
at
com.sun.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBuilder.java:311)
at
com.sun.el.ExpressionFactoryImpl.createMethodExpression(ExpressionFactoryImpl.java:96)
at
org.jboss.weld.util.el.ForwardingExpressionFactory.createMethodExpression(ForwardingExpressionFactory.java:43)
at
org.jboss.weld.el.WeldExpressionFactory.createMethodExpression(WeldExpressionFactory.java:53)
at
com.sun.faces.facelets.tag.TagAttributeImpl.getMethodExpression(TagAttributeImpl.java:240)
at
com.sun.faces.facelets.tag.jsf.ActionSourceRule$ActionMapper2.applyMetadata(ActionSourceRule.java:107)
at
com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
我在使用 JSF 复合组件时遇到类似的错误。
<c:interface>
<c:attribute name="module"/>
<c:attribute name="redirectTo" type="java.lang.String"/>
</c:interface>
<c:implementation rendered="#{systemSettingModel.LOG_REASON_FOR_CHANGES_ISAKTIV}">
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, cc.attrs.module)}"
**action="#{cc.attrs.redirectTo}"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
</c:implementation>
#{cc.attrs.redirectTo}: javax.el.ELException:
java.lang.IllegalArgumentException: Cannot convert
multimodulesettings.jsf?faces-redirect=true&includeViewParams=true of
type class java.lang.String to class javax.el.MethodExpression
javax.faces.FacesException: #{cc.attrs.redirectTo}:
javax.el.ELException: java.lang.IllegalArgumentException: Cannot
convert
multimodulesettings.jsf?faces-redirect=true&includeViewParams=true of
type class java.lang.String to class javax.el.MethodExpression at
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
at javax.faces.component.UICommand.broadcast(UICommand.java:315) at
javax.faces.component.UIData.broadcast(UIData.java:1108) at
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at
org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at
org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:295)
如何将固定字符串传递给在 commandButton 的 action 属性中使用的 JSF 模板或复合组件?
作为一种解决方法,我实现了一个 JSF bean 方法,它只是 returns 传入的字符串,就像这样。
public String echo(String s) {
return s;
}
然后不是将修复字符串作为参数传递给组件,而是通过 EL 表达式传递它。
<ui:include src="moduleSettingImportDialog.xhtml">
<ui:parameter name="redirectTo" value="#{jsfBean.echo('mypage.jsf?faces-redirect=true')}"/>
</ui:include>
我有这个 JSF 片段,它运行良好。单击命令按钮时,它应该通过重定向到自身来重新加载页面。
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, module)}"
**action="mypage.jsf?faces-redirect=true"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
因为我想在多个页面中重复使用它,所以我尝试制作这个 JSF 模板并通过 ui:include
包含它。唯一的问题是我需要根据使用的页面来配置操作。
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, module)}"
**action="#{redirectTo}"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
</ui:composition>
包含
<ui:include src="moduleSettingImportDialog.xhtml">
<ui:parameter name="redirectTo" value="mypage.jsf?faces-redirect=true"/>
</ui:include>
我得到的错误类似于
javax.el.ELException: Not a Valid Method Expression: #{redirectTo} at com.sun.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBuilder.java:311) at com.sun.el.ExpressionFactoryImpl.createMethodExpression(ExpressionFactoryImpl.java:96) at org.jboss.weld.util.el.ForwardingExpressionFactory.createMethodExpression(ForwardingExpressionFactory.java:43) at org.jboss.weld.el.WeldExpressionFactory.createMethodExpression(WeldExpressionFactory.java:53) at com.sun.faces.facelets.tag.TagAttributeImpl.getMethodExpression(TagAttributeImpl.java:240) at com.sun.faces.facelets.tag.jsf.ActionSourceRule$ActionMapper2.applyMetadata(ActionSourceRule.java:107) at com.sun.faces.facelets.tag.MetadataImpl.applyMetadata(MetadataImpl.java:81)
我在使用 JSF 复合组件时遇到类似的错误。
<c:interface>
<c:attribute name="module"/>
<c:attribute name="redirectTo" type="java.lang.String"/>
</c:interface>
<c:implementation rendered="#{systemSettingModel.LOG_REASON_FOR_CHANGES_ISAKTIV}">
<p:dataTable value="#{fileModel.files}"
var="file" scrollable="true" scrollHeight="400">
<p:column headerText="#{msgs.lbl_file}">
#{file.name}
</p:column>
<p:column width="150">
<p:commandButton value="#{msgs.lbl_import}"
actionListener="#{fileModel.importFile(file, cc.attrs.module)}"
**action="#{cc.attrs.redirectTo}"**/>
</p:column>
<p:column width="150">
<p:commandLink value="#{msgs.lbl_view}" target="_blank" ajax="false"
actionListener="#{fileModel.view(file)}"/>
</p:column>
</p:dataTable>
</c:implementation>
#{cc.attrs.redirectTo}: javax.el.ELException: java.lang.IllegalArgumentException: Cannot convert multimodulesettings.jsf?faces-redirect=true&includeViewParams=true of type class java.lang.String to class javax.el.MethodExpression javax.faces.FacesException: #{cc.attrs.redirectTo}: javax.el.ELException: java.lang.IllegalArgumentException: Cannot convert multimodulesettings.jsf?faces-redirect=true&includeViewParams=true of type class java.lang.String to class javax.el.MethodExpression at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIData.broadcast(UIData.java:1108) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:295)
如何将固定字符串传递给在 commandButton 的 action 属性中使用的 JSF 模板或复合组件?
作为一种解决方法,我实现了一个 JSF bean 方法,它只是 returns 传入的字符串,就像这样。
public String echo(String s) {
return s;
}
然后不是将修复字符串作为参数传递给组件,而是通过 EL 表达式传递它。
<ui:include src="moduleSettingImportDialog.xhtml">
<ui:parameter name="redirectTo" value="#{jsfBean.echo('mypage.jsf?faces-redirect=true')}"/>
</ui:include>