A
A
Alexey Kopendakov2018-05-02 11:34:40
Java
Alexey Kopendakov, 2018-05-02 11:34:40

How to properly use foreach loops in jsf?

Good afternoon.
There was such a problem: from the database I get a string of words separated by a comma. In the entity itself (entity) there are links with a one-to-many relationship, so using the DTO pattern does not work (or I just don’t understand how).
When displaying on a page, I need to display each word as a separate link. the roof is already moving, but the result is still no: - I tried to use a separate bin for the transformation -

@Stateless
@ManagedBean(name = "dtFileHelper")
public class FileHelper {
    public List<String> myName(String name) {
        String[] oneName;
        List<String> rez1=new ArrayList<>();
        oneName = name.split(",");
        for (String nam:oneName) {
            rez1.add(nam);
        }
        return rez1;
    }
}

And output:
<p:column headerText="Видеозаписи">
                    <c:forEach var="fname" items="#{dtFileHelper.myName(file.name)}">
                        <h:outputText value="#{fname}"/><br/>
                    </c:forEach>
                </p:column>

But pancake, only the first record is deduced. Although the rez1 list itself is returned correctly.
If you rewrite the bean so that it simply fills the list with fixed values ​​when it is created, then everything is fine - these values ​​are displayed.
in which direction to dig? I understand correctly that there is no debugging in xhtml files?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Kopendakov, 2018-05-02
@alex_kag

In general, it turned out that the problem lies in a slightly different one - the datagrid was initially filled in a lazy style, then I had to use ui: repeat and it all worked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question