To make any changes @ theme-level, you must include that code in the portal_normal.vm file of your current theme(or the theme you are using in that particular page)
· Create a new file (naming : portal_normal.vm) at the following location in your theme –
/mytheme -theme/docroot/_diffs/templates/portal_normal.vm
1st Approach
STEP:1
·
Add the following line of code after the
</header> tag (or select your desired location @ theme- level) -
#set($addressDetailsLocalService =
$serviceLocator.findService("AddressDirectory-portlet","com.test.service.addressDetailsLocalService"))
#set($count =
$addressDetailsLocalService.getaddressDetailsesCount())
<h2> The No. of Entries in Your Address Portlet Are :
$count </h2>
where,
Ø AddressDirectory-portlet – your custom portlet’s id
Ø Com.test.service.addressDetailsLocalService – path of your local service
api(addressDetailsLocalService.java) generated by the service layer
Ø $count – is a velocity variable ,i have
defined to store the no. Of entries added in my entity(addressDetails).
·
Deploy your theme again..and check the
respective changes have been reflected
...
STEP-2:
Now as you can observe ,this change has been reflected for
the very first time only (first time after the theme has been redeployed)
but inaffective later on..
To get rid of the following problem –go to your addAddress() method in the
requisite .java file ,now in this
method simply add this line of code-
addressDetailsUtil.clearCache(addressObj);
where,
Ø addressDetails –name of the custom
entity(entity which you are using)
Ø addressObj- is the object of the
entity.
-this line of code will clear the database cache
Why Step2: The db cache are useful to avoid unuseful
access to DB...But If the entity is
changed by application, cache copy is invalidated, and a new refreshed copy of
the entity are extracted by DB. If you update data in you db, the update are
not listened, so your application data are not updated.
Alternative: Issue gets resolved if each time
after adding an entry to your portlet go to –
Control Panel / server Administration / Resources
/Actions
and clear the database cache from here....but this is not an
optimal solution as each time you have to clear the cache manually....so ie why
i preferred adding the above line of code in
my .java file (AddressDirectory .java).
Otherwise : checkout this way :
2nd Approach (Recommended)
Using this
method(addressDetailsLocalService.getaddressDetailses(0,-1).size()) ,
you need'nt
to clear the DB cache everytime you make an entry..
#set($addressDetailsLocalService
=
$serviceLocator.findService("AddressDirectory-portlet", "com.test.service.addressDetailsLocalService"))
#set($count =
$addressDetailsLocalService.getaddressDetailses(0, -1).size())
<h2>
The No. of Entries in Your Address Portlet Are : $count </h2>