我需要显示拍卖物品清单。当用户单击每个项目旁边的出价按钮时,我希望 ajax 在该拍卖项目下打开一个出价表单。因此,我将使用 ui:repeat
和 f:ajax
,如下所示,但是当我进入该页面时,所有拍卖项目都会打开出价组件,如下所示给他们。单击任何按钮都不会执行任何操作。这是代码(投标表单简化为 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>
我做错了什么?如何仅指定与点击的拍卖项目相关的出价组件?
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. 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. And clicking any of the buttons doesn't do anything. This is the code (with the bid form simplified to just an 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?
发布评论
评论(1)
如果我理解正确的话,您想最初隐藏
bidView
直到按下按钮吗?您可以通过为其赋予rendered
属性并将其放入可以由
引用的另一个组件中来实现。你只需要重新安排动作方法和检查逻辑。像这样的东西:
If I understand you correctly, you want to initially hide the
bidView
until the button is pressed? You can do it by giving it arendered
attribute and put it in another component which can be referenced by<f:ajax>
. You only need to rearrange the action method and checking logic.with something like this: