anu 86 |
: |
Display different images within the portlet |
|
|
|
|
|
I'm developing JSR-168 compatible portlet for Liferay using the Netbeans portal pack. The purpose of my portlet is to display a pie chart according to some values in a database. In the edit mode (myportlet_edit.jsp)of the portlet I gave a form for the user to fill the text value in order to retrieve the data from the database. (Eg: Month of the year) |
|
|
|
|
|
Then in the view.jsp file, I connected to the database and retrieved the required details for the month selected by the user, to generate the pie chart.Then I generated the pie chart using JFree and stored it as an .png image within the folder liferay-portal-5.2.3\tomcat-6.0.18\webapps\myportlet. Every thing is fine up to that point and I get the correct piechart image within the folder everytime I change the month.
|
|
|
|
|
|
But the problem is it is not correctly displayed at the portlet. In the view.jsp file of my portlet I used the following code to display the generated pie chart. |
|
|
|
|
|
|
|
|
|
|
|
When I deploy the portlet for the first time, it displayed the correct image according to the selected month and which is stored in the folder. But when I set the month again and refresh the page,correct chart is generated at the folder, but the chart is not changed at the portlet. |
|
|
|
|
|
Can someone please help me to solve this issue. Since this is urgent matter, any help would be highly appreciated. |
|
|
|
Mazhar Anwar |
: |
Hi, |
|
|
|
|
|
Rather than storing to file system, you can directly send image to browser by using any Servlet or serveResource method of |
|
|
|
|
|
PortletAPI and by using Java Script or ajax you can change the src of your image <img> tag. |
|
|
|
|
|
something like |
|
|
|
|
|
document.getElementById('<portlet:namespace />chartImage').src = url; |
|
|
|
|
|
where url will be your Servlet call or serveResource Method call which will return you an image and this will solve your problem. |
|
|
|
|
|
Regards |
|
|
|
Ankur Srivastava |
: |
Are you doing a form submit upon month change event.. ? |
|
|
|
anu 86 |
: |
Thanks lot for your immediate replies. Yes I'm using a form to get the month from the user. It is in myportlet_edit.jsp file as below |
|
|
|
|
|
|
|
|
|
|
|
Then in the processAction method of the myportlet.java file I did the following. |
|
|
|
|
|
|
|
|
|
|
|
Then in the do_view method of the myportlet.java file I did the following. |
|
|
|
|
|
|
|
|
|
|
|
Finally in the myportlet_view.jsp file I did the following. |
|
|
|
|
|
|
|
|
|
|
|
Then based on this filterValue I queried my database and created the jfree pie chart with those retrieved values as below. |
|
|
|
|
|
|
|
|
|
|
|
Then at the end of <% %> tags of the above java codes, I did the following to view this saved chart. |
|
|
|
|
|
|
|
|
|
|
|
Although the correct chart is displayed for the first time in the porltet, next times when I submit a new month the chart doesn't changed in the portlet. (But the correct chart is created and saved within the folder /webapps/myportlet/piechart.png) |
|
|
|
Babu Janarthanan |
: |
Hi, |
|
|
|
|
|
I Guess this is due to hard coding the file name as "piechart.png". instead you can create file name using ServletUtilities.saveChartAsPNG(chart, 280, 180, null, null). you can also take a look at admin portlet for JFree chart implementation(server.jspf) |
|
|
|
|
|
hope it helps you. |
|
|
|
|
|
Thx, |
|
|
Babu |
|
|
|
anu 86 |
: |
Hi Babu, |
|
|
|
|
|
Although it is sometimes back, thanks lot for your guide. But I still have problems in it. First I added the following to my WEB-INF/web.xml file of the portlet. |
|
|
|
|
|
|
|
|
|
|
|
Then I changed the previous view.jsp file of my portlet and now it has the following code to create the chart. |
|
|
|
|
|
|
|
|
|
|
|
But now it doesn't display the chart within my portlet. There is only a small red dot in the chart area. |
|
|
|
|
|
So can anyone please help me on this...Since I'm new to this area, any help would be really helpful. |
|
|
|
|
|
Thanks, |
|
|
|
No comments:
Post a Comment