留言板

How to get image path in structure

Manjula Lakshmi,修改在8 年前。

How to get image path in structure

New Member 帖子: 4 加入日期: 15-8-27 最近的帖子
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,修改在8 年前。

RE: How to get image path in structure

Expert 帖子: 375 加入日期: 09-3-10 最近的帖子
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,修改在8 年前。

RE: How to get image path in structure

New Member 帖子: 4 加入日期: 15-8-27 最近的帖子
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,修改在8 年前。

RE: How to get image path in structure

Expert 帖子: 375 加入日期: 09-3-10 最近的帖子
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}">