I'm implementing functionality in SDL Tridion 2013 where the user is able to utilise a filter which in turn queries the broker for matching criteria and then returns the Component Presentations sorted in DESCENDING order of Date (the Schema has Date field) to the page. When I publish the DCP on CME, I confirm that the DCP is sorted adequately.

But my problem is happened when the DCP is published on XPM. Before I explain my problem, I described my source code below.

the java code is below.

package com.tridion.tag.news;

import java.util.ArrayList;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import com.tridion.broker.querying.*;
import com.tridion.broker.querying.criteria.*;
import com.tridion.broker.querying.criteria.metadata.*;
import com.tridion.broker.querying.sorting.SortDirection;
import com.tridion.broker.querying.sorting.SortParameter;
import com.tridion.broker.querying.sorting.column.CustomMetaKeyColumn;
import com.tridion.dynamiccontent.ComponentPresentationAssembler;

public class NewsSearch implements Tag {
    private PageContext pageContext;
    private Tag parentTag;
    private String criteria;
    private String schemaURI;
    private ComponentPresentationAssembler cpAssembler;
    private String componentId;
    private String componentTemplateURI = "tcm:19-1149-32";
    private ArrayList<Criteria> criteriaList = new ArrayList<Criteria>();

public void setPageContext(PageContext pageContext) {
    this.pageContext = pageContext;

public Tag getParent() {
    return this.parentTag;

public void setParent(Tag parentTag) {
    this.parentTag = parentTag;

public void setCriteria(String criteria) {
    this.criteria = criteria ;

public void setSchemaURI(String schemaURI) {
    if (schemaURI != null)
        schemaURI.substring(4, 6);
    this.schemaURI = schemaURI ;

public int doStartTag() throws JspException {
    try {
        JspWriter writer=pageContext.getOut();
        // create criteria
        CustomMetaKeyCriteria keyCriteria = new CustomMetaKeyCriteria("date");
        CustomMetaValueCriteria greaterCriteria = new CustomMetaValueCriteria(keyCriteria, criteria,"yyyy",Criteria.GREATER_THAN);
        CustomMetaValueCriteria lessCriteria = new CustomMetaValueCriteria(keyCriteria, String.valueOf((Integer.parseInt(criteria) + 1)),"yyyy",Criteria.LESS_THAN);
        // create query
        Query query = new Query(CriteriaFactory.And(criteriaList.toArray(new Criteria[criteriaList.size()])));
        // create sort
        SortParameter sortParam = new SortParameter (new CustomMetaKeyColumn("date",MetadataType.DATE), SortDirection.DESCENDING);
        // execute query
        String[] queryResult = query.executeQuery();
        if (queryResult != null) {
            int count = queryResult.length;
            cpAssembler = new ComponentPresentationAssembler(schemaURI);
            for (int i = 0; i < count; i++) {
                componentId = queryResult[i];
                writer.print(cpAssembler.getContent(componentId, componentTemplateURI));
    } catch (Exception e) {
        throw new JspException(e.getMessage());
    return SKIP_BODY;

public int doEndTag() throws JspException {
    return 0;

public void release() {


The DWT code (PT) is below.(For the debug, the criteria is fixed value(2014).)

<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="cd_tags" prefix="tridion" %>
<%@ taglib uri="cd_tags" prefix="news" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja">
    <news:NewsSearch criteria="2014" />

The DWT code (CT) is below.

  <th><img src="@@newsImage@@" alt="@@newsImageAlt@@" width="70" height="14" /></th>
    <td class="date">@@date@@</td>
       <li><a tridion:href="@@Component.ID@@">@@RenderComponentField("Fields.title",0)@@</a></li>

the output image (when DCP is published on CME) is below. enter image description here

My Problem

I found that the Component is published when the Component is edited on XPM. refer to the following site.

Publishing page on CME is different from that on XPM about default publishing rules for pages. Is it design?

After being published a DCP by clicking Finish Editing on XPM(for example publish 'old news' Component), these DCPs are not sorted adequately.I think that these DCPs seem to be sorted by order of published date.

the output image (when DCP is published on XPM) is below.

enter image description here

But when this DCP is re-published on CME, the DCP is sort adequately. Or after a while, the DCP is sort adequately.

Why published the DCP by clicking Finish Editing on XPM is not sorted adequately?

  • I see a similar issue on my system, when my query contains a SortParameter, inside XPM (after updating the Preview), the sort order is not as specified. Good thing is that on the actual website it will be fine (no republish required), but I would contact Customer Support and log this as a defect. Mar 31, 2014 at 9:15
  • When you state 'Or after a while, the DCP is sort adequately.' is this always the case... If so then wouldn't you be best investigating the caching models. For example - how long is 'after a while' ... is it consistent? ... is it the same after a browser hard refresh? ... does clearing the cache (e.g. restarting the application pool) force this to be correct? or (as I think Bart has assumed above) does this appear 'adequately' after republishing through the CME only? Mar 31, 2014 at 10:03
  • @Dylan..MarkSaunders from what I've seen it didn't look like a caching issue. Loading the Page in XPM and in a next tab without, both show the same order. When updating the preview in XPM, that then shows a different order (without any sorting), while the Page in the other tab stays sorted correctly on reload. I have no explanation how this can be yet. Mar 31, 2014 at 14:09
  • Did either of you (Arai or Bart) look in the broker db to see if there is a difference between the values of the field you are sorting on?
    – Quirijn
    Mar 31, 2014 at 15:55
  • @BartKoopman - so the only point to clarify is what exactly is meant by 'Or after a while, the DCP is sort adequately' ... this infers that eventually they become the same (is there some interaction that isn't described etc. - this is what lead me to consider caching) Mar 31, 2014 at 18:44


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.