【发布时间】:2019-02-04 16:14:14
【问题描述】:
我们按照本教程 -> https://www.danklco.com/posts/2013/06/changing-cq-components-design-path.html 为多个组件创建了一个全局设计路径解决方案,以共享设计,非常适合经典 UI 设计对话框。
public class GlobalDesignDialogTag extends BaseTag
{
/**
* Global design properties attribute name.
*/
public static final String GLOBAL_DESIGN_PROPERTIES_ATTRIBUTE_NAME = "globalDesignProperties";
private static final long serialVersionUID = 1L;
@Override public final int doEndTag()
{
final String
globalDesignPath =
getCurrentDesign().getPath() + "/" + JCR_CONTENT + "/" + getCurrentResource().getName();
EditContext editContext = getEditContext();
String currentDesignPath = getCurrentDesign().getPath() + "/jcr:content/default-page/par-main/secondary-nav";
if (WCMMode.fromRequest(getSlingRequest()) == WCMMode.DESIGN)
{
// Set the design dialog content path to be global design level instead of template
editContext.setContentPath(globalDesignPath);
}
if (AuthoringUIMode.fromRequest(getSlingRequest()).equals(AuthoringUIMode.TOUCH)) {
editContext.setContentPath(globalDesignPath);
}
final Resource globalDesignResource = getResourceResolver().getResource(globalDesignPath);
if (globalDesignResource != null)
{
// Set an attribute containing global design properties as ${currentStyle.propertyName} will still
// point to the default design dialog path under the template.
pageContext.setAttribute(GLOBAL_DESIGN_PROPERTIES_ATTRIBUTE_NAME,
globalDesignResource.adaptTo(ValueMap.class));
}
return EVAL_PAGE;
}
/**
* Gets the EditContext from the pageContext.
*
* @return The EditContext from the pageContext.
*/
private EditContext getEditContext()
{
return (EditContext) pageContext.getAttribute(DefineObjectsTag.DEFAULT_EDIT_CONTEXT_NAME);
}
/**
* Gets the current design from the pageContext.
*
* @return The current design from the pageContent.
*/
private Design getCurrentDesign()
{
if (pageContext.getAttribute(DefineObjectsTag.DEFAULT_CURRENT_DESIGN_NAME) != null)
{
return (Design) pageContext.getAttribute(DefineObjectsTag.DEFAULT_CURRENT_DESIGN_NAME);
}
return getCurrentResource().adaptTo(Design.class);
}
}
现在我们需要将经典 UI 升级为触控 UI,这涉及到很多组件的升级,但我们仍然希望保持大部分核心 java 代码不变或尽可能减少更改。
但是上面的教程方法editContext.setContentPath(globalDesignPath);
似乎不适用于触摸 UI 设计对话框...
请看下面的图片说明
因此,在经典 UI 设计对话框中,粉红色线条发生的情况是预期的行为,使用 editContext.setContentPath(globel) 它确实将设计对话框的二级导航节点保存在设计模板级别。
但是对于绿线,使用上面相同的代码示例,触发了从触摸 UI 保存的设计对话框,editContext.setContentPath(globel) 它看起来并没有做任何事情......它保存了demo-site/jcr:content/default-page/par-main/secondary-nav 下的节点,这是页面模板级别设计...不同页面设计模板中的其他辅助导航组件将无法访问属性。
理想情况下,触摸 UI 设计对话框应该像蓝线一样......通过保存对话框,它应该更新 demo-site/jcr:content/secondary-nav 节点属性
经过调查,我认为最可疑的行是editContext.setContentPath(globel),是不是在触摸UI中,它有一种新的(EditContext)对象或API来将触摸UI设计对话框保存到自定义路径中?
如果可能,请提供代码示例。
谢谢
【问题讨论】:
标签: aem tld aem-6 aem-touch-ui