Jsf ui: retry size doesn't get java bean value

JSF 2.0 ui: repeat tag gets the java bean (arraylist) value as the value property, but the size property doesn't. I use ui repeat inside a datatable that shows states iteratively, and ui repeat shows comments for each state. I am giving a ui repeat size property from a java class, because each status has a different number of comments. Therefore, the size should be determined dynamically. Here is a summary of what I have done. Model classes:

@ManagedBean
@RequestScoped
public class Comment {
     private String commentAuthorName;
//getter and setter
}

This represents a state class that has a list of comments:

@ManagedBean
@RequestScoped
public class Status {
    private ArrayList<Comment> commentList;
    private int numOfComments;
//getter and setter
}

This gives an idea of ​​the StatusBean class:

@ManagedBean
@SessionScoped
public class StatusBean {
    List<Status> panelList = new ArrayList<Status>();
    List<Comment> commentList = new ArrayList<Comment>();
    public static void process() {
        panelList = StatusService.getPersonalStatus(log.getLoggeduser());//means fill list
        commentList = StatusService.getPersonalComments(panelList);//gets comments via related statuses
        for (int i=0; i<panelList.size(); i++) { //for each status
             Status status = panelList.get(i);
             for(Comment comment : commentList) { //for each comment of each status
             status.setNumOfCommentsShown(1);
           }
        }
    }
}

, . Ui PrimeFaces DataTable, . datatable, , , ui repeat .

<p:dataTable liveScroll="true" value="#{StatusBean.panelList}" 
             var="Status" scrollable="true">
   <ui:repeat var="Comment" value="#{Status.commentList}" 
           size="#{Status.numOfComments}"></ui:repeat>
</p:dataTable>

, # {Status.numOfComments} , . size = 3 , .

+1
1

, , , .

, , <ui:repeat> size, bean, . EL, . , EL #{5}. , , , , , , , ?

, JSF <ui:repeat>, . , .

, .

, . <ui:repeat>, . JSF bean . <ui:param> <ui:fragment>. .

:

<p:dataTable value="#{statusBean.statusesList}" var="status">
    <p:column headerText="Status name">
        <h:outputText value="#{status.statusName}"/>
    </p:column>
    <p:column headerText="Status comments">
        <ul>
            <ui:param name="max" value="#{status.numOfComments}"/>
            <ui:repeat var="comment" value="#{status.commentList}" varStatus="statusVar">
                <ui:fragment rendered="#{statusVar.index lt max}">
                    <li>
                        <h:outputText value="Author: #{comment.authorName}; comment: #{comment.description}"/>
                    </li>
                </ui:fragment>
            </ui:repeat>
        </ul>
    </p:column>
</p:dataTable>

:

public class Comment {

    private String authorName;
    private String description;

}

public class Status {

    private List<Comment> commentList;
    private int numOfComments;
    private String statusName;

}

bean:

@ManagedBean
@RequestScoped
public class StatusBean {

    private List<Status> statusesList;

    public StatusBean() {
        Status status;
        List<Status> statusesList = new ArrayList<Status>();
        Comment comment;
        List<Comment> commentList;
        for(int s = 0; s < 10; s++) {
            commentList = new ArrayList<Comment>();
            for(int c = 0; c < 20; c++) {
                commentList.add(new Comment("User " + (s + 1) + "-" + (c + 1), "Description for comment " + (s + 1) + "-" + (c + 1)));
            }
            statusesList.add(new Status(commentList, (s + 1), "Status " + (s + 1)));
        }
        this.statusesList = statusesList;
    }

}

,

, , , .

  • : @ManagedBean @...Scoped () @Entity , bean;
  • , . bean: , Status;
  • beans, () (Servlet 3.0) preRenderView (Servlet 2.5) @PostConstruct. bean. BalusC ;
  • : , ? , (, " ", ajax ). size="...";
  • , Primefaces, Luiggi Mendoza.

bean :

@ManagedBean
@RequestScoped
public class StatusBean {

    private List<Status> statusesList;

    @EJB
    private StatusService statusService;

    @ManagedProperty(value="#{user}")
    private User user;

    @PostConstruct
    public void init() {
        statusesList = statusService.getStatuses(user);
    }

    public List<Status> getStatusesList() {
        return statusesList;
    }

}
+5

All Articles