java node 获取属性,类'java.util.HashMap $ Node'没有可写的属性'key'

在使用PrimeFaces的单元格编辑功能时,尝试更改Bean映射的键会遇到错误。这是因为HashMap的EntrySet中的键是不可变的。JavaBeans规范规定键属性是只读的,没有提供修改键的方法。这防止了在集合中修改键可能导致的冲突问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How to solve this issue:

I want to Change key of my bean map with celledit feature from primefaces.

For editing the value of map it works well.

For changing the key i get following error:

javax.el.PropertyNotWritableException: The class 'java.util.HashMap$Node' does not have a writable property 'key'.

editable="true" editMode="cell" >

update=":form:msgs" />

解决方案

The reason that you get an error is that the keys in an entrySet are immutable. The entrySet() method returns a Set. If you look at the javadocs for Map.Entry you will see:

a V getValue() method,

a void setValue(V) method,

a K getKey() method, but

no void setKey(K) method

Basically, the key property is read-only per the JavaBeans convention. That's actually a good thing, because if you could modify a key in an Set you would have the difficult problem of what to do if the new key was the same as the key of another entry in the original map.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值