First of all, it starts with this piece of code:
Code: Select all
<cms:content contentType="Message" contentItemVar="item">
<c:if test="${numResults > 0}">
<h3>${item.messageText}</h3>
</c:if>
</cms:content>
This automatically includes the assumption that for this CMS block, a content element of type "Message" will be placed. As a result, if the customer wants to change the block (instead of a symple text message, he wants an image now) he's not able to do it, cause the code expects the structured content to be an 'instance' of Message. To change this, one needs a code change.
So maybe it's better to allow a 'view' property on the StructuredContent, so that you only provide the cms:content tag in your source code, and the component will handle 'itself'.
Next thing I wanted to create (just a poc) is a rotating banner component, with the advantage that the customer can specify which images it has to include in the admin console. So I started extending the StructuredContentImpl, and doing this like:
Code: Select all
@Entity
@Table(name = "SC_ROTATING_BANNER")
public class RotatingBannerStructuredContent extends StructuredContentImpl {
private static final long serialVersionUID = -744340426023911601L;
@OneToMany(fetch = FetchType.LAZY, targetEntity = MediaImpl.class, cascade = { CascadeType.ALL })
@JoinTable(name = "SC_ROTATING_BANNER_2_MEDIA", joinColumns = @JoinColumn(name = "SC_ROTATING_BANNER_ID"), inverseJoinColumns = @JoinColumn(name = "MEDIA_ID"))
@Cascade(value = { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@AdminPresentation(friendlyName="Medias")
protected Set<Media> images = new HashSet<Media>();
public Set<Media> getImages() {
return images;
}
public void setImages(Set<Media> images) {
this.images = images;
}
}
But with this approach I have several issues:
- I cannot create an instance of this class using the admin console, cause the admin console will always create an instance of StructuredContentImpl with the StructuredContentType containing my 'Rotating Banner'.</li>
- I inserted an instance of my rotating banner in the database and opened this in the admin console. This does not raise any exceptions, but still I cannot see my newly added field... (I hope this is not a mistake I made? forgot some annotation or sth?)
- Another thing is that, just before passing those objects to the view, they are converted into their DTO representation. This conversion includes (by default) the conversion of the default fields (specified in the StructredContentImpl) and also the so called 'StructuredContentFields' but not the information I added in my subclass. The problem with this is that, the way I see the current solution, it's only possible to put in text fields (or simple fields) but not real domain objects; so for example link to images, link to some categories, link to some products, ...
Going together with the latest remarq about assigning domain objects to some StructureContent instance; to make the components real components, it would be a good idea to provide them with there own controller, so that if this component needs any logic, it's not nesessary to execute this code in every controller showing up the page containing the component, but the component will take care of it on its own
If you combine the three things: model-view-controller, then we really have a separate component, that we can easily place anywhere on the site, where a cms:content tag has been placed.
You can take it even further: at the moment the cms:content is specified by contentType, or by contentName which is not really flexible. Why not introduce a tag like for example: '<cms:slot id="XXX"/>'. This just defines a content slot on a certain page. Now if some advanged logic is inserted, in the admin console, when opening the page, it would be possible to see a list of those slots on the current page. Using drag and drop the customer can then add components to the slots. So that for example in the admin console, the slot 'XXX' on page 'HOME' contains 3 content elements: an image, a banner and a text component. This makes it really easy to move blocks around, and gives the customer the flexiblity to add/remove/update/... the cms components themselves.
Now I hope two things:
- you get guys get my point
- this counts as a valid 1st post