markrgli Posted May 8, 2009 Share Posted May 8, 2009 Hi guys,Is it possible to set the image path/data of a report (from a .jrxml file) at runtime?I have these JRXML files that have image placeholders (there are image elements in the design file but the expressions are not set) and I need to set the path/data of the image from my code after I load the design file. Is this possible? Attached is the code I tried but apparently it didn't work.Any ideas?Thank you in advance.MarkCode:JasperDesign design = JRXmlLoader.load(jasperFile); JRElement elem = design.getDetail().getElementByKey("banner");if (elem instanceof JRDesignImage) { JRDesignImage img = (JRDesignImage) elem; // Tried debugging and confirmed that this line is called. img.setExpression(new JRDesignExpression() { private static final long serialVersionUID = 1L; @Override public String getText() { return "D:\\images\\sample.jpg"; } @Override public Class getValueClass() { return String.class; } @Override public String getValueClassName() { return String.class.getName(); } });} Link to comment Share on other sites More sharing options...
markrgli Posted May 8, 2009 Author Share Posted May 8, 2009 I've found the solution. :)Hope it will be of any help to others.Code:JasperDesign design = // load designJRBand band = design.getDetail();// "banner" is the key of the image "placeholder" in my design fileJRElement elem = band == null ? null : band.getElementByKey("banner");if (elem instanceof JRDesignImage) { JRDesignImage img = (JRDesignImage) elem; JRDesignExpression expr = new JRDesignExpression(); expr.setText("\"D:/images/sample.jpg\""); expr.setValueClass(String.class); expr.setValueClassName(String.class.getName()); img.setExpression(expr);} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now