Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Adding image dynamically
newbie321
<p>Hi, </p>
<p> </p>
<p>I need to change the URI of image at a runtime, The target xml code should look sometihng like this:</p>
<p> </p>
<div>
<pre class="_prettyXprint">
<image name="myImage" id="177">
<property name="height">2in</property>
<property name="width">2in</property>
<property name="source">file</property>
<expression name="uri" type="constant">c:\temp\image.jpg</expression>
</image></pre>
<p> I am able to set pretty much everything through Java except the '<strong>type="constant"</strong>' tag. the following java code would produce xml almost identical to above, except <strong>type="constant" </strong>is missing</p>
<pre class="_prettyXprint">
ImageHandle image= (ImageHandle) reportDesignHandle.findElement("myImage");
image.setWidth("2in");
image.setHeight("2in");
image.setFile("c:\\temp\\image.jpg");</pre>
<div>
<pre class="_prettyXprint">
<image name="myImage" id="177">
<property name="height">2in</property>
<property name="width">2in</property>
<property name="source">file</property>
<expression name="uri">c:\temp\image.jpg</expression>
</image></pre>
<p>Anyone knows how to set the "type=constant" through Java?</p>
<p>Thanks! </p>
</div>
</div>
Find more posts tagged with
Comments
micajblock
<p>This might be easier</p>
<p> </p>
<p><a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/files/file/815-dynamic-image-in-a-library/'>http://developer.actuate.com/community/forum/index.php?/files/file/815-dynamic-image-in-a-library/</a></p>
;
newbie321
<blockquote class="ipsBlockquote" data-author="mblock" data-cid="138736" data-time="1440507272">
<div>
<p>This might be easier</p>
<p> </p>
<p><a data-ipb='nomediaparse' href='
http://developer.actuate.com/community/forum/index.php?/files/file/815-dynamic-image-in-a-library/'>http://developer.actuate.com/community/forum/index.php?/files/file/815-dynamic-image-in-a-library/</a></p>
;
</div>
</blockquote>
<p> </p>
<p>Thanks,
@mblock
!</p>
<p> </p>
<p>That example is using JavaScript in the event handler. I specifically need to change the location of the location of the image through Java. </p>
<p> </p>
<p>Best,</p>
micajblock
<p>Sorry, I do not know how to do this in Java.</p>
JFreeman
<p>Have you tried something like:</p>
<pre class="_prettyXprint _lang-js">
image.setTypeExpression("constant");
</pre>
<p>I've not had a chance to test this but from the api doc it looks like that might do it.</p>
newbie321
<p>When I run</p>
<pre class="_prettyXprint">
image.setTypeExpression("constant");</pre>
<p><span style="color:rgb(102,102,0);">the xml changes from </span></p>
<div>
<pre class="_prettyXprint">
<property name="source">file</property>
<expression name="uri">c:\temp\image4.jpg</expression></pre>
<p><span style="color:rgb(102,102,0);">to </span></p>
</div>
<div>
<pre class="_prettyXprint">
<property name="source">expr</property>
<expression name="typeExpr">constant</expression></pre>
<p>I played a little bit more with this issue by trial and error and I think I actually figured it out. </p>
<p>The path to the file name needs to be in quotations. </p>
<p>ie</p>
<pre class="_prettyXprint">
ImageHandle.setFile("\"c:/temp/image4.jpg\"");</pre>
<p>I also discovered that it's best to use forward slashes. </p>
<p>I was using backslashes thinking they will resolve, but they don't:</p>
<pre class="_prettyXprint">
ImageHandle.setFile("\"c:\\temp\\image4.jpg\"");</pre>
<p>To use back slashes, you actually have to double escape them. One escape is for java string and another escape is for birt ie:</p>
<pre class="_prettyXprint">
ImageHandle.setFile("\"c:\\\\temp\\\\image4.jpg\"");</pre>
<p> Here the xml will becomes like</p>
<pre class="_prettyXprint">
<expression name="uri">"c:\\temp\\image4.jpg"</expression></pre>
<p>Yeah, this is very tricky and non-intuitive, but makes sense when I look at it retrospectively. </p>
<p> </p>
<p>I appreciate your time and follow-through on this
@JFreeman
. </p>
<p>There is tons of things about BIRT that I am still learning as I go through different problems. </p>
</div>
JFreeman
<p>Thank you for providing the full details of your findings.</p>
<p>I'm glad to hear you have figured it out.</p>
<p> </p>
<p>Let us know if you have additional questions.</p>