Sonntag, 14. November 2010

Open word from java

One easy way to open a certain doc-file from java is here:

public void open(){
Runtime rt= Runtime.getRuntime();
try {
String path="C:/Program Files/Microsoft Office/OFFICE/WINWORD.exe";
String filename="C:/test/myfile.doc";
Process p =rt.exec(path+" "+filename );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

Montag, 4. Januar 2010

Caching problem with JavaScript or what else ?

This is an show-case application wich demonstrates a problem.
It consists out of 2 portlets that communicate with each other through IPC.
The whole application is created with ICEFaces 1.8.0 and runs in Liferay 5.22.

In the left portlet an entry from the menu is selected, and the corresponding values are shown in the right portlet. The content in the right portlet is served by a managed bean. The content itself contains much JavaScript, so you can say the managed bean delivers JavaScript-code.







The belonging values to the users selection are showed in the right portlet.
The user chooses an value from the select-menu.
The values of the right portlet - let us call them items - are in an array,
the items array.


var items = new Array();
items[0] = Array('id1','100');
items[1] = Array('id2','200');






If the user clicks on an item, the correspondning value should be shown.
As defined in the items array this is :


100 for item1


200 for item2


If the user click on the id the value is shown in green. In the picture the value 100 is shown for item1.

The function showValue() which has access on the items array prints the corresponding value:


function showValue(number){
document.getElementById('value').innerHTML=""+items[number][1]+"";
document.getElementById('value').style.color="green";
document.getElementById('value').style.paddingTop="25px";

}


The items of the right portlet are defined by html in the following way:


<tr>
<td onclick="showValue('1');">item1</td>
</tr>
<tr>
<td onclick="showValue('2');">item2</td>
</tr>





Problem

Above is described as it should work, but it does not. As mentioned before the workflow is the following:


The user selects an entry in the left portlet, JavaScript-Code is generated in the bean and is setted to the right portlet, and then this is rendered with the ICEFaces mechanism defined though the interfaces Renderable and DisposableBean.
After the render the item in the right porlet are available - as it should be - but the showTable() function doese not work. After an refresh with F5 the function works as it should. It has to be mentioned, that after the render with the ICEFaces-interfaces the showTable HTML-JavaScript code is available and correct but does not work. An explicit refresh with F5 is necessary to get it to work.


Has anybody an idea for the reason?



In this picture you can see further strange behaviour.
If the user select the second entry in the left portlet, the corresponding items are correctly shown in the right portlet. But if you click on item1 it shows the value 100 for the item1 from the last selection insteaf of 333 for the actually selection.


So this behaviour leads me to this point:

The items array with the values that the user sees differs from this one the function showValue() uses. The items array the user sees is the actually one, but the one the function showValue uses is the old one.


Is this a cache problem? And if yes, how to update the items value in the cache? Is this only through F5 possible? The disadvantage with F5 is that all portlets are rendered new on the page instead of the desired ones if it is when using the ICEFaces Renderable and DisposableBean.

The Eclipse-project and the war file is available here:

Liferay-Forum

Best regards,

Gaston