【发布时间】:2020-01-18 08:56:45
【问题描述】:
我有这个工作正常的 JSF sn-p。单击命令按钮时,它应该通过重定向到自身来重新加载页面。
<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:不是有效的方法表达式:#{redirectTo} 在 com.sun.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBuilder.java:311) 在 com.sun.el.ExpressionFactoryImpl.createMethodExpression(ExpressionFactoryImpl.java:96) 在 org.jboss.weld.util.el.ForwardingExpressionFactory.createMethodExpression(ForwardingExpressionFactory.java:43) 在 org.jboss.weld.el.WeldExpressionFactory.createMethodExpression(WeldExpressionFactory.java:53) 在 com.sun.faces.facelets.tag.TagAttributeImpl.getMethodExpression(TagAttributeImpl.java:240) 在 com.sun.faces.facelets.tag.jsf.ActionSourceRule$ActionMapper2.applyMetadata(ActionSourceRule.java:107) 在 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:无法转换 multimodulesettings.jsf?faces-redirect=true&includeViewParams=true 的 将类 java.lang.String 输入到类 javax.el.MethodExpression javax.faces.FacesException:#{cc.attrs.redirectTo}: javax.el.ELException:java.lang.IllegalArgumentException:不能 转变 multimodulesettings.jsf?faces-redirect=true&includeViewParams=true 的 键入 class java.lang.String 到 class javax.el.MethodExpression at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) 在 javax.faces.component.UICommand.broadcast(UICommand.java:315) 在 javax.faces.component.UIData.broadcast(UIData.java:1108) 在 javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) 在 javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) 在 com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 在 com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 在 com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) 在 javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) 在 org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 在 org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:78) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) 在 org.glassfish.tyrus.servlet.TyrusServletFilter.doFilter(TyrusServletFilter.java:295)
如何将固定字符串传递给 JSF 模板或在 commandButton 的 action 属性中使用的复合组件?
【问题讨论】:
-
不是重复的,但这可能会有所帮助:Composite component with optional method expression
-
它可以与
h:commandButton和f:ajax一起使用吗?
标签: jsf glassfish-4