为什么在CQ5中单个组件有多个jsp? [英] why do we have multiple jsp's for a single component in CQ5?

查看:75
本文介绍了为什么在CQ5中单个组件有多个jsp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是CQ5的新手。在学习其概念时,我知道CQ5使用Sling框架进行请求处理并基于最佳匹配来解析脚本。我在CQ5中看到很少的组件(大多数是页面或顶级组件)在单个组件下具有多个jsp(例如,页面组件具有page.jsp,body.jsp,header.jsp类似重定向组件具有重定向) .jsp,body.jsp,content.jsp)。因此,我想问一下在哪种情况下,我们将有多个jsp,并且将使用吊索来解析哪个脚本以显示内容?

I am new to CQ5. While learning its concepts i came to know that CQ5 uses Sling framework for request processing and resolves scripts based on best match. I have seen few components( most of them are page or top level components) in CQ5 which are having more than one jsp under a single component(e.g page component have page.jsp, body.jsp, header.jsp similary redirect component have redirect.jsp, body.jsp, content.jsp) . So i wanted to ask in what scenarios, we will be having multiple jsp's and which script will be resolved by sling to display the content?

推荐答案

在一个组件下拥有多个jsp的可能性与吊索比与CQ息息相关(尽管cq在框架上也提供了一些扩展)。在顶级组件(例如,例如页面组件)中使用更多jsp的原因通常是为了捕获包含在较低级别某处发生的情况(因此,包含文件的定义在那里,但实际文件是

The possibility to have more than one jsp under a component has a bit more to do with sling than with CQ (although cq also provides some extensions on the framework). The reason for having more jsp's in a top level component (like a page component for example) is often to catch the cases of an include happening on a lower level somewhere (so the definition of the included file is there, but the actual file is not present in the component).

在我看来,在单个组件下具有多个jsp的主要原因有3个(无论什么级别),所有这些原因都可以一次应用于同一组件

In my opinion there are 3 main reasons for having multiple jsp's under a single component (no matter what level) and all of those reasons can be applied to the same component at once


  1. 以较小(更易于维护)的方式拆分该组件

  2. 覆盖渲染

  3. 使用吊索选择器的功能

方案1:将组件分解成更小(更易于维护)的片段

如标题所示,我们可以在组件中使用多个jsp来拆分将该组件划分为易于维护和覆盖的单独部分,或者将它们组合使用f两者。 两者都是基础页面组件中发生的情况。但是,请查看方案2中的详细信息。

As the title states here, we can use multiple jsp's in a component to split up the rendering of that component into seperate sections which are easier to maintain and easier to override or a combination of both. The "both" case is what is happening in foundation page component. But check Scenario 2 for details on that.

标准页面的渲染从具有模板的cq页面开始,而模板又指定了用于渲染的组件。因此,跳过模板部分,直接进入实际的基础页面组件。页面的渲染位于page.jsp中。其中包含 head.jsp和 body.jsp,进一步细分了该代码。他们进而将其进一步分割。这使您可以覆盖子组件中页面组件的特定部分(请参阅场景2)。

The rendering of a standard page starts with that cq page having a template which in its turn specifies the component to use for rendering. So skipping the template part and going directly to the actual foundation page component. Rendering for the page start's in page.jsp. In it's broken up further by including a "head.jsp" and "body.jsp". They in turn split it up even further. This allows you to override specific parts of the page component in a child component (see scenario 2).

场景2:覆盖呈现

假设您制作了自己的基础页面组件(常见做法),该组件继承自基础页面组件(通过sling:resourceSuperType属性),并且您只对吐出特定内容感兴趣体内的html结构。在这种情况下,您只需要在该基础页面组件内创建一个body.jsp文件即可。实际上,这会覆盖主体的呈现(在基础页面组件中),但对于其他所有内容(例如head,headlibs)等等,则默认为默认设置,以此类推。在我们的情况下,它将默认为基础页面组件中指定的文件。该链将解析为基础组件,然后解析为基础页面组件(因为其中只有body.jsp,而没有base.jsp)。在基础页面组件中,找到了page.jsp,其中包括body.jsp(将是在基本组件中定义的body.jsp)。

Say you made your own base page component (common practise) which inherits from the foundation page component (through sling:resourceSuperType property), and you are only interested in spitting out a specific html structure in the body. In this case you just create a body.jsp file inside that "base page" component (nothing else). This actually overrides the rendering for the body (in the foundation page component), but defaults for everything else (for example head, headlibs) and so on, on the availability of those files in the parent chain somewhere. In our case it will default on the files specified in the foundation page component. The chain will resolve to your base component, then to the foundation page component (as you only have body.jsp in there and no base.jsp). Inside the foundation page component, page.jsp is found which includes body.jsp (which will be the body.jsp defined in base component).

我们在此所做的工作在所有级别上。当从页面组件之外的其他组件继承时,此概念也将起作用。例如,我用它来覆盖基础列表组件的呈现,其中包括一个jsp(sling.jsp),而后者又使用了带有特定选择器的sling include,然后使组件继承了该列表组件,并且

What we do here works on all levels. This concept will also work when inherit from other components than a "page" componente. For example, I've used it to override rendering of the foundation list component where I included a jsp (sling.jsp) which in its turn uses a sling include with a specific selector, and than made components that inherit from that list component and override the sling include selector to something else.

方案3:使用吊索选择器的功能

由于吊索具有选择器的概念,因此吊索将在吊索链中向上查找正确的组件以呈现内容。 Sling将始终使用最特定的选择器进行渲染。

Since sling has the concept of "selectors", sling will go up the sling chain to find the correct component to render the content. Sling will always use the most specific selector to render.

例如,说我创建了一个从基础title组件继承的title组件。假设我在标题组件中有这个结构。

For example say I've created a title component that inherits from the foundation title component. Say I have this structure inside the title component.

title.jsp
h2.jsp
fancy.jsp

很明显,h2和fancy是标题组件的实际选择器

It should be obvious that h2 and fancy are actual selectors for the title component

将多个jsp与选择器结合使用是一种常见的做法。这些用来以不同的方式显示基本相同的组件。

It's a commonly used practise to have multiple jsp's is in combination with selectors. These are used to display basically the same component in a different way.

您也可以将h2.jsp放在页面组件中。如果您正确地设置了链条,Sling会找到它。

You could also put that h2.jsp inside your page component. Sling will find it if you set the chain corretly.

选择器的功能比我在这里描述的还要多。但这只是问题的一部分。

There is more to selectors then what I described here. But this is just part that matters to the question.

这篇关于为什么在CQ5中单个组件有多个jsp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆