2
據我所知,這兩個標籤都將變量從tiles上下文導入到JSP中,因此這些變量在JSP中可見。請詳細說明importAttribute和useAttribute之間的區別。在Apache Tiles 2中,importAttribute和useAttribute有什麼區別?
據我所知,這兩個標籤都將變量從tiles上下文導入到JSP中,因此這些變量在JSP中可見。請詳細說明importAttribute和useAttribute之間的區別。在Apache Tiles 2中,importAttribute和useAttribute有什麼區別?
顯然這兩者之間沒有區別,只是在useAttribute
中可以指定預期變量的類名。
下面是標籤代碼:
@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);
}
}