Log in (form-based) from JSF page - jsf

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.

Related

How to listen on a stateless POST request and set JSF managed bean properties

I have a Java-EE application that works with JSF (ManagedBean, ManagedProperty, ect ...) and Spring framework. I need to be able to retrieve data via a javascript form sent from an external website. I have opened the rights to authorize the CORS (Cross Origin or Cross Domain).
I would like to know what is the best way to grab an external form with JSF so that it is processed by my ManagedBean.
To make my question more explicit I made a diagram
==============
EDIT
The application works with JSF, I'm looking for a way to retrieve data (from a Javascript form on an external site) in a ManagedBean under JSF. I tried to retrieve this data by creating a Java-EE standard servlet and using the doPost ... methods of HttpServlet. But this solution does not work (this was the subject of my previous question on S.O). Several people told me that in a web application do not mix Java-EE standard and JSF, it is either Servlet or JSF. I made a diagram (above) explaining quickly what I am trying to do.
To recap: I would like to retrieve data from an external website (via a Javascript form) in the ManagedBean of my application.
==============
I've already tried with a standard Java-EE servlet but it's not the right way. Indeed, with a standard servlet I can recover the data from the form but I can not access the ManagedBean. I must therefore have abandoned this hypothesis.
I did not find a similar question about Stackoverflow, If necessary I can give more indications.
Thank you for your help.

Jsf Primefaces Remember fileUpload name on back page [duplicate]

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

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.

JSF 2 Content Controller (pull in content based on URI)

I'm new to JSF and am trying to make a content controller. Basically whenever someone makes a request to www.myapp.com/external/** I'd like to forward to a controller that pulls external content into a page template and spits it out to the user.
For example /external/test/test.html might pull in content from a location XXYYZZ/test/test.html.
I was able to achive this pretty easily in Spring 3, but I'm a little confused on where to start with JSF.
I feel like I'd need to create a custom servlet to handle /external/**? But what would the class of this servlet be? What would it consist of?
Any help is appreciated!
I would suggest you not do this with the JSF servlet. Instead, do this with JAX-RS, or a custom servlet, or continue to do it with Spring. Map the custom servlet to a different URL pattern than your JSF pages. That way you can use JSF for the pieces where it is appropriate, and serve your static content as appropriate.
While I've never done so myself, Google yields plenty of examples where people have integrated Sping and JSF.

Resources