dev@javaserverfaces.java.net

Seeking Review [1472-CCRequiredAttribute]

From: Ed Burns <Ed.Burns_at_Sun.COM>
Date: Sat, 02 Jan 2010 12:33:27 -0500

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