1 14 15 package com.sun.facelets.tag.jsf; 16 17 import javax.faces.component.ActionSource; 18 import javax.faces.component.ActionSource2; 19 import javax.faces.event.ActionEvent; 20 import javax.faces.event.MethodExpressionActionListener; 21 22 import com.sun.facelets.FaceletContext; 23 import com.sun.facelets.el.LegacyMethodBinding; 24 import com.sun.facelets.tag.TagAttribute; 25 import com.sun.facelets.tag.Metadata; 26 import com.sun.facelets.tag.MetaRule; 27 import com.sun.facelets.tag.MetadataTarget; 28 import com.sun.facelets.util.FacesAPI; 29 30 35 final class ActionSourceRule extends MetaRule { 36 37 public final static Class [] ACTION_SIG = new Class [0]; 38 39 public final static Class [] ACTION_LISTENER_SIG = new Class [] { ActionEvent.class }; 40 41 final static class ActionMapper extends Metadata { 42 43 private final TagAttribute attr; 44 45 public ActionMapper(TagAttribute attr) { 46 this.attr = attr; 47 } 48 49 public void applyMetadata(FaceletContext ctx, Object instance) { 50 ((ActionSource) instance).setAction(new LegacyMethodBinding( 51 this.attr.getMethodExpression(ctx, String .class, 52 ActionSourceRule.ACTION_SIG))); 53 } 54 } 55 56 final static class ActionMapper2 extends Metadata { 57 58 private final TagAttribute attr; 59 60 public ActionMapper2(TagAttribute attr) { 61 this.attr = attr; 62 } 63 64 public void applyMetadata(FaceletContext ctx, Object instance) { 65 ((ActionSource2) instance).setActionExpression(this.attr 66 .getMethodExpression(ctx, String .class, 67 ActionSourceRule.ACTION_SIG)); 68 } 69 70 } 71 72 final static class ActionListenerMapper extends Metadata { 73 74 private final TagAttribute attr; 75 76 public ActionListenerMapper(TagAttribute attr) { 77 this.attr = attr; 78 } 79 80 public void applyMetadata(FaceletContext ctx, Object instance) { 81 ((ActionSource) instance) 82 .setActionListener(new LegacyMethodBinding(this.attr 83 .getMethodExpression(ctx, null, 84 ActionSourceRule.ACTION_LISTENER_SIG))); 85 } 86 87 } 88 89 final static class ActionListenerMapper2 extends Metadata { 90 91 private final TagAttribute attr; 92 93 public ActionListenerMapper2(TagAttribute attr) { 94 this.attr = attr; 95 } 96 97 public void applyMetadata(FaceletContext ctx, Object instance) { 98 ((ActionSource) instance) 99 .addActionListener(new MethodExpressionActionListener( 100 this.attr.getMethodExpression(ctx, null, 101 ActionSourceRule.ACTION_LISTENER_SIG))); 102 103 } 104 105 } 106 107 public final static ActionSourceRule Instance = new ActionSourceRule(); 108 109 public ActionSourceRule() { 110 super(); 111 } 112 113 public Metadata applyRule(String name, TagAttribute attribute, 114 MetadataTarget meta) { 115 if (meta.isTargetInstanceOf(ActionSource.class)) { 116 117 boolean elSupport = FacesAPI.getComponentVersion(meta 118 .getTargetClass()) >= 12; 119 120 if ("action".equals(name)) { 121 if (elSupport && meta.isTargetInstanceOf(ActionSource2.class)) { 122 return new ActionMapper2(attribute); 123 } else { 124 return new ActionMapper(attribute); 125 } 126 } 127 128 if ("actionListener".equals(name)) { 129 if (elSupport) { 130 return new ActionListenerMapper2(attribute); 131 } else { 132 return new ActionListenerMapper(attribute); 133 } 134 } 135 } 136 return null; 137 } 138 } 139 | Popular Tags |