复合组件的required属性在Mojarra 2.0.3中引发异常 [英] Composite component required attribute throws exception in Mojarra 2.0.3

查看:113
本文介绍了复合组件的required属性在Mojarra 2.0.3中引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究JSF 2.0复合组件,但是对于composite:attribute标记中的require属性应该做什么感到有些困惑.该文档说,如果页面作者必须提供该属性的值,则required属性为true.

I've been playing around with JSF 2.0 composite components but I'm a bit confused as to what the require attribute in the composite:attribute tag is meant to do. The documentation says that the required attribute is true if the page author must supply a value for this attribute.

我将其解释为必须为具有required=true的所有Composite:属性提供值.我还假定一个空字符串是有效值.这就是它在Mojarra 2.0.2中的工作方式.

I've interpreted that as meaning that a value must be supplied for all composite:attributes that have required=true. I also assumed that an empty string is a valid value. And this is how it worked in Mojarra 2.0.2.

使用这个简单的托管bean:

Using this simple managed bean:

@ManagedBean(name = "simpleMB")
@ViewScoped
public class SimpleManagedBean implements Serializable {

   private static final long serialVersionUID = -1;

   private String whatever;

   ... setter and getter
}

以及复合组件:

<composite:interface>
    <composite:attribute name="value" required="true" />
</composite:interface>

<composite:implementation>
    <h:outputText value="Value: '#{cc.attrs.value}'" />    
</composite:implementation>

这些标签在Mojarra 2.0.2中有效:

These tags worked in Mojarra 2.0.2:

<foo:bar value="" />
<foo:bar value="#{simpleMB.whatever}" />

但是,当我升级到2.0.3时,只有第一个标记有效.第二个标签导致此错误消息:

However, when I upgraded to 2.0.3, only the first tag works. The second tag causes this error message:

/requiredAttribute.xhtml @20,42 <foo:bar> The following attribute(s) are 
required, but no values have been supplied for them: value.

当我将required设置为false时,它可以正常工作.

It works fine when I set required to false.

我是否误解了必需属性的含义?有人可以阐明我应该期待的行为吗?

Have I misinterpreted what the required attribute means? Can somebody clarify what behaviour I should expect?

谢谢.

推荐答案

与@ViewScoped bean结合使用,我们遇到了与required ="true"相似的问题.

We have simular issues with required="true" in combination with @ViewScoped bean.

我的情况是,该bean不再像@ViewScoped bean一样(每次都会调用新的构造函数).

I our case the bean no longer behaves like a @ViewScoped bean (new constructor call every time).

您的问题可能是因为Bean失去了作用域,所以variabels再次为空?

Your problem might be that because the bean looses its scope the variabels are null again?

无论哪种情况,我唯一能给您的遮阳篷就是不要使用required ="true"或使用@SessionScoped bean.

Either case the only awnser I can give you is to not use required="true" or use a @SessionScoped bean.

(可能与Mojarra无法处理@ViewScoped bean中的属性绑定有关)

(Possibly this relates to the problem of Mojarra not being able to handle bindings to properties in @ViewScoped beans)

这篇关于复合组件的required属性在Mojarra 2.0.3中引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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