如何从icefaces数据表中删除一行?
我有一个简单的ice:dataTable,它有两列,一列是操作列,另一列是表示正则表达式的字符串。操作列的标题是添加操作,每行都有删除操作。我真的不在乎它是如何工作的,只要它确实有效。现在我正在尝试模仿icefaces复合组件editableTable,它要求您选择一行,此时为该行呈现操作,然后当您单击操作时,它将应用于所选行。因此,在我尝试完成这项工作时,我使用 rowSelector 创建了简单的数据表,该 rowSelector 为所选行设置了 item.selected:
<ice:dataTable value="#{configuration.selectedTagPositiveRegexes}"
var="item">
<ice:column>
<ice:rowSelector value="#{item.selected}" />
<f:facet name="header">
<ice:commandLink styleClass="linkBlue"
action="#{configuration.tagRegexAdd}">
<ice:outputText value="Add" />
</ice:commandLink>
</f:facet>
<ice:commandLink styleClass="linkBlue"
action="#{configuration.tagRegexRemove}"
rendered="#{item.selected}">
<ice:outputText value="Remove" />
</ice:commandLink>
</ice:column>
<ice:column>
<f:facet name="header">
<ice:outputText value="Regular Expression" />
</f:facet>
<ice:inputText value="#{item.object}" size="100" />
</ice:column>
</ice:dataTable>
然后在我的支持 bean 中,我有这 2 个方法:
public void tagRegexAdd() {
log.debug( "add a new regex" );
for ( SelectableRow<String> row : selectedTagPositiveRegexes ) {
row.selected = false;
}
selectedTagPositiveRegexes.add( 0, new SelectableRow<String>( "", true ) );
}
public void tagRegexRemove() {
log.debug( "remove an existing regex" );
int i = 0;
int selectedIndex = -1;
for ( SelectableRow<String> row : selectedTagPositiveRegexes ) {
if ( row.selected ) {
selectedIndex = i;
row.selected = false;
}
i++;
}
if ( selectedIndex >= 0 ) {
selectedTagPositiveRegexes.remove( selectedIndex );
}
}
当我单步执行此代码时,我注意到发生的情况是单击删除操作时,selectedTagPositiveRegexes 的 getter 被调用 3 次,然后是实际的删除方法,然后再调用 1 次 getter,此时浏览器会收到执行我想要的操作的响应。但是,某些事件必须已被某些事物排队,因为返回响应后,getter 会再被调用 3 次,之后被删除的项目后面的项目将被被删除的项目替换。我不知道这里发生了什么,并且对于如何使用它一定有严重的误解,但我的假设是由元素列表支持的数据表应该从该列表中获取其内容。这样,如果我在列表中添加或删除,数据表应该代表新状态。但我的这个假设似乎大错特错了。任何有关其实际运作方式的见解都将不胜感激。
I have a simple ice:dataTable which has 2 columns, one an action column the other a string representing a regular expression. The action column has as its header an add action, and for each row a remove action. I dont really care how this works as long as it does. Right now I am attempting to mimic the icefaces composite component editableTable which requires you to select a row at which point the actions get rendered for that row then when you click an action it is applied to the selected row. So in my attempt to make this work, I created simple datatable with an rowSelector that sets my item.selected for the selected row:
<ice:dataTable value="#{configuration.selectedTagPositiveRegexes}"
var="item">
<ice:column>
<ice:rowSelector value="#{item.selected}" />
<f:facet name="header">
<ice:commandLink styleClass="linkBlue"
action="#{configuration.tagRegexAdd}">
<ice:outputText value="Add" />
</ice:commandLink>
</f:facet>
<ice:commandLink styleClass="linkBlue"
action="#{configuration.tagRegexRemove}"
rendered="#{item.selected}">
<ice:outputText value="Remove" />
</ice:commandLink>
</ice:column>
<ice:column>
<f:facet name="header">
<ice:outputText value="Regular Expression" />
</f:facet>
<ice:inputText value="#{item.object}" size="100" />
</ice:column>
</ice:dataTable>
Then in my backing bean, I have these 2 methods:
public void tagRegexAdd() {
log.debug( "add a new regex" );
for ( SelectableRow<String> row : selectedTagPositiveRegexes ) {
row.selected = false;
}
selectedTagPositiveRegexes.add( 0, new SelectableRow<String>( "", true ) );
}
public void tagRegexRemove() {
log.debug( "remove an existing regex" );
int i = 0;
int selectedIndex = -1;
for ( SelectableRow<String> row : selectedTagPositiveRegexes ) {
if ( row.selected ) {
selectedIndex = i;
row.selected = false;
}
i++;
}
if ( selectedIndex >= 0 ) {
selectedTagPositiveRegexes.remove( selectedIndex );
}
}
What I notice happening as I step through this code is that the getter for selectedTagPositiveRegexes is getting called 3 times when the remove action is clicked, followed by the actual remove method followed by 1 more call to the getter at which point the browser receives a response that does what I want. However, some event must have been queued by something because after returning the response, the getter gets called 3 more times after which the item after that item that was removed gets replaced with the item that was removed. I have no idea what is going on here and must have a serious misunderstanding as to how this is used, but my assumption was that the datatable, being backed by a list of elements should obtain its content from that list. That way if i add or remove to/from the list, the datatable should represent the new state. But I appear to be terribly wrong in that assumption. Any insight whatsoever as to how this is actually working will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还没有尝试过这种方式,但这对我有用。
在托管 bean 中,创建 HtmlDataTable 类型的属性,然后使用ice:dataTable 的绑定属性指向它。现在在回调中,执行以下操作:
在某些情况下,我必须运行它才能使其正确更新。我仅当您有嵌套表时才相信这一点:
I haven't tried it that way, but this has worked for me.
In your managed bean, create a property of type HtmlDataTable and then use the binding attribute of ice:dataTable to point to it. Now in the callback, do this:
In some cases I've had to run this to make it update correctly. I believe this only when you have nested tables:
尝试添加到数据表的绑定,可以是 (org.icefaces.ace.component.datatable.DataTable) 或 (HtmlDatatable),
代码将是,
并且 bean:
Try adding a binding to the datatable, could be an (org.icefaces.ace.component.datatable.DataTable) or (HtmlDatatable)
the code will be
and the bean: