Two ways we can render the library component in custom JSP,
1. Using WCM library component tag
2. Using Workspace render method
Using Library Component tag
After initializing workspace using init:workspace , you can use the below tag to render the library component
>wcm:libraryComponent name="Name of the component" >[Error Message]>/wcm:libraryComponent >
Using Workspace render method
String libComponentName="LibraryComponentName";
String libCompFinalStr="";
LibraryComponent libComp = null;
DocumentIdIterator docIds = wcmWorkspace.findByName(DocumentTypes.LibraryComponent,"LibraryComponentName");
if (docIds.hasNext()){
DocumentId did = (DocumentId)docIds.next();
newsLibComp = (LibraryComponent)wcmWorkspace.getById(did);
libCompFinalStr = wcmWorkspace.render(renderingContext, libComp);
}
output of the LibraryComponent will be in "libCompFinalStr" , you can display that string wherever you want
jsp tag only works if your component is in the same library. Library option does not seem to work for tag.
ReplyDeleteBased on the infocenter library option should work fine and below is the tld definition
Delete<tag>
<name>libraryComponent</name>
<tagclass>com.ibm.workplace.wcm.api.WCM_LibraryComponentTag</tagclass>
<teiclass>com.ibm.workplace.wcm.api.WCM_LibraryComponentTag$TEI</teiclass>
<bodycontent>JSP</bodycontent>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>library</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
..........................
And it is working fine when I tested it like below from the JSP
<wcm:libraryComponent name="test_img" library="anonymous">
You do not have access to this item.
</wcm:libraryComponent>
probably you may need to raise PMR if it doesn't work as mentioned in info center .
This comment has been removed by the author.
ReplyDeleteHi Siva,
ReplyDeleteI have to three text element in a library. I need to fetch all three test element value at JSP. I need your help to do this.
Thanks.