| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package javax.faces.webapp; |
| 17 | |
|
| 18 | |
import javax.faces.component.EditableValueHolder; |
| 19 | |
import javax.faces.component.UIComponent; |
| 20 | |
import javax.faces.internal.WebAppUtil; |
| 21 | |
import javax.faces.validator.Validator; |
| 22 | |
import javax.servlet.jsp.JspException; |
| 23 | |
import javax.servlet.jsp.tagext.TagSupport; |
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
public class ValidatorTag extends TagSupport { |
| 29 | |
|
| 30 | |
private static final long serialVersionUID = 1L; |
| 31 | |
|
| 32 | 21 | private String validatorId = null; |
| 33 | |
|
| 34 | 21 | public ValidatorTag() { |
| 35 | 21 | } |
| 36 | |
|
| 37 | |
public void setValidatorId(String validatorId) { |
| 38 | 21 | this.validatorId = validatorId; |
| 39 | 21 | } |
| 40 | |
|
| 41 | |
public int doStartTag() throws JspException { |
| 42 | 0 | UIComponentTag tag = UIComponentTag |
| 43 | |
.getParentUIComponentTag(pageContext); |
| 44 | 0 | if (tag == null) { |
| 45 | 0 | throw new JspException("Not nested in a UIComponentTag"); |
| 46 | |
} |
| 47 | 0 | if (!tag.getCreated()) { |
| 48 | 0 | return EVAL_PAGE; |
| 49 | |
} |
| 50 | 0 | Validator validator = createValidator(); |
| 51 | 0 | UIComponent component = tag.getComponentInstance(); |
| 52 | 0 | if (component == null || !(component instanceof EditableValueHolder)) { |
| 53 | 0 | throw new JspException( |
| 54 | |
"Component is null or not editable value holder."); |
| 55 | |
} |
| 56 | 0 | EditableValueHolder editableValueHolder = (EditableValueHolder) component; |
| 57 | 0 | editableValueHolder.addValidator(validator); |
| 58 | 0 | return SKIP_BODY; |
| 59 | |
} |
| 60 | |
|
| 61 | |
public void release() { |
| 62 | 0 | validatorId = null; |
| 63 | 0 | super.release(); |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
protected Validator createValidator() throws JspException { |
| 67 | |
try { |
| 68 | 21 | String id = this.validatorId; |
| 69 | 21 | if (UIComponentTag.isValueReference(id)) { |
| 70 | 0 | id = (String) WebAppUtil.getValueFromCreatedValueBinding(id); |
| 71 | |
} |
| 72 | 21 | return WebAppUtil.createValidator(id); |
| 73 | 0 | } catch (Exception e) { |
| 74 | 0 | throw new JspException(e); |
| 75 | |
} |
| 76 | |
} |
| 77 | |
} |