如何在JSF中的数据表顶部添加新行?

时间:2017-07-07 15:02:02

标签: java jsf datatable row

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

<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>

1 个答案:

答案 0 :(得分:1)

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

sentMessagesList.add(message);

只需将其更改为使用带有索引参数的add()

sentMessagesList.add(0, message);

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