I'd be concerned about performance if it wasn't for this being a Dev
time check only - so that's fine.
So, given that, my only two comments are:
1) Please don't do assignments in if conditions - it obfuscates the
code, and doesn't improve performance.
2) I don't know offhand what Exception I'd pick to throw, but I'm sure
that IOException isn't the one I'd choose. IllegalStateException is
probably better... though there's probably a better one still that I
haven't thought of.
Otherwise, r=driscoll
Jim
On 1/2/10 9:33 AM, Ed Burns wrote:
> https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1472
>
> SECTION: Modified Files
> ----------------------------
> M jsf-ri/src/com/sun/faces/facelets/tag/composite/InterfaceHandler.java
>
> - Test for required attributes and facets. This changebundle is missing
> the localized messages, which you can assume will be there in the
> final changebundle. I will also add automated tests.
>
> SECTION: Diffs
> ----------------------------
> Index:
> jsf-ri/src/com/sun/faces/facelets/tag/composite/InterfaceHandler.java
> ===================================================================
> ---
> jsf-ri/src/com/sun/faces/facelets/tag/composite/InterfaceHandler.java
> (revision 8242)
> +++
> jsf-ri/src/com/sun/faces/facelets/tag/composite/InterfaceHandler.java
> (working copy)
> @@ -64,10 +64,13 @@
> import javax.faces.view.facelets.TagAttribute;
> import javax.faces.view.facelets.TagConfig;
> import java.beans.BeanDescriptor;
> +import java.beans.BeanInfo;
> +import java.beans.PropertyDescriptor;
> import java.io.IOException;
> import java.util.ArrayList;
> import java.util.List;
> import java.util.Map;
> +import javax.el.ValueExpression;
>
> public class InterfaceHandler extends TagHandlerImpl {
>
> @@ -102,9 +105,59 @@
> if (FaceletViewHandlingStrategy.isBuildingMetadata(context)) {
> imbueComponentWithMetadata(ctx, parent);
> this.nextHandler.apply(ctx, parent);
> + } else {
> + if (ProjectStage.Development ==
> context.getApplication().getProjectStage()) {
> + validateComponent(context, parent);
> + }
> }
> }
>
> + private void validateComponent(FacesContext context, UIComponent cc)
> throws IOException {
> + Map<String, Object> attrs = cc.getParent().getAttributes();
> + BeanInfo componentMetadata = (BeanInfo)
> attrs.get(UIComponent.BEANINFO_KEY);
> + PropertyDescriptor[] declaredAttributes =
> componentMetadata.getPropertyDescriptors();
> + String key;
> + Object requiredValue;
> + boolean required = false;
> +
> + // Traverse the attributes of this component
> + for (PropertyDescriptor cur : declaredAttributes) {
> +
> + if (null != (requiredValue = cur.getValue("required"))) {
> + if (requiredValue instanceof ValueExpression) {
> + requiredValue = ((ValueExpression)
> requiredValue).getValue(context.getELContext());
> + required = Boolean.parseBoolean(requiredValue.toString());
> + }
> + }
> + if (required) {
> + key = cur.getName();
> + if (!attrs.containsKey(key)) {
> + throw new IOException("");
> + }
> + }
> + }
> +
> + // Traverse the declared facets
> + Map<String, PropertyDescriptor> declaredFacets =
> + (Map<String, PropertyDescriptor>) attrs.get(UIComponent.FACETS_KEY);
> + if (null != declaredFacets) {
> + for (PropertyDescriptor cur : declaredFacets.values()) {
> + if (null != (requiredValue = cur.getValue("required"))) {
> + if (requiredValue instanceof ValueExpression) {
> + requiredValue = ((ValueExpression)
> requiredValue).getValue(context.getELContext());
> + required = Boolean.parseBoolean(requiredValue.toString());
> + }
> + }
> + if (required) {
> + key = cur.getName();
> + if (!attrs.containsKey(key)) {
> + throw new IOException("");
> + }
> + }
> + }
> + }
> + }
> +
> @SuppressWarnings({"unchecked"})
> private void imbueComponentWithMetadata(FaceletContext ctx, UIComponent
> parent) {
> // only process if it's been created
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net
>