简体   繁体   English

f:ui中的uj:重复

[英]f:ajax inside ui:repeat

I need to show a list of auction items. 我需要显示拍卖物品清单。 When a user clicks on a Bid button next to each item, I'd like to have ajax open a bid form right under this auction item. 当用户点击每个项目旁边的出价按钮时,我想让ajax在此拍卖项目下打开出价表单。 So I'm going with a ui:repeat and a f:ajax as shown below, but when I go to the page all the auction items have the bid component open next to them. 所以我将使用ui:repeatf:ajax ,如下所示,但是当我转到页面时,所有拍卖项目都会在其旁边打开出价组件。 And clicking any of the buttons doesn't do anything. 并单击任何按钮不会执行任何操作。 This is the code (with the bid form simplified to just an outputText: ) 这是代码(将出价形式简化为outputText:

<h:form>
<table border="1">
<ui:repeat var="parcel" varStatus="status" value="#{auctionsViewBean.parcels}">
<tr>
  <td><h:commandButton value="Bid" action="nothing">
      <f:ajax render="bidView"/>
  </h:commandButton></td>
  <td>#{status.index + 1}</td>
  <td>#{parcel.a}</td>
  <td>#{parcel.b}</td>
  <td>#{parcel.c}</td>
</tr>    
<tr><td><h:outputText id="bidView" value="#{auctionsViewBean.showBidViewForParcel(parcel)}">Some text</h:outputText></td></tr>

</ui:repeat> 
</table>
</h:form>

What am I doing wrong? 我究竟做错了什么? And how can I specify only the bid component related to the clicked auction item? 如何仅指定与点击的拍卖项目相关的出价组件?

If I understand you correctly, you want to initially hide the bidView until the button is pressed? 如果我理解正确,您最初要隐藏bidView直到按下按钮? You can do it by giving it a rendered attribute and put it in another component which can be referenced by <f:ajax> . 你可以通过给它一个rendered属性并将它放在另一个可以被<f:ajax>引用的组件中来实现。 You only need to rearrange the action method and checking logic. 您只需要重新排列操作方法和检查逻辑。

<h:commandButton value="Bid" action="#{auctionsViewBean.addBidView(parcel)}">
<f:ajax render="bidView" />
...
<h:panelGroup id="bidView">
    <h:panelGroup rendered="#{auctionsViewBean.showBidView(parcel)}">
        ...
    </h:panelGroup>
</h:panelGroup>

with something like this: 用这样的东西:

public void addBidView(Parcel parcel) {
    bidViews.put(parcel, new BidView());
}

public boolean isShowBidView(Parcel parcel) {
    return bidViews.containsKey(parcel);
}

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

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