Composite component required = "true" not respected

In the composite interface, I defined this attribute:

<composite:attribute name="myAttribute" required="true"/> 

Now, when I use my composite component as follows, without defining any attributes:

 <myTag:myCC/> 

I expect an error to occur. This is not true. What can I lose?

+4
source share
1 answer

This will only happen if your JSF project stage is set to Development , as described below in web.xml :

 <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Development</param-value> </context-param> 

The default is Production . Do not be surprised if, after setting the above context parameter, you see several other errors / warnings related to "development errors".

In your particular case, you should get an exception when you open the page something like this when you omit the required attribute:

 javax.faces.view.facelets.TagException: /test.xhtml @22,19 <my:composite> The following attribute(s) are required, but no values have been supplied for them: foo. at com.sun.faces.facelets.tag.composite.InterfaceHandler.validateComponent(InterfaceHandler.java:232) at com.sun.faces.facelets.tag.composite.InterfaceHandler.apply(InterfaceHandler.java:125) at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:95) ... 
+7
source

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


All Articles