Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For example, we can define the following component's definition:

Code Block
languagexml
linenumberstrue
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:slice="http://www.cognifide.com/slice/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="cq:Component"
    jcr:title="Rich Text"
    slice:model="com.example.RichTextModel"/>

In such case, we don't need to explicitly declare model in JSP file - it will be available out of the box, in a JSP bindings object, like in the example below:

Code Block
languagexml
linenumberstrue
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@include file="/libs/foundation/global.jsp"%>

Richtext content: ${bindings.model.text}

To simplify the code even more, you can put <slice:defineObjects/> somewhere in global.jsp include - it allows you to avoid "bindings" part, so above code, can be simplified as follows:

Code Block
languagexml
linenumberstrue
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@include file="/libs/foundation/global.jsp"%>
<slice:defineObjects/>

Richtext content: ${model.text}

...