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
thumbnail
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.
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
thumbnail
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:

&lt;#assign portal_url = portalUtil.getPortalURL(company.getVirtualHostname(), portalUtil.getPortalPort(), true) /&gt;
&lt;#assign articlesWebServiceURL = portal_url + "/c/journal/get_articles?groupId=${scopeGroupId}&amp;delta=100&amp;approved=true&amp;expired=false&amp;orderBy=display-date" /&gt;
&lt;#assign articleWebServiceResult = saxReaderUtil.readURL(articlesWebServiceURL) /&gt;
&lt;#assign root = articleWebServiceResult.getRootElement() /&gt;

&lt;#assign images = root.selectObject("//dynamic-element[@name='Images']/dynamic-content/text()") /&gt;

&lt;#if images?is_sequence&gt;
        &lt;#assign temporary_image_src = "" /&gt;
        &lt;#list images as images_e&gt;
                &lt;#assign temporary_image_src = temporary_image_src + images_e.getText() /&gt;
                &lt;#if images_e_index gte 2&gt;
                        &lt;#break&gt;
                <!--#if-->  
        <!--#list-->
        &lt;#assign images = temporary_image_src /&gt;
&lt;#else&gt; 
        &lt;#assign images = images.getText() /&gt;
<!--#if-->

<img src="${images}">