简体   繁体   English

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

[英]How can I add a new row at the top of my datatable in JSF?

Every time I add a new row in my datatable (via commandbutton "new Feedback") it is added at the bottom of the datatable. 每次我在数据表中添加新行时(通过命令按钮“新反馈”),该行都会添加到数据表的底部。 How can I add it and make sure that it will appear at the top? 如何添加它并确保它显示在顶部?

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

In your action method for the command gettingFeedbackMulti , you are probably doing something like this 在命令gettingFeedbackMulti操作方法中,您可能正在执行以下操作

sentMessagesList.add(message);

Just change it to use add() with index argument like this 只需将其更改为将add()与索引参数一起使用,就像这样

sentMessagesList.add(0, message);

This will add it to index 0 of your list 这会将其添加到列表的索引0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM