绑定 Set 集合中的对象

发布于 2024-10-07 12:01:51 字数 554 浏览 1 评论 0原文

我有一个表格,其中填充了集合的一些对象。我用列表实现了集合(一切正常),但现在我想使用集合。我注册了一个属性编辑器来创建对象。问题是我不知道必须使用什么语法来填充 Set 的对象。

public class MyObject(){
    Set<OtherObject> otherObjects = new HashSet();
}

我尝试过使用表单标签中的语法,例如列表的语法:

name="otherObjects['${status.index}']"

和映射的语法:

name="otherObjects['${id}']"

但是两者都会出错,因为“索引属性路径'otherObjects[0]'中引用的属性既不是数组也不是列表或地图”

我也尝试过,

name="otherObjects"

但这并没有填充对象。 谁能告诉我如何将数据绑定到 Set 中的对象。

谢谢

I have a form which fills some objects of a Collection. I had the collection implemented with a List (an everything worked good), but now I want to use a Set. I have a property editor registered to create the objects. The problem is that I don't know what is the syntax I must use to populate the objects of the Set.

public class MyObject(){
    Set<OtherObject> otherObjects = new HashSet();
}

I have tried with the syntax in the form tags, like the syntax a list:

name="otherObjects['${status.index}']"

and like the syntax for a map:

name="otherObjects['${id}']"

but both come to an error because "Property referenced in indexed property path 'otherObjects[0]' is neither an array nor a List nor a Map"

I have also tried with

name="otherObjects"

but this doesn't fill the objects.
Can anyone tell me how to bind the data to the objects in a Set.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

墨落成白 2024-10-14 12:01:51

According to the documentation on data binding, you can only user the bracket notation to bind to nested objects in a "naturally ordered collection". A set doesn't qualify.

土豪 2024-10-14 12:01:51

不能在表单标签中使用旧语法并添加一个将返回一组对象的 getter 吗?

public class MyObject(){
  List<OtherObject> otherObjectsList = new ArrayList<OtherObjects>();

  public Set<OtherObject> getOtherObject()
  {
    return new HashSet<OtherObject>(otherObjectsList);
  }
}

Can't you use the old syntax in the form tags and add a getter that will return a set of objects?

public class MyObject(){
  List<OtherObject> otherObjectsList = new ArrayList<OtherObjects>();

  public Set<OtherObject> getOtherObject()
  {
    return new HashSet<OtherObject>(otherObjectsList);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文