Component component requires exception exceptions in Mojarra 2.0.3

I played with JSF 2.0 composite components, but I'm a bit confused about having to use the require attribute in the composite:attribute tag. The documentation states that the required attribute is true if the page author must specify a value for this attribute.

I interpreted this as meaning that a value should be provided for all composite attributes that have required=true . I also suggested that an empty string is a valid value. And so he worked in Mojarra 2.0.2.

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 } 

And the component component:

 <composite:interface> <composite:attribute name="value" required="true" /> </composite:interface> <composite:implementation> <h:outputText value="Value: '#{cc.attrs.value}'" /> </composite:implementation> 

These tags worked in Mojarra 2.0.2:

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

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. 

It works fine when I set to false.

I misinterpreted what the required attribute means? Can someone clarify what behavior I should expect?

Thanks.

+3
source share
3 answers

We have simulated problems with required = "true" in combination with @ViewScoped bean.

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

Perhaps the problem is that since the bean is losing its scope, are the variables again null?

In any case, the only box I can give you is not using require = "true" or using the @SessionScoped bean.

(This is probably due to the fact that Mojarra cannot handle property bindings in @ViewScoped beans)

+2
source

I do not know if this is a mistake, but it is the nature of el-expressions. The default expression type is String and the empty string translated as null.

0
source

This is similar to this question , which seems to have been closed some time ago, although I cannot find in which version it was included.

0
source

Source: https://habr.com/ru/post/1494666/


All Articles