Line break in data from a list

0

I have a dialog that shows on the screen the data received from a list:

<p:dialog header="#{zona.nome}" widgetVar="vendedores" minHeight="40">
    <h:outputText value="#{zonaBean.getVendedoresPorZona(zona.id)}"/> <br />
</p:dialog>

When this dialog is displayed, all the information appears on the same line, and I wanted it to be a die on each line.

Does anyone know how I can do this?

    
asked by anonymous 07.12.2016 / 20:12

2 answers

1

Since you did not specify what you are going to do with the list (I believe it is only for display, but the same logic applies to other structures - checkboxes, for example), there are several possible solutions (assuming that getVendersPorZona returns a list of String). In the examples, I'm using the outputText of your question for didactic purposes:

By Repeat (allows greater flexibility, not being restricted to a specific output):

<p:dialog header="#{zona.nome}" widgetVar="vendedores" minHeight="40">
    <ui:repeat value="#{zonaBean.getVendedoresPorZona(zona.id)}" var="v">
        <h:outputText value="#{v}"/><br />
    </ui:repeat>
</p:dialog>

By Repeat of Primefaces:

<p:dialog header="#{zona.nome}" widgetVar="vendedores" minHeight="40">
    <p:repeat value="#{zonaBean.getVendedoresPorZona(zona.id)}" var="v">
        <h:outputText value="#{v}"/><br />
    </p:repeat>
</p:dialog>

By Datafist of Primefaces:

<p:dialog header="#{zona.nome}" widgetVar="vendedores" minHeight="40">
    <p:dataList value="#{zonaBean.getVendedoresPorZona(zona.id)}" var="v" itemType="disc">
        <h:outputText value="#{v}"/>
    </p:dataList>
</p:dialog>

By DataTable of Primefaces (useful when having an object with multiple attributes):

<p:dialog header="#{zona.nome}" widgetVar="vendedores" minHeight="40">
    <p:dataTable value="#{zonaBean.getVendedoresPorZona(zona.id)}" var="v">
        <p:column headerText="Vendedor">
            <h:outputText value="#{v}"/>
        </p:column>
    </p:dataTable>
</p:dialog>

By ForEach (formerly exemplified by @ arthur-vidal):

<p:dialog header="#{zona.nome}" widgetVar="vendedores" minHeight="40">
    <c:forEach var="v" items="${zonaBean.getVendedoresPorZona(zona.id)}">
        <h:outputText value="#{v}"/><br />
    </c:forEach>
</p:dialog>
    
12.12.2016 / 13:49
1

I imagine you're displaying everything on the same line because the "< / br >" is executed only once and after displaying the outputText. It tries to put the return of this list inside a forEach.

Example:

<p:dialog header="#{zona.nome}" widgetVar="vendedores" minHeight="40">    
    <c:forEach  items="#{zonaBean.getVendedoresPorZona(zona.id)}" var="row"  
       <h:outputText value="row"/> <br />
    </c:forEach>
</p:dialog>    
    
09.12.2016 / 19:01