fres nillo

Greenhorn
+ Follow
since Feb 01, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by fres nillo

I have some doubts about one development related to different frameworks and .properties files.

I'm developing three projects, there are one with desktop java J2SE that uses a native .properties (not connected with nothing, it's used to manage and adapt local files to be ingested), other that have Struts2 framework and uses the default .properties file for i18n (used to manage the content of the frontend) and other more, based on SpringMVC and Liferay which uses the standard way to get a property (the target front-end).

The problem is that now, I want to unify these three projects, and the only way that I have into my head is use a common library that request for a property, and get the target code. The problem is that I have to adapt all the projects and all the called getText(KEY) functions should be replaced by these target library.

My question is if there is other way to load several .properties files with a library, and take advantage of the current framework of each project, because the only solution that I've thought is replace all the called getText() functions and call to a external library that check if there are one property of each .property file, but with this solution I have some problems with SpringMVC.

Thanks in advance for any idea.
10 years ago
I don't know why you use:

# HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
# String filename =request.getParameter("userImageFileName");
# int id =Integer.parseInt(request.getParameter("id"));

when the easy way to do this is only creating an attribute in action with a getter, and setter if you need it, with the same name that you have in the jsp:

# <s:param name="userImageFileName" value="%{userImageFileName}"></s:param> <--
# <s:param name="id" value="%{id}"></s:param></s:url> <--
# <s:a href="%{fileDownload}"><s:property value="userImageFileName" /></s:a>

<s:a href="%{fileDownload}?userImageFileName=<s:property value="userImageFileName" />&id=<s:property value="id" />">

OR

<s:a href="%{fileDownload}?userImageFileName=document.getElementsByName('userImageFileName')[0].value&id=document.getElementsByName('id')[0].value"><s:property value="userImageFileName" /></s:a>


I hope that it was useful for you.
13 years ago
Thanks for your quick response, but I don't have any idea how it's related with the question about a file uploader with progress status, please reply if I'm in a mistake.

I thought about using the interceptor execAndWait to send the progress like this (putting the progressBar in a iframe):
...
dojo.io.iframe.send({
url: ...upload.action,
method: 'post',
handleAs: 'json',
load: function(response){
var progress = response.percentComplete;
document.getElementById('progressBar').style.width = progress+"%";
});
...

I extracted that from http://stackoverflow.com/questions/4073140/strut2-execandwait-interceptor-json-result-type-dojo-dijit-progressbar-ajax, but I don't have any idea what is or where is the FileProcessor class (non ProcessFileAction).

Thanks.
13 years ago
Hi all

I want to use an file uploader with a progress bar with Struts2, which works with all internet browsers but there is a problem with that.

I had to develop an Ajax solution with a boundary to "skip" the file upload interceptor (to send data like a form.submit() ), but the solutions works only if the browser permit read the file (in IE with an ActiveXObject which calls to system file read methods, with Firefox with FileReader, in Chrome 9 in other way; but Safari, Chromium and Opera don't have support with that because it's based in File HTML5 API).

I have test develop an Flex3 & 4 solution too, but the problem is that the server has an self-signed certificated ssl connection, and Flex doesn't support this certification type.

Is there an implementation/plugin (ot is it known) that supports ssl self-signed certification with Struts2 that works in all explorers? I see that in Struts1 works with a Listener that sends to client with JSON the status data uploaded, but I didn't see nothing in Struts2 that works fine.

Thanks.
13 years ago
Solution:

I test it and works for me, the idea was build all the post source code and send it like this:

var BOUNDARY = "myMark------"+(new Date).getMilliseconds();
var source = '';
source += "--" + BOUNDARY + "\r\n" + "Content-Disposition: form-data; name=\"fileNameInAction\"";
source += '; filename="' + file.name + '"' + "\r\n" + 'Content-type: ' + file.type;
source += "\r\n" + "\r\n" + file.getAsBinary() + "\r\n";
req += "--" + BOUNDARY + '--';
httpRequest.open("POST","action.action");
httpRequest.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
httpRequest.sendAsBinary(req);
13 years ago
Hi Tom, thanks for your response, I can tell you that the form has a mutipart/form-data in the <form> tag, because if I do a submit it works perfectly. In the example I changed xmlHttpRequest.setRequestHeader("Content-Type","application/octet-stream") by xmlHttpRequest.setRequestHeader("Content-Type","multipart/form-data"), and the result is the same, debugging is viewed that the client don't send all the data before the server finish his action (File and InputStream has a null value and only has been sent the header data when it happends, seeing the traffic). I think that there is a configuration and it's needed to permit XMLHttpRequest with FileUpload Interceptor because the client waits finish the server action and has a response (in my case an HTML with error because the file is empty).
13 years ago
Hi all,

I have to said that there are alternatives to this method, but I want to implement this with Struts2 without any new libraries (like ajax-file-upload-struts2), because it works with a simple upload.
I have an action that caught files of a simple form with submit action. It's using in server the FileUpload interceptor and when there is a submit the file go to the server successfully.
Well, the problem happens when it's used an XmlHttpRequest to send this file.
In a summary, here is the code:

var file = document.forms[0].httpFile.files[0]
xmlHttpRequest.open("POST","upload.action",true);
upload = xmlHttpRequest.upload;
upload.addEventListener("progress", function (e) {
if (e.lengthComputable) {
console.log((e.loaded/e.total)*100);
}
}, false);

xmlHttpRequest.setRequestHeader("Cache-Control", "no-cache");
xmlHttpRequest.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlHttpRequest.setRequestHeader("Content-Type","application/octet-stream");
xmlHttpRequest.setRequestHeader("X-File-Name", file.name);
xmlHttpRequest.setRequestHeader("X-File-Size", file.fileSize);
xmlHttpRequest.setRequestHeader('Connection', 'close');
xmlHttpRequest.send(file);

The file is sent to server, but when server launch the action, file is null, I tried with inputstream but i have the same problem. If I submit the form from javascript, it works fine but not with XmlHttpRequest and I don't have any idea why it happens (i think that can be changed the request header and send the full form, but I have changed it and didn't work for me!)

By the way, is possible use the HTML5 feature to see what is the percent uploaded with Struts2 framework in server?

Thanks, and sorry for my English
13 years ago