1 .I am getting a promotional entity in my spring controller and then replacing the default entity that came with my CP.

@RequestMapping(method = RequestMethod.GET, value = "GetPromoItem/{entityId}")
public String getPromoItem(HttpServletRequest request,@PathVariable String entityId, @RequestParam String regionName) throws Exception {
//Get the entity from request
EntityModel entity = getEntityFromRequest(request, entityId);
final MvcData mvcData = entity.getMvcData();
//Get the Promotional item if returned for the current page/region combination
//Some code to get the promotional component id,template id based on region
PromoItemModel item=(PromoItemModel) contentProvider.getEntityModel(compId.getItemId()+"-"+templateId.getItemId(), localization);     
  if(item !=null) 
request.setAttribute(ENTITY_MODEL, entity);
return resolveView(mvcData, "Entity", request);    

2. Registered ViewModel , rendered using promotion.jsp

<jsp:useBean id="entity" type="com.sdl.webapp.common.api.model.entity.PromoItemModel" scope="request"/>
<jsp:useBean id="markup" type="com.sdl.webapp.common.markup.Markup" scope="request"/>
<%@ taglib prefix="dxa" uri="http://www.sdl.com/tridion-dxa" %>

<div class="container-fluid ${entity.htmlClasses}" ${markup.entity(entity)}>

    <div id="location-tile" class="row">
        <div class="col-sm-6">
            <div class="tile">
                <h1 ${markup.property(entity, "headline")}> ${ entity.headline }</h1>        

On my page I can see the promotional content if available and default if not, but the XPM markup is for the default entity always.

i- how can i generate and use the XPM Markup for my promotional entity using DXA?
ii- how can i modify this markup?
(Use case is appending some extra markup - like we add Smart Target Promotion XPMMarkup)

Any examples or pointers to similar markup generation within DXA projects are welcome.

  • It's not clear to me what you are trying to achieve, nor how you are trying to achieve it, can you clarify and provide a code sample? – Rick Pannekoek Feb 3 '16 at 18:10
  • @Rick - i have modified the question and added some sample code snippets, let me know if any further info required – Ashutosh Feb 4 '16 at 5:11

I guess your controller is intended as an Entity Controller. In that case, I would recommend to inherit from class EntityController and override method enrichModel. See, for example, class ListController: https://github.com/sdl/dxa-web-application-java/blob/master/dxa-framework/dxa-common-api/src/main/java/com/sdl/webapp/common/controller/ListController.java

From which class does your PromoItemModel inherit? If it inherits from EntityModel, the XPM markup should be automagically generated.

| improve this answer | |
  • Thanks for your inputs, To add Controller inherits from BaseController and Class inherits AbstractEntityModel, tried few things per reference from ListController ,no luck as of now. – Ashutosh Feb 8 '16 at 8:03
  • Also observed at the latest news module on homepage, though the data is populated dynamically but the XPM editing is not available for that data(list items/news), i feel that we are looking at an incorrect reference here. – Ashutosh Feb 8 '16 at 12:10
  • How is the PromoItemModel created? Class AbstractEntityModel generates XPM markup from the key/value pairs in the XpmMetadata property. If you create your own EntityModel from scratch, you will have to set XpmMetadata yourself too. – Rick Pannekoek Feb 8 '16 at 18:57
  • I have updated snippet in question to show the same, we are using contentProvider to create our Entity, verified it has set XpmMetadata& other properties correctly. – Ashutosh Feb 9 '16 at 5:00
  • Ok. That sound good. It's still not quite clear to me how your controller method gets invoked. Can you also show how your attempt to refactor it cf. ListController implementation looks? – Rick Pannekoek Feb 9 '16 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.