简体   繁体   English

将行组件动态添加到JSF 2 dataTable

[英]Dynamically adding row component to JSF 2 dataTable

I have a dataTable where each row represents an auction item, and a Bid button next to each item. 我有一个dataTable,其中每一行代表一个拍卖项目,并且每个项目旁边都有一个Bid按钮。 When the user clicks the button I need to show a little bidding component with an input text, and a button to submit the bid. 当用户单击按钮时,我需要显示一个带有输入文本的小投标组件,以及一个用于提交投标的按钮。 This "bidding" component needs to be right under the auction item the user is bidding on. 该“出价”组件必须位于用户要出价的拍卖项下。

With regular HTML this is simple: just have another row, conditionally rendered under the auction item row. 使用常规HTML,这很简单:只需在拍卖项目行下有条件地显示另一行即可。 I know how to do this. 我知道该怎么做。

But dataTable is based on columns, and I need to dynamically render not a column, but a row (with colspan equals the number of columns in this dataTable.) 但是dataTable基于列,因此我需要动态地呈现的不是行,而是行(colspan等于此dataTable中的列数)。

(I'm not sure if this is clear enough so I'll try saying it in other words: the dynamically inserted row does not have another auction item. It has a couple of other widgets.) (我不确定这是否足够清楚,所以我将尝试用其他方式说出来:动态插入的行没有其他拍卖品。它有几个其他小部件。)

Is there a way to do this? 有没有办法做到这一点?

I don't think you can achieve what you want with only original JSF's tags. 我认为仅凭原始JSF的标签就无法实现所需的功能。 In fact, it may be very difficult for you to develop such composite component on your own. 实际上,您可能很难自行开发此类复合组件。

Fortunately, if you take a look at PrimeFaces's <p:dataTable> , you will see a feature called ExpandableRows . 幸运的是,如果您看一下PrimeFaces的<p:dataTable> ,将会看到一个名为ExpandableRows的功能。 Your table should look like this: 您的表应如下所示:

<h:form>  
    <p:dataTable var="item" value="#{mrBean.itemsToBid}">  

        <f:facet name="header">  
             Items for Bidding  
        </f:facet>  

        <p:column style="width:16px">  
            <p:rowToggler />  
        </p:column>  

        <p:column headerText="Name" >
            #{item.name}
        </p:column>  

        <p:column headerText="Condition" >  
            #{item.condition} 
        </p:column>  

        <p:rowExpansion>  

            <h:panelGrid id="display" columns="2" > 
                <h:outputText value="Your bid:" />  
                <h:inputText  value="#{mrBean.bidAmount}" />  

                <h:commandButton actionListener="#{mrBean.bid(item)}" value="Bid"/>  
            </h:panelGrid>  

        </p:rowExpansion>  
    </p:dataTable>  
</h:form>  

Your bidding form is inside the <p:rowExpansion> component and it does appear right below your item row. 您的出价表单位于<p:rowExpansion>组件内部,并且确实显示在项目行的下方。

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

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