in jsf2 with expression 的参数-6ren"> in jsf2 with expression 的参数-我试图通过 UI include 在后端传递一些参数,但当我使用 value = "#{value}"等表达式时,它不会传递参数。但我可以使用普通字符串(如 value="value")发送参数。 -6ren">
gpt4 book ai didi

jsf - 不发送带有 in jsf2 with expression 的参数

转载 作者:行者123 更新时间:2023-12-02 04:33:52 29 4
gpt4 key购买 nike

我试图通过 UI include 在后端传递一些参数,但当我使用 value = "#{value}"等表达式时,它不会传递参数。但我可以使用普通字符串(如 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/>

索引.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>

谢谢。

最佳答案

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

你的变量ovar 定义ui:repeat 的属性因此尚未初始化。因此,它的计算结果为 null .

一个可能的替代方案是使用 c:forEachc:forEach是一个 JSTL 标记处理程序,在 View 构建时执行。然而这就是@BalusC has to say关于这一点:

Replacing <ui:repeat> by <c:forEach> should fix this issue. It may however have undesireable side effects. It's hard to tell beforehand as your concrete functional requirements are not fully clear.

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

这里还有一篇关于该主题的非常好的读物:JSTL in JSF2 Facelets... makes sense?

关于jsf - 不发送带有 <ui :include src ="page.xhtml"> in jsf2 with expression 的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24735057/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com