Composite component required=“true” not respected

 ̄綄美尐妖づ 提交于 2020-01-02 05:45:08

问题


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?


回答1:


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)
    ...


来源:https://stackoverflow.com/questions/18482024/composite-component-required-true-not-respected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!