【问题标题】:Problem with c:forEach inside rich:dataTablec:forEach 在rich:dataTable 中的问题
【发布时间】:2011-11-23 15:35:42
【问题描述】:

我有这个页面:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
    template="./templates/template.xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:c="http://java.sun.com/jstl/core">

    <ui:define name="main_title">AO MMS Messages</ui:define>
    <ui:define name="main">
    <rich:dataTable value="#{dataProviderBean.aoRequests}" var="item">
        <f:facet name="noData">No messages are available.</f:facet>
        <rich:column>
            <f:facet name="header">Profile</f:facet>
               #{item.profile.username}
           </rich:column>
        <rich:column>
            <f:facet name="header">Timestamp</f:facet>
               #{item.timestamp}
           </rich:column>
        <rich:column>
            <f:facet name="header">Recipient</f:facet>
               #{item.recipient}
           </rich:column>
        <rich:column>
            <f:facet name="header">Sender</f:facet>
               #{item.sender}
           </rich:column>
        <rich:column>
            <f:facet name="header">Text</f:facet>
            <h:outputText value="Contents: #{item.getContentByStringType('text/plain')}" />
               <c:forEach var="content" items="#{item.getContentByStringType('text/plain')}">
                <h:outputText value="Content: #{content}" />
               </c:forEach>
           </rich:column>
        <rich:column>
            <f:facet name="header">Headers</f:facet>
               #{item.headers}
           </rich:column>
    </rich:dataTable>
    </ui:define>
</ui:composition>

Text 列仅打印以下内容:

Contents: [TextContent [content=Hello World in MMS]] Content:

为什么不遍历列表?

请求课程以获取更多信息:

public class Request {

    private Profile profile;
    private Map<String, String> headers;
    private Date timestamp;
    private MessageType messageType;
    private Map<String, ArrayList<Content>> contents;

    public Request(MessageType messageType) {
        this.messageType = messageType;
        this.timestamp = new Date();
    }

    public Profile getProfile() {
        return profile;
    }

    public void setProfile(Profile profile) {
        this.profile = profile;
    }

    public Map<String, String> getHeaders() {
        return headers;
    }

    public void setHeaders(Map<String, String> headers) {
        this.headers = headers;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public MessageType getMessageType() {
        return messageType;
    }

    public void setMessageType(MessageType messageType) {
        this.messageType = messageType;
    }

    public Map<String, ArrayList<Content>> getContents() {
        return contents;
    }

    public void setContents(Map<String, ArrayList<Content>> contents) {
        this.contents = contents;
    }

    public List<Content> getContentByStringType(String type) {
        return contents.get(type);
    }

    public String getSender() {
        return headers.get(HttpHeaders.X_NOKIA_MMSC_FROM.getValue()).replaceAll("/.*", "");
    }

    public String getRecipient() {
        return headers.get(HttpHeaders.X_NOKIA_MMSC_TO.getValue()).replaceAll("/.*", "");
    }

    @Override
    public String toString() {
        return "Request [profile=" + profile + ", headers=" + headers + ", timestamp=" + timestamp
                + ", messageType=" + messageType + ", contents=" + contents + "]";
    }

}

【问题讨论】:

    标签: java jsf richfaces jstl


    【解决方案1】:

    在这种情况下使用ui:repeat 而不是c:forEach

    c:forEach在这里不起作用,因为您试图引用未定义的 var itemc:forEachTagHandler,因此它试图在构建树时评估 item;@ 987654329@ 是一个组件,它仅在渲染响应中定义 var item

    有关此问题的更多信息,您可以阅读以下文章:. TagHandler vs Component

    【讨论】:

      猜你喜欢
      • 2011-01-10
      • 2011-02-24
      • 2014-01-05
      • 1970-01-01
      • 2011-12-18
      • 2012-12-04
      • 1970-01-01
      • 2012-01-14
      • 2014-03-26
      相关资源
      最近更新 更多