return b.toString();
}
+ /**
+ * Finds the <jsp:body> subelement of the given parent node. If not
+ * found, null is returned.
+ */
+ protected static Node.JspBody findJspBody(Node parent) {
+ Node.JspBody result = null;
+
+ Node.Nodes subelements = parent.getBody();
+ for (int i = 0; (subelements != null) && (i < subelements.size()); i++) {
+ Node n = subelements.getNode(i);
+ if (n instanceof Node.JspBody) {
+ result = (Node.JspBody) n;
+ break;
+ }
+ }
+
+ return result;
+ }
+
+
private String createJspId() {
if (this.jspIdPrefix == null) {
StringBuilder sb = new StringBuilder(32);
}
}
- /**
- * Finds the <jsp:body> subelement of the given parent node. If not
- * found, null is returned.
- */
- private Node.JspBody findJspBody(Node parent) {
- Node.JspBody result = null;
-
- Node.Nodes subelements = parent.getBody();
- for (int i = 0; (subelements != null) && (i < subelements.size()); i++) {
- Node n = subelements.getNode(i);
- if (n instanceof Node.JspBody) {
- result = (Node.JspBody) n;
- break;
- }
- }
-
- return result;
- }
-
@Override
public void visit(Node.ForwardAction n) throws JasperException {
Node.JspAttribute page = n.getPage();
public void visit(Node.CustomTag n) throws JasperException {
setScriptingVars(n, VariableInfo.AT_BEGIN);
setScriptingVars(n, VariableInfo.NESTED);
- new ScriptingVariableVisitor(err).visitBody(n);
+ visitBody(n);
setScriptingVars(n, VariableInfo.AT_END);
}
Vector<Object> vec = new Vector<Object>();
Integer ownRange = null;
+ Node.CustomTag parent = n.getCustomTagParent();
if (scope == VariableInfo.AT_BEGIN
|| scope == VariableInfo.AT_END) {
- Node.CustomTag parent = n.getCustomTagParent();
if (parent == null)
ownRange = MAX_SCOPE;
else
String varName = varInfos[i].getVarName();
Integer currentRange = scriptVars.get(varName);
- if (currentRange == null
- || ownRange.compareTo(currentRange) > 0) {
+ // If a fragment helper has been used for the parent tag
+ // the scripting variables always need to be declared
+ if (currentRange == null ||
+ ownRange.compareTo(currentRange) > 0 ||
+ parent != null && isImplemetedAsFragment(parent)) {
scriptVars.put(varName, ownRange);
vec.add(varInfos[i]);
}
}
Integer currentRange = scriptVars.get(varName);
- if (currentRange == null
- || ownRange.compareTo(currentRange) > 0) {
+ // If a fragment helper has been used for the parent tag
+ // the scripting variables always need to be declared
+ if (currentRange == null ||
+ ownRange.compareTo(currentRange) > 0 ||
+ parent != null && isImplemetedAsFragment(parent)) {
scriptVars.put(varName, ownRange);
vec.add(tagVarInfos[i]);
}
}
}
+ private static boolean isImplemetedAsFragment(Node.CustomTag n) {
+ // Replicates logic from Generator to determine if a fragment
+ // helper will be used
+ if (n.implementsSimpleTag()) {
+ if (Generator.findJspBody(n) == null) {
+ if (!n.hasEmptyBody()) {
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+
+
public static void set(Node.Nodes page, ErrorDispatcher err)
throws JasperException {
page.visit(new CustomTagCounter());