Fórum
How to get image path in structure
Manjula Lakshmi, modificado 8 Anos atrás.
How to get image path in structure
New Member Postagens: 4 Data de Entrada: 27/08/15 Postagens Recentes
Hi All,
I have created two fields. One is Test box(Title) another one is Image(Image) fields in Structure. I am able to get Text box value by using below code. Same way i writen code to image it is getting NullPointer Exception. Please help me how to get image/folder path.
ServiceContext serviceContext = (ServiceContext)workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);
Map<String, Serializable> serviceContextAttb = serviceContext.getAttributes();
String structurefields = serviceContextAttb.get("_fieldsDisplay").toString();
String[] fields = structurefields.split(",");
for (String key : fields){
if(key.contains("Title"))
String title = serviceContextAttb.get(key).toString();
else if(key.contains("Image"))
String image = serviceContextAttb.get(key).toString();
}
Thanks
Manju
I have created two fields. One is Test box(Title) another one is Image(Image) fields in Structure. I am able to get Text box value by using below code. Same way i writen code to image it is getting NullPointer Exception. Please help me how to get image/folder path.
ServiceContext serviceContext = (ServiceContext)workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);
Map<String, Serializable> serviceContextAttb = serviceContext.getAttributes();
String structurefields = serviceContextAttb.get("_fieldsDisplay").toString();
String[] fields = structurefields.split(",");
for (String key : fields){
if(key.contains("Title"))
String title = serviceContextAttb.get(key).toString();
else if(key.contains("Image"))
String image = serviceContextAttb.get(key).toString();
}
Thanks
Manju
Bijan Vakili, modificado 8 Anos atrás.
RE: How to get image path in structure
Expert Postagens: 375 Data de Entrada: 10/03/09 Postagens Recentes
I'm not sure why it wouldn't be working; though do you know what attributes in this: workflowContext, serviceContext, serviceContextAttrb -- there are several ways you can find out; simplest is to add a print statement; otherwise you can set breakpoints in code (and run the server in the debug mode).
Note you can specify the script contexts:
https://github.com/liferay/liferay-portal/blob/6.2.x/definitions/liferay-workflow-definition_6_2_0.xsd#L40
which allow you to have code in portlet; for easier debugging purposes ; though I assume you already knew that; otherwise couldn't use the generics; since the scripting language don't support.
Note you can specify the script contexts:
https://github.com/liferay/liferay-portal/blob/6.2.x/definitions/liferay-workflow-definition_6_2_0.xsd#L40
which allow you to have code in portlet; for easier debugging purposes ; though I assume you already knew that; otherwise couldn't use the generics; since the scripting language don't support.
Manjula Lakshmi, modificado 8 Anos atrás.
RE: How to get image path in structure
New Member Postagens: 4 Data de Entrada: 27/08/15 Postagens Recentes
Hi Bijan Vakili,
Thanks for your reply.
But i am not able to get image path in structure. Please suggest me to provide another way how to achieve it.
Thanks
Thanks for your reply.
But i am not able to get image path in structure. Please suggest me to provide another way how to achieve it.
Thanks
Bijan Vakili, modificado 8 Anos atrás.
RE: How to get image path in structure
Expert Postagens: 375 Data de Entrada: 10/03/09 Postagens Recentes
One way would be to get the XML and query it with an xpath as follows in freemarker code (though you can do the same in Java or scripting as well):
Note this script works with 6.2 GA3 and should work with 6.2.x:
Note this script works with 6.2 GA3 and should work with 6.2.x:
<#assign portal_url = portalUtil.getPortalURL(company.getVirtualHostname(), portalUtil.getPortalPort(), true) />
<#assign articlesWebServiceURL = portal_url + "/c/journal/get_articles?groupId=${scopeGroupId}&delta=100&approved=true&expired=false&orderBy=display-date" />
<#assign articleWebServiceResult = saxReaderUtil.readURL(articlesWebServiceURL) />
<#assign root = articleWebServiceResult.getRootElement() />
<#assign images = root.selectObject("//dynamic-element[@name='Images']/dynamic-content/text()") />
<#if images?is_sequence>
<#assign temporary_image_src = "" />
<#list images as images_e>
<#assign temporary_image_src = temporary_image_src + images_e.getText() />
<#if images_e_index gte 2>
<#break>
<!--#if-->
<!--#list-->
<#assign images = temporary_image_src />
<#else>
<#assign images = images.getText() />
<!--#if-->
<img src="${images}">