我们按照本教程 -> https://www.danklco.com/posts/2013/06/sharing-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 设计对话框保存到自定义路径中吗?如果可能,请提供代码示例。谢谢