Hi,
i want to refere to the image in velocity template, but i dont know how. I have this web resource:
<web-resource name="SNPluginImages" i18n-name-key="sn-plugin-images.name" key="sn-plugin-images"> <description key="sn-plugin-images.description">The SNPluginImages Plugin</description> <resource name="ajax-loader.gif" type="download" location="/images/ajax-loader.gif"> <param name="content-type" value="image/gif" /> </resource>> </web-resource>
And in velocity im trying to use :
<img id="sn-value-ajax-loader-image" src="$requestContext.baseUrl/download/resources/com.intelek.serialnumberChecker:sn-plugin-images/images/ajax-loader.gif" />
But it doesnt work. What is right syntax for referes ?
Thank you.
Community moderators have prevented the ability to post new answers.
You can't use /images/ in your path unless you map the directory. Here you are mapping the image directly and hence you should try something like
<img id="sn-value-ajax-loader-image" src="/jira/download/resources/com.intelek.serialnumberChecker:sn-plugin-images/ajax-loader.gif">
It is better to map the directory as:
<resource type="download" name="images/"location="images/"/>
And do what you are doing now.
Thats it ! :) Good to know, its working like shortcut. Thank you. Its working now !
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It would help to know where are you trying to use the velocity template. More specifically who populates the context.
You could use JiraVelocityUtils.createVelocityParams(jiraAuthenticationContext) to get all sort of helpful stuff in the context (like the baseUrl).
For the rest of the url, I usually use the WebResourceUrlProvider to get the link based on the keys in the atlassian-plugin.xml.
HTH,
Florin.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Florin,
its on edit.vm on customfield.
package com.intelek.jira.customfields; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.atlassian.jira.issue.customfields.impl.TextCFType; import com.atlassian.jira.issue.customfields.manager.GenericConfigManager; import com.atlassian.jira.issue.customfields.persistence.CustomFieldValuePersister; import com.atlassian.jira.issue.customfields.impl.FieldValidationException; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.fields.config.FieldConfig; import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem; import java.util.List; import java.util.Map; public class serialnumberCF extends TextCFType { private static final Logger log = LoggerFactory.getLogger(serialnumberCF.class); public serialnumberCF(CustomFieldValuePersister customFieldValuePersister, GenericConfigManager genericConfigManager) { super(customFieldValuePersister, genericConfigManager); } @Override public Map<String, Object> getVelocityParameters(final Issue issue, final CustomField field, final FieldLayoutItem fieldLayoutItem) { final Map<String, Object> map = super.getVelocityParameters(issue, field, fieldLayoutItem); // This method is also called to get the default value, in // which case issue is null so we can't use it to add currencyLocale if (issue == null) { return map; } FieldConfig fieldConfig = field.getRelevantConfig(issue); //add what you need to the map here return map; } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For the baseUrl you can get it using
map.putAll(JiraVelocityUtils.createVelocityParams(jiraAuthenticationContext));
and the WebResourceUrlProvider via constructor injection.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Uh, i am not familiar with these methods and java , so its chinese for me now.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So, you get the authentication context like this.
ComponentAccessor.getJiraAuthenticationContext()
And then use it to get the velocity params
map.putAll(JiraVelocityUtils.createVelocityParams(jiraAuthenticationContext));
This will allow you to use $baseurl in the velocity context, as you said before.
Then, for the second part, you'll need the WebResourceUrlProvider in your class.
private WebResourceUrlProvider urlProvider; public serialnumberCF(CustomFieldValuePersister customFieldValuePersister, GenericConfigManager genericConfigManager, WebResourceUrlProvider urlProvider) { super(customFieldValuePersister, genericConfigManager); this.urlProvider = urlPorvider; }
Now that you have it as a member in your class, you can use it to get the url of the resource using urlProvider.getStaticPluginResourceUrl(...). (or use Jobin's solution below for this second part, it's better)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try ${requestContext.baseUrl}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried ${requestContext.baseUrl}, but it doesnt work.
Image (in firebug) is now :
<img id="sn-value-ajax-loader-image" src="/jira/download/resources/com.intelek.serialnumberChecker:sn-plugin-images/images/ajax-loader.gif">
But there is no image, and firebug is saying 404. Is atlas-run rerun needed ? or just fastdev will be enough.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.