Thursday, September 6, 2012

ATG Useful Code Snippets

  1)     Write a XML code for Property having Enumerated Data-Type 


    <property category-resource="categoryPioneerCycling" name="size" data-type="enumerated"
               column-name="clothing_size" display-name-resource="clothingSize">
      
        <attribute name="useCodeForValue" value="false"/>
        <option resource="clothingSizeUnknown" code="0"/>
        <option resource="clothingSizeExtraSmall" code="1"/>
        <option resource="clothingSizeSmall" code="2"/>
        <option resource="clothingSizeMedium" code="3"/>
        
      </property>  


Remember : 
1. Here mentoning the Data-type in important.
2. the attribute useCodeForValue tells whether the code given to options must be used or not.
3. If this attribute is true then options will be stored as integers in the database.


  2)     JSP Code  Error message for each droplet 



   <dsp:droplet name="/atg/dynamo/droplet/ErrorMessageForEach">
      <dsp:param bean="CouponFormHandler.formExceptions" name="exceptions"/>
      <dsp:oparam name="output">
        <dsp:valueof param="message"/>
      </dsp:oparam>
    </dsp:droplet>




3) Write a code to display breadcrumbs i.e nav history on the page.

Step 1 :
     Put the below code in the category or product page in order to get the item id , navAction and nav Count
   
       <dsp:droplet name="/atg/commerce/catalog/CatalogNavHistoryCollector">
         <dsp:param name="item" param="element"/>
         <dsp:param name="navAction" param="navAction"/>
         <dsp:param param="navCount" name="navCount"/>
       </dsp:droplet> 

    Step 2 : Create JSP to dsiplay the breadcrumbs and include it in all pages where you need to display it.
    
   <dsp:importbean bean="/atg/commerce/catalog/CatalogNavHistory"/>
     <dsp:droplet name="/atg/dynamo/droplet/ForEach">
   <dsp:param bean="CatalogNavHistory.navHistory" name="array"/>
   <dsp:param name="elementName" value="historyElement"/>
   <dsp:oparam name="outputStart">
      Navigation History: 
   </dsp:oparam>
   <dsp:oparam name="output">
      <dsp:getvalueof id="templateURL" param="historyElement.template.url" idtype="java.lang.String">
       <dsp:a href="genericcategory.jsp">
         <dsp:param name="id" param="historyElement.repositoryId"/>
         <dsp:param name="navAction" value="pop"/>
         <dsp:param bean="CatalogNavHistory.navCount" name="navCount"/>
       <b>  <dsp:valueof param="historyElement.displayName"/>
       </dsp:a> >></b>
      </dsp:getvalueof>
   </dsp:oparam>
   <dsp:oparam name="empty">
       No navigation history.
   </dsp:oparam>
</dsp:droplet>


  Remember : 1. CatalogNavHistory.navHistory is the component which stores the navigation history
    2. navAction specifies the action to be performed which is of 3 types 
     push --> inorder to push the item used in catgeory/product page
   pop --> used in the breadcrumbs page when used user clicks any of the                                                        item in the breadcrumb   
     jump --> used in search 

    



1 comment:

  1. here while am using droplet but am getting a error called formExceptions component can't find..

    ReplyDelete