Line break in data from a list

Asked

Viewed 644 times

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 information appears on the same line, and I wanted it to be a given on each line.

Someone knows how I do it?

  • I believe that the String you want to show already has line breaks. In this case use a <p:inputTextArea /> instead of outputText.

  • Have you tried using the dataList? http://www.primefaces.org/showcase/ui/data/dataList.xhtml

2 answers

1


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

By Repeat (allows greater flexibility, not 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>

For Repeat of the 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>

For Datalist of the 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>

For Datatable Primefaces (useful when you have 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 (previously 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>

1

I imagine you are displaying everything on the same line because "< /br >" runs only once and after displaying outputText. Try to put the return of that 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>    

Browser other questions tagged

You are not signed in. Login or sign up in order to post.