Reputation: 1651
I am trying to pass some parameters in back end with UI include but not its not passing params when I am using expression like value = "#{value}". But I am able to send with params with normal string like 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/>
But I can pass params with
<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>
Thanks.
Upvotes: 3
Views: 1372
Reputation: 1729
The problem is, like @XtremeBiker already said, that ui:include
is executed before ui:repeat
. More precisely, ui:include
is executed at view build time, while ui:repeat
is evaluated at view render time.
Your variable o
defined by the var
attribute of ui:repeat
is thus not yet initialized. It therefore evaluates to null
.
A possible alternative is to use c:forEach
. c:forEach
is a JSTL Tag Handler and is executed at view build time. However that is what @BalusC has to say about that:
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.
Not exactly sure what side effects he mentioned there. However, I had no problems yet, replacing <ui:repeat>
by <c:forEach>
.
Here is also a very good read about that topic: JSTL in JSF2 Facelets... makes sense?
Upvotes: 1