Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composite component required="true" not respected

In the composite:interface I have defined an attribute like this:

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

Now when I use my composite component like this, without defining any attributes:

<myTag:myCC/>

I would expect an error to occur. It doesn't. What could I possibly be missing?

like image 353
pgsandstrom Avatar asked Mar 23 '23 15:03

pgsandstrom


1 Answers

It will only occur if your JSF project stage is set to Development as follows in web.xml:

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

It defaults to Production. Don't be surprised if you start to see several other errors/warnings related to "development mistakes" after setting the above context parameter.

In your specific case you should get an exception during opening 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)
    ...
like image 64
BalusC Avatar answered Apr 09 '23 20:04

BalusC