如何将动作结果传递给jsf组成?

问题描述 投票:0回答:1

我有这个运行良好的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.E​​LException:无效的方法表达式:#{redirectTo}在com.sun.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBuilder.java:311)在com.sun.el.E​​xpressionFactoryImpl.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.E​​LException:java.lang.IllegalArgumentException:无法转换multimodulesettings.jsf?faces-redirect = true&includeViewParams = true的将类java.lang.String键入类javax.el.MethodExpressionjavax.faces.FacesException:#{cc.attrs.redirectTo}:javax.el.E​​LException:java.lang.IllegalArgumentException:无法兑换multimodulesettings.jsf?faces-redirect = true&includeViewParams = true的在类javax.el.MethodExpression处输入类java.lang.Stringcom.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)

如何将固定的字符串传递给在CommandButton的action属性中使用的JSF模板或复合组件?

jsf glassfish-4
1个回答
0
投票

作为一种解决方法,我实现了一个JSF bean方法,它只返回像这样传递的字符串。

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>
© www.soinside.com 2019 - 2024. All rights reserved.