Jsf Primefaces Remember fileUpload name on back page [duplicate] - jsf

I am using <p:fileUpload> component. Is it possible to preselect and show the selected file in field before the browse button?
I am using Mojarra 2.0.3, PrimeFaces 2.2 RC2, GlassFish 3.

No, if this was possible, this would have been a huge security hole. You would then in theory be able to let the selected file point to C:/path/to/passwords.txt and then use JavaScript to submit the form and so silently get a file with sensitive data from the client without its permission.
See also:
How to set a value to a file input in HTML?
Send full client side file path to server side using p:fileUpload

Related

Anyway to upload file by ajax in JSF?

I need to upload file ajax so that I can show the name of uploaded file but without adding any jar files like primefaces, richfaces.
My form is inside dialog box where I have an upload button which should call a method by ajax. My code is something like this...
<h:commandButton value="Upload" action="#{bean.uploadMethod}">
<f:ajax listener="#{bean.abcMethod}" event="click"/>
</h:commandButton>
and I would also like to know if I can just browse, keep the name of file in some list to show and then I can submit my whole form. This submission should also upload those files which I have shown the name in list. Is it possible?
I'm also struggling with uploading files (images) through AJAX. I've looked for several methods and how companies like Google or Dropbox implemented this.
So far I found two methods:
Use an iframe to submit the file. This isn't actually AJAX, so it works in most browsers. However I have yet to see an implementation (other than PrimeFaces') in JSF.
Encode the file client side with base64, send through AJAX and decode on the server side. However I haven't seen an implementation in JSF and I haven't got the time past days to actually cook something up.
If you want a quick solution you can use primefaces, richfaces (and probably icefaces). But you already said you didn't want to use one of those.
Maybe someone is nice enough to post a real solution here, but I thought I'd throw in an idea or two. ;-)
Primefaces offers the FileUpload component which is a fully AJAX enabled file upload JSF component.
Here is the showcase example
I am not complete sure how it works but I believe it utilizes modern browser features through HTML5. This functionality of course requires that the client be a modern browser that can understand HTML5 markup.

Why does JSF process the entire form

We are developing web application using JSF. We are using rich faces on Jboss server. We have a4j command buttons , command links and a4j js functions to invoke server actions.
We have set limit render to true, render only required components. And I also set execute to "#this" . We are observing a strange behavior , All the actions associated with the form are also executed along with the button clicked, even though we have not specified the execute value to "#this". This is bringing down the performance drastically.
Is this the way JSF process POST requests or is there something else we are missing?
What you're currently describing in the question is definitely not the default behaviour of JSF nor RichFaces.
Your concrete problem is caused elsewhere. As per the comments, you seem to have created a PhaseListener for logging purposes which is re-executing the entire view for some reason. You'd need to turn off this PhaseListener or to fix its implementation.

reRender a JSF1.2 componente programmatically

Sometimes, I have to reRender some component in my applications (using JSF1.2 and RichFaces 3.3.2).
Is possible to do that programmatically in server side, or just the old school way, in client side?
Thanks.
Components are always rendered on the server (markup is then sent to the browser for DOM update). If you need to decide in runtime which components to re-render, you can do reRender=#{bean.compoentsToRender}
Take a look at <a4j:poll> or <a4j:push>.

How to preset the value of p:fileUpload

I am using <p:fileUpload> component. Is it possible to preselect and show the selected file in field before the browse button?
I am using Mojarra 2.0.3, PrimeFaces 2.2 RC2, GlassFish 3.
No, if this was possible, this would have been a huge security hole. You would then in theory be able to let the selected file point to C:/path/to/passwords.txt and then use JavaScript to submit the form and so silently get a file with sensitive data from the client without its permission.
See also:
How to set a value to a file input in HTML?
Send full client side file path to server side using p:fileUpload

Log in (form-based) from JSF page

Using JSF 1.2 and RichFaces 3.3.1 on JBoss 4.2.3.
I've just started on a JSF Application. It uses XHTML files for most of its content, and a login.jsp with form-based authentication for logging in, something I understand is common in JSF applications. However, I now need to include sections from the regular pages, which include a header bar and a right panel, that have RichFace styles. I've tried dozens of combinations of ways to put the Rich tags into the login page, while still allowing the submit to go through j_security_check, but so far nothing has worked. Is there a way to do this?
Just convert login.jsp to login.xhtml. It doesn't matter for j_security_check where the request is coming from. You can just use plain HTML in a JSF/Facelets page.

Resources