As far as I know both tags import variables from tiles context to JSP so variables are made visible in the JSP. Please elaborate the difference between importAttribute and useAttribute.
问问题
1383 次
1 回答
3
显然,两者之间没有区别,除了 inuseAttribute
允许您指定预期变量的类名。
这是标签的importAttribute
代码:
@Override
public void doTag() throws JspException {
JspContext jspContext = getJspContext();
Map<String, Object> attributes = model.getImportedAttributes(JspUtil
.getCurrentContainer(jspContext), name, toName, ignore,
jspContext);
int scopeId = JspUtil.getScope(scopeName);
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
jspContext.setAttribute(entry.getKey(), entry.getValue(), scopeId);
}
}
和useAttribute
标签代码:
@Override
public void doTag() throws JspException {
JspContext pageContext = getJspContext();
Map<String, Object> attributes = model.getImportedAttributes(JspUtil
.getCurrentContainer(pageContext), name, id, ignore,
pageContext);
if (!attributes.isEmpty()) {
int scopeId = JspUtil.getScope(scopeName);
pageContext.setAttribute(getScriptingVariable(), attributes
.values().iterator().next(), scopeId);
}
}
于 2012-12-11T03:52:27.057 回答