on 05-17-2006 3:38 PM
Hi all,
Looking at some of the default Propertyrenderers deliverd by SAP in km.shared.ui.util_api.jar, I've written a new custom IStructuredPropertyRenderer. This in relation to <a href="https://www.sdn.sap.com/irj/sdn/thread?threadID=51095&start=15&tstart=0">Avoid version changing when creating a propierty</a>. So I'm not using IProperty but IAppProperty in order to prevent versioning changes. This IAppProperty is updated by a custom service as in the link above. To render this property, I created a new renderer.
As there is not a lot of documentation on this (I read the
<a href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/kmc/Knowledge%20Management%20and%20Collaboration%20Developers%20Guide.html">Writing Custom Renderers for KM Property Groups</a> document to get an idea.
I uploaded the renderer par file, created the new property renderer and assigned this to a dummy property 'hitscount' (type integer, in the default namespace http://sapportals.com/xmlns/cm). Unfortunately, nothing can be seen. Perhaps my coding could be wrong, but ... the question is : what should be selected in the NW Developer studio when creating a new Propertyrender to have the correct folderstructure generated? I just used File -> Portal Application -> Create a new Portal Application Project. Under src.core I just created two new folders and created a new java file. I assume File -> Portal application -> new Portal Application Object -> object -> RF Component Wizard needs to be used?
A sample par file would be welcome 🐵
Below my code :
package be.kindengezin;
import com.sap.tc.logging.Location;
import com.sapportals.htmlb.Component;
import com.sapportals.htmlb.HTMLFragment;
import com.sapportals.htmlb.Label;
import com.sapportals.htmlb.TextView;
import com.sapportals.htmlb.event.Event;
import com.sapportals.htmlb.page.DynPage;
import com.sapportals.wcm.IWcmConst;
import com.sapportals.wcm.WcmException;
import com.sapportals.wcm.repository.IPropertyMap;
import com.sapportals.wcm.repository.IResource;
import com.sapportals.wcm.repository.IResourceFactory;
import com.sapportals.wcm.repository.PropertyName;
import com.sapportals.wcm.repository.ResourceFactory;
import com.sapportals.wcm.repository.service.IRepositoryService;
import com.sapportals.wcm.repository.service.IRepositoryServiceFactory;
import com.sapportals.wcm.repository.service.appproperties.IAppProperty;
import com.sapportals.wcm.repository.service.appproperties.IAppPropertyMap;
import com.sapportals.wcm.repository.service.appproperties.IApplicationPropertiesService;
import com.sapportals.wcm.service.propertyconfig.IMetaContext;
import com.sapportals.wcm.service.propertyconfig.IMetaName;
import com.sapportals.wcm.service.propertyconfig.renderer.IStructuredPropertyRenderer;
import com.sapportals.wcm.service.propertyconfig.renderer.enum.PropertyDisplayMode;
import com.sapportals.wcm.util.logging.CatchBlockHandler;
import com.sapportals.wcm.util.logging.LoggingFormatter;
public class PropertyRendererHitscount implements IStructuredPropertyRenderer {
public static Location log;
static
{
log = Location.getLocation((be.kindengezin.PropertyRendererHitscount.class).getName());
}
/**
*/
public PropertyRendererHitscount() {
super();
// TODO Auto-generated constructor stub
}
/* (non-Javadoc)
@see com.sapportals.wcm.service.propertyconfig.renderer.IStructuredPropertyRenderer#renderMetaProperty(com.sapportals.wcm.service.propertyconfig.IMetaName, com.sapportals.wcm.service.propertyconfig.IMetaContext)
*/
public Component renderMetaProperty(IMetaName metaName, IMetaContext rendererContext)
throws WcmException {
// TODO Auto-generated method stub
if(metaName == null)
return null;
try
{
IResource res = rendererContext.getResource();
IResourceFactory factory = ResourceFactory.getInstance();
IRepositoryServiceFactory repServiceFactory = factory.getServiceFactory();
IRepositoryService repositoryService = repServiceFactory.getRepositoryService(res, IWcmConst.APP_PROPERTIES_SERVICE);
IApplicationPropertiesService aApplicationProperty = (IApplicationPropertiesService)repositoryService;
IAppPropertyMap appProperties = aApplicationProperty.getProperties(res);
IAppProperty currentProperty = null;
if(appProperties != null)
currentProperty = appProperties.get(new PropertyName(metaName.getNamespace(), metaName.getName()));
if(metaName.isReadonly() || !metaName.isMaintainable() || !PropertyDisplayMode.CREATE.equals(rendererContext.getDisplayMode()) && !PropertyDisplayMode.EDIT.equals(rendererContext.getDisplayMode()) && !PropertyDisplayMode.DISPLAY.equals(rendererContext.getDisplayMode()))
return renderProperty(currentProperty, rendererContext.getResource(), 0);
else
return null;
}
catch(Exception e)
{
CatchBlockHandler.handle("PropertyRendererHitscount", "Exception", e, false, false);
throw new WcmException(e);
}
}
public Component renderProperty(IAppProperty property, IResource res, int maxLength)
{
Integer result = null;
TextView resultText = null;
if(res == null)
return null;
try
{
if(property == null)
{
PropertyName propertyNameHitCount = new PropertyName("http://sapportals.com/xmlns/cm","hitscount");
IResourceFactory factory = ResourceFactory.getInstance();IRepositoryServiceFactory repServiceFactory = factory.getServiceFactory();
IRepositoryService repositoryService = repServiceFactory.getRepositoryService(res, IWcmConst.APP_PROPERTIES_SERVICE);
IApplicationPropertiesService aApplicationProperty = (IApplicationPropertiesService)repositoryService;
property = aApplicationProperty.getProperty(propertyNameHitCount,res);
if(property == null)
return null;
}
}
catch(WcmException wcmEx)
{
CatchBlockHandler.handle("PropertyRendererHitscount", "WcmException", wcmEx, false, false);
log.warningT("Could not retrieve hitscount property for <" + res + ">; " + LoggingFormatter.extractCallstack(wcmEx));
return null;
}
result = property.getIntegerValue();
resultText.setTooltip(result.toString());
resultText.setText(result.toString());
resultText.setWrapping(true);
return resultText;
}
/* (non-Javadoc)
@see com.sapportals.wcm.service.propertyconfig.renderer.IStructuredPropertyRenderer#processEvent(com.sapportals.wcm.service.propertyconfig.IMetaName, com.sapportals.htmlb.event.Event, com.sapportals.wcm.service.propertyconfig.IMetaContext, com.sapportals.htmlb.page.DynPage)
*/
public String[] processEvent(
IMetaName arg0,
Event arg1,
IMetaContext arg2,
DynPage arg3)
throws WcmException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
@see com.sapportals.wcm.service.propertyconfig.renderer.IStructuredPropertyRenderer#getProperties(com.sapportals.wcm.service.propertyconfig.IMetaName, com.sapportals.wcm.service.propertyconfig.IMetaContext, com.sapportals.htmlb.page.DynPage)
*/
public IPropertyMap getProperties(IMetaName metaName, IMetaContext rendererContext, DynPage dynPage)
throws WcmException {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
@see com.sapportals.wcm.service.propertyconfig.renderer.IStructuredPropertyRenderer#renderMetaNameLabel(com.sapportals.wcm.service.propertyconfig.IMetaName, com.sapportals.wcm.service.propertyconfig.IMetaContext)
*/
public Component renderMetaNameLabel(IMetaName metaName, IMetaContext rendererContext) {
// TODO Auto-generated method stub
if(metaName != null && rendererContext.getResourceContext() != null)
{
Label textView = new Label("l_" + metaName.getId());
textView.setText(metaName.getLabel(rendererContext.getResourceContext().getLocale()));
textView.setTooltip(getPropertyTooltip(metaName));
boolean invalid = rendererContext.getInvalidMetaNames() != null && rendererContext.getInvalidMetaNames().containsKey(metaName.getId());
textView.setValid(!invalid);
textView.setRequired(metaName.isMandatory());
return textView;
} else
{
return renderSpacing();
}
}
public String getPropertyTooltip(IMetaName metaName)
{
if(metaName != null)
return metaName.getFullId();
else
return "";
}
public Component renderSpacing()
{
return new HTMLFragment("KEVIN");
// return new HTMLFragment("<nobr> </nobr>");
}
}
Thanks everyone!
Hi Kevin,
to make your life more easy, I would suggest to start with a simple implementation of <i>AbstractPropertyRenderer</i>, implementing <i>public Component renderProperty(IProperty property, IResource resource, int maxlength)</i>. This way, you should get a first result with 20 lines or less. If it doesn't work, check the default.trc for any exception. And/or try to debug your code.
Hope it helps
Detlev
PS: You have implemented a wrapper service for adding your application classpath to the CrtClassloaderRegistry? You have added all SharingReferences needed?
PPS: Mark code with the "Code"-marker function of the SDN editor, this way it get's much more readable.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
9 | |
9 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.