gpt4 book ai didi

jsf - 为什么 JSF 文档中没有 InputHidden 只读属性?

转载 作者:行者123 更新时间:2023-12-04 14:36:30 24 4
gpt4 key购买 nike

最近遇到一个案例,想设置索引值从ui:repeat varStatus="v"开始使用 <h:inputHidden="#{v.index}/> .如果你试试这个和execute使用 AJAX 的组件你会得到一个异常,该属性是不可写的。环顾四周,我发现 inputHidden支持 readonly="true"使错误消失的属性。

为什么这不在文档中? (即特殊、直通、其他)使用安全吗?

最佳答案

在做了一些挖掘之后 Core JavaServer Faces 3e有话要说:

The h:inputHidden tag has the same attributes as the other input tags, except that it does not support the standard HTML and DHTML tags

所以,为什么readonly不在 inputHidden 的文档中以及为什么它没有在您的 HTML 中呈现是因为 inputHidden不支持它。当我尝试添加 readonly 时,Netbeans 也证实了这一点作为 inputHidden 的属性'(带有错误消息的红色波浪线)。当我提交没有 setter 的表单时,我能够得到那个异常为放置在 inputHidden 中的我的 bean 属性定义.自 inputHidden调用 setter当提交表单时(对于我的情况)并且由于我的代码中没有定义任何表单,它当然会抛出该异常,即:

javax.el.PropertyNotWritableException: /index.xhtml @14,56 value="#{bean.x}": The class 'Bean' does not have a writable property 'x'. 

至于为什么当你这样做时它会起作用,我不知道。既然你担心安全,我建议你按照 BalusC 所说的去做,只需使用 <input type="hidden">或者你定义一个 setter对于那个属性(property)。不要那样使用它。

关于jsf - 为什么 JSF 文档中没有 InputHidden 只读属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17625239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com