不使用表达式</ui:include>在jsf2中使用<ui:include src =“page.xhtml”>发送参数

时间:2014-07-14 11:00:19

标签: jsf el facelets jsf-2.2

当我使用像value =“#{value}”这样的表达式时,我试图在后端传递一些参数,包括UI但不传递参数。但我可以发送带有普通字符串的参数,例如value =“value”。

<ui:include src="index_1.xhtml">
      <ui:param name="action1" value="#{o.columnId}" />
      <ui:param name="action2" value="#{o.columnType}" />
</ui:include> <br/>

但我可以用

传递参数
<ui:include src="index_1.xhtml">
      <ui:param name="action1" value="Value1" />
      <ui:param name="action2" value="Value2" />
</ui:include> <br/>

的index.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>TODO supply a title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    </h:head>
    <h:body>
        <h:form>
            <ui:repeat value="#{myBean.models}" var="o">
                <ui:include src="index_1.xhtml">
                    <ui:param name="action1" value="#{o.columnId}" />
                    <ui:param name="action2" value="#{o.columnType}" />
                </ui:include> <br/>
                <ui:include src="index_2.xhtml"> 
                    <ui:param name="action1" value="#{o.columnId}" />
                    <ui:param name="action2" value="#{o.columnType}" />
                </ui:include><br/>
                <ui:include src="index_3.xhtml">
                    <ui:param name="action1" value="#{o.columnId}" />
                    <ui:param name="action2" value="#{o.columnType}" />
                </ui:include><br/>
            </ui:repeat>
            <p:commandButton value="Submit" action="#{myBean.submitForm}" />
        </h:form>
    </h:body>
</html>

index_1.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>TODO supply a title</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    </h:head>
    <h:body>
        <f:event listener="#{myBean.ajaxEventForObjectNo(action1, action2)}" type="preRenderView" />
        <h:outputLabel>Single Line Text</h:outputLabel>
        <p:inputText value="#{myBean.models[myBean.objectNo].columnId}" />
    </h:body>    
</html>

感谢。

1 个答案:

答案 0 :(得分:1)

问题是,就像@XtremeBiker已经说过的那样,ui:includeui:repeat之前执行。更确切地说,ui:include查看构建时间执行,而ui:repeat查看渲染时评估。

因此o的{​​{1}}属性定义的变量var尚未初始化。因此,它评估为ui:repeat

可能的替代方法是使用nullc:forEach是JSTL标记处理程序,在查看构建时下执行。不过这就是@BalusC has to say关于那个:

  

c:forEach替换<ui:repeat>应解决此问题。然而,它可能具有不希望的副作用。由于您的具体功能要求尚不完全清楚,因此很难预先说明。

不完全确定他在那里提到的副作用。但是,我还没有遇到任何问题,将<c:forEach>替换为<ui:repeat>

以下是关于该主题的非常好的阅读:JSTL in JSF2 Facelets... makes sense?