为什么JSF文档中没有InputHidden只读属性? [英] Why is InputHidden readonly attribute not in JSF documentation?

查看:135
本文介绍了为什么JSF文档中没有InputHidden只读属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了一种情况,我想使用<h:inputHidden="#{v.index}/>ui:repeat varStatus="v"设置索引值.如果尝试此操作,并使用AJAX execute组件,则会出现该属性不可写的异常.环顾四周时,我发现inputHidden支持readonly="true"属性,该属性可以使错误消失.

I have recently encountered a case where I wanted to set the index value from ui:repeat varStatus="v" using <h:inputHidden="#{v.index}/>. If you try this and execute the component using AJAX you will get an exception that the property is not writeable. While looking around I found that inputHidden supports a readonly="true" attribute that does just that making the error go away.

有没有为什么不在文档中的原因? (即特殊,直通,其他) 使用安全吗?

Is there a reason why this is not in documentation? (i.e. special, passthrough, other) Is it safe to use?

推荐答案

进行一些挖掘后 Core JavaServer Faces 3e 要这样说:

After doing some digging Core JavaServer Faces 3e had this to say :

h:inputHidden标记与其他输入标记具有相同的属性,只是它不支持标准的HTML和DHTML标记

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中呈现readonly的原因,是因为inputHidden不支持它.当我尝试将readonly作为属性添加到inputHidden'(带有错误消息的红色波浪线)时,Netbeans也确认了这一点.当我提交的表单中没有为放置在inputHidden中的bean属性定义setter的表单时,我能够得到该异常.由于inputHidden在提交表单时(针对我的情况)会调用setter,并且由于我的代码中未定义任何内容,因此它当然会抛出该异常,即:

So, the reason why readonly is not in the docs for inputHidden and also why it's not being rendered in your HTML is because inputHidden does not support it. This was also confirmed by Netbeans when I tried to add readonly as an attribute to inputHidden'(red squiggly lines with an error message). I was able to get that exception when I submitted a form with no setter defined for my bean property that was placed in inputHidden. Since inputHidden calls the setter when a form is submitted (for my case) and since none is defined in my code, it will of course throw that exception, namely:

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即可.不要那样用.

As for why it works when you do that I have no idea. Since you're worried about safety, I would suggest you do as BalusC says and simply use <input type="hidden"> or you define a setter for that property. Don't use it like that.

这篇关于为什么JSF文档中没有InputHidden只读属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆