sling - why do we have multiple jsp's for a single component in CQ5? -


i new cq5. while learning concepts came know cq5 uses sling framework request processing , resolves scripts based on best match. have seen few components( of them page or top level components) in cq5 having more 1 jsp under single component(e.g page component have page.jsp, body.jsp, header.jsp similary redirect component have redirect.jsp, body.jsp, content.jsp) . wanted ask in scenarios, having multiple jsp's , script resolved sling display content?

the possibility have more 1 jsp under component has bit more sling cq (although cq provides extensions on framework). reason having more jsp's in top level component (like page component example) catch cases of include happening on lower level somewhere (so definition of included file there, actual file not present in component).

in opinion there 3 main reasons having multiple jsp's under single component (no matter level) , of reasons can applied same component @ once

  1. breaking component in smaller (more maintainable) pieces
  2. overriding rendering
  3. using power of sling selectors

scenario 1: breaking component in smaller (more maintainable) pieces

as title states here, can use multiple jsp's in component split rendering of component seperate sections easier maintain , easier override or combination of both. "both" case happening in foundation page component. check scenario 2 details on that.

the rendering of standard page starts cq page having template in turn specifies component use rendering. skipping template part , going directly actual foundation page component. rendering page start's in page.jsp. in it's broken further including "head.jsp" , "body.jsp". in turn split further. allows override specific parts of page component in child component (see scenario 2).

scenario 2: overriding rendering

say made own base page component (common practise) inherits foundation page component (through sling:resourcesupertype property), , interested in spitting out specific html structure in body. in case create body.jsp file inside "base page" component (nothing else). overrides rendering body (in foundation page component), defaults else (for example head, headlibs) , on, on availability of files in parent chain somewhere. in our case default on files specified in foundation page component. chain resolve base component, foundation page component (as have body.jsp in there , no base.jsp). inside foundation page component, page.jsp found includes body.jsp (which body.jsp defined in base component).

what here works on levels. concept work when inherit other components "page" componente. example, i've used override rendering of foundation list component included jsp (sling.jsp) in turn uses sling include specific selector, , made components inherit list component , override sling include selector else.

scenario 3: using power of sling selectors

since sling has concept of "selectors", sling go sling chain find correct component render content. sling use specific selector render.

for example i've created title component inherits foundation title component. have structure inside title component.

title.jsp h2.jsp fancy.jsp 

it should obvious h2 , fancy actual selectors title component

it's commonly used practise have multiple jsp's in combination selectors. these used display same component in different way.

you put h2.jsp inside page component. sling find if set chain corretly.

there more selectors described here. part matters question.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -