1

Good afternoon.

I have the following problem, the end of the attribute value

<c: foreach should vary for each row in the datatable, eh trying with expression language but simply does not work.

This is the code:

<ace:dataTable  value="#{TreeTableBk.rubros}" var="rubro"
                paginator="true" paginatorPosition="bottom" rows="10" style="font-size: 12px; font-family: Tahoma, Verdana, Arial, Sans-Serif">
                <ace:column
                    headerText="Informacion">
                    <div align="left">
                    <h:panelGroup>
                        <c:forEach begin="0" end="#{rubro.nivel}">
                            <h:outputText value="__*"></h:outputText>
                        </c:forEach>
                        <h:inputText 
                        value      = "#{rubro.codigoPadre}"
                        rendered   = "#{rubro.final_ == 'N'}"
                        styleClass = "SMRInputTextNegrilla6" 
                        style      = "background-color:#A5CCE7">
                        </h:inputText>
                    <h:inputText 
                        value      = "#{rubro.codigoPadre}"
                        rendered   = "#{rubro.final_ == 'S'}"
                        styleClass = "SMRInputTextNegrilla6" >
                    </h:inputText>
                    <h:inputText 
                        value      = "#{rubro.codigo}"
                        styleClass = "SMRInputTextNegrilla6" 
                        style      = "background-color:#D1F2C7">
                    </h:inputText>
                    <h:inputText 
                        value      = "#{rubro.descripcion}"
                        styleClass = "SMRInputTextNegrilla6" >
                    </h:inputText>
                    <h:inputText value="#{rubro.nivel}" styleClass="SMRInputTextNegrilla6">
                    </h:inputText>
                    </h:panelGroup>
                    </div>
                </ace:column>
            </ace:dataTable>

Any idea how to resolve this would be helpful.

many Thanks

1 Answers1

1

Tag handlers like <c:forEach> runs during building the view, not during rendering the view. UI components like <h:dataTable> runs during rendering the view, not during building the view. So, at the moment the <c:forEach> runs, the <h:dataTable> isn't running and thus its var="rubro" is never available in the EL scope and thus #{rubro} inside <c:forEach> always evaluates as null.

So, the <c:forEach> is completely out of the question for this particular functional requirement. Your best bet is using the <ui:repeat>. This does however not support anything like the begin and end attribute of the <c:forEach>. You could however create a custom EL function which creates a dummy array of the given size and then feed it to <ui:repeat value>.

E.g.

<ui:repeat value="#{my:createArray(robro.nivel)}">
    <h:outputText value="__*" />
</ui:repeat>

with

public static Object[] createArray(int size) {
    return new Object[size];
}

The JSF utility library OmniFaces has an of:createArray() function for exactly this purpose, see also the of:createArray() showcase example.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555