Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 在UIInput的值中使用el条件运算符时发生javax.el.PropertyNotWritableException_Jsf_Input_El_Placeholder_Conditional Operator - Fatal编程技术网

Jsf 在UIInput的值中使用el条件运算符时发生javax.el.PropertyNotWritableException

Jsf 在UIInput的值中使用el条件运算符时发生javax.el.PropertyNotWritableException,jsf,input,el,placeholder,conditional-operator,Jsf,Input,El,Placeholder,Conditional Operator,我收到以下错误消息: javax.el.PropertyNotWritableException: /u/editProfile.xhtml @64,140 value="#{empty userProfile.cfg.gpu or userProfile.cfg.gpu == '' ? usernavmsg.EditMe: userProfile.cfg.gpu}": null 问题在于,当bean属性的值为null时,inputText字段的值从我的ManagedBean属性切换到资源字符

我收到以下错误消息:

javax.el.PropertyNotWritableException: /u/editProfile.xhtml @64,140 value="#{empty userProfile.cfg.gpu or userProfile.cfg.gpu == '' ? usernavmsg.EditMe: userProfile.cfg.gpu}": null
问题在于,当bean属性的值为null时,inputText字段的值从我的ManagedBean属性切换到资源字符串。所以我不能坚持这个价值观

我从托管bean中的数据库请求用户的概要文件。如果所述配置文件的属性为空,则该值为“编辑我”。如果不为null,则为该属性的值。这是有效的!但是,当我提交表单并尝试保留一个新值或根本没有值时,就会出现错误。该错误仅在开始时为null的字段中出现(当我从db请求它们时)。所以问题是,当值为null时,它会从我的ManagedBean属性切换到资源字符串

我有一张表格,上面写着:

<h:outputLabel value="#{usernavmsg.GPU}: "/>
        <p:inplace styleClass="lessDark">
            <p:inputText value="#{empty userProfile.cfg.gpu ? usernavmsg.EditMe: userProfile.cfg.gpu}" />
        </p:inplace>

提交表单时,我希望在数据库中持久保存userProfile.cfg,但这不会发生


我能解决这个问题吗?有可能吗

EL中的条件语句确实是不可写的。它们是只读的。故事结束了。这同样适用于EL中的方法引用,如
{bean.property()}
中的方法引用。它必须是一个真值表达式,如
{bean.property}
中所示

您使用(HTML5)“占位符”的方法实际上是错误的。为此,您应该使用
占位符
属性,而不是
属性

<html ... xmlns:a="http://xmlns.jcp.org/jsf/passthrough">
...
<p:inputText value="#{userProfile.cfg.gpu}" a:placeholder="#{usernavmsg.EditMe}" ... />

...

谢谢。关于占位符的部分不是我想要做的。为了解决我的问题,我将为数据库中的每个字段设置一个默认值“edit me”。我没有测试,因为我刚刚醒来,但我相信它的工作。如果没有,我会编辑这个。不客气。至于你的解决方法,这真的很尴尬。最好是出于爱好/教育目的。如果我是贵公司的首席开发人员,我几乎会解雇你;)在以后的问题中,尝试详细说明意图(功能需求)。这通常会产生更好的答案。另请参见标记不属于数据库。只有数据属于数据库。否则,您将破坏数据库的可移植性/可重用性/完整性。此外,未指定的数据应该由
null
表示,而不是由任意字符串表示,甚至不是空字符串。不仅在数据库中,而且在编程语言中。