【问题标题】:How can I add a new row at the top of my datatable in JSF?如何在 JSF 的数据表顶部添加新行?
【发布时间】:2017-12-11 22:37:49
【问题描述】:

每次我在数据表中添加新行(通过命令按钮“新反馈”)时,它都会添加到数据表的底部。如何添加它并确保它出现在顶部?

<h:form>
    <h:inputText value="#{helloBean.content}" ></h:inputText>
    <h:commandButton value="send message"
        action="#{helloBean.multiAufruf}">
    </h:commandButton>
    <h:commandButton value="new Feedback"
        action="#{helloBean.gettingFeedbackMulti}">
    </h:commandButton>

    <h:dataTable value="#{helloBean.sentMessagesList}" var="message">
        <h:column>
            <h:inputText value="#{message.content}"></h:inputText>
        </h:column>
        <h:column>
            <h:outputText value="#{message.time}"></h:outputText>
        </h:column>
        <h:column>
            <h:outputText value="#{message.idList}"></h:outputText>
        </h:column>
        <h:column>
            <h:outputText value="#{message.feedbackz}"></h:outputText>
        </h:column>
    </h:dataTable>
</h:form>

【问题讨论】:

    标签: java jsf datatable row


    【解决方案1】:

    在命令gettingFeedbackMulti 的操作方法中,您可能正在执行类似的操作

    sentMessagesList.add(message);
    

    只需将其更改为使用add() 和这样的索引参数

    sentMessagesList.add(0, message);
    

    这会将它添加到列表的索引 0

    【讨论】:

      猜你喜欢
      • 2010-09-25
      • 1970-01-01
      • 1970-01-01
      • 2011-11-25
      • 1970-01-01
      • 2014-08-28
      • 1970-01-01
      • 2019-08-05
      • 1970-01-01
      相关资源
      最近更新 更多