3

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.

Aaron Gotreaux
  • 273
  • 2
  • 4
  • 10
MRX
  • 1,611
  • 8
  • 33
  • 55
  • 2
    `ui:repeat` is evaluated after `ui:include`, that's why you don't have the params you're iterating over yet. Replace the `ui:repeat` by `c:forEach`. – Aritz Jul 14 '14 at 11:43
  • That's true. You have to take care about JSTL and JSF tags together. However, there's no other way to iterate over a collection including xhtml content. You should think about changing that plain xhtml for a composite component, it seems it suits better your case. – Aritz Jul 14 '14 at 12:02
  • Yes. Composite Component Would Be Best. – MRX Jul 14 '14 at 12:24

1 Answers1

1

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?

Community
  • 1
  • 1
Angelo.Hannes
  • 1,729
  • 1
  • 18
  • 46