I am using MyFaces 1.1.14. I have two JSPX pages with JSF components and my managed bean is in request scope. At first page, bean constructor is getting fired and when I submit a form it is fired again. But after my app navigates to the new page, it is not getting fired. The constructor is supposed to be called, right?
The thing is that page is accessing some properties of the bean — those setters get called — no problem with that, but why is the constructor not called? When the page get loaded I need to get data from previous process (i.e from different framework). What is the problem with my understandings?
The navigation does by default not fire a new HTTP request. Instead, a different view is been used as content of the current HTTP response. Only when you navigate with a redirect by appending the <redirect/> entry to the <navigation-case>, then a new HTTP request would be created.
You should totally understand it if you're familiar with RequestDispatcher#forward() concept of the basic Servlet API which JSF is sitting on top of.
See also:
What is the difference between redirect and navigation/forward and when to use what? - Note that the code examples are targeted at JSF 2.x, but the principles apply as good on JSF 1.x.
Related
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.
There is a requirement in the webapp I am developing (not changeable unfortunately ) that states that I have to send via post certain parameters to a servlet from a JSF managed bean. That servlet then forwards to a page where it shows some of the parameters sent via POST in a form for the client to see.
That servlet is part of an external application, thus I cannot use RequestDispatche.
I have tried Apache Http client but i get to a point that the post URL responds with the content of the page (i can actually see the HTML in my logs), what i would like to do is forward to the page not receive it as answer in my code.
If this makes no sense let me know :).
EDIT:
what i need to do is:
JSF BEAN->POST data to an external servlet -> Follow servlet redirect/forward to an external page
One way I'm thinking of doing this is forwarding to an internal facelets or JSP page that builds a hidden form with all required parameters and automatically submits it to the post Servlet
So after trying to find other ways to do it, I have decided to go this way:
Create an internal page, with a hidden form that will be automatically committed with a small javascript.
Get all required data in the bean, navigate to page, fill hidden fields with the required info, post to external servlet.
I should also say that a better way to do this kind of interaction would be:
Post data to servlet (for example using apache http client)
manage the servlet response (for example 200 OK)
navigate via GET (using a redirect) to the servlet by passing some id as a
get parameter through which the data can be shown in the page
This would require the servlet to accept POST and get requests, and also to have a way to get the data sent via post when it's called via get. This was not the case for us.
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.
(Using JEE6) Is it possible to have a webpage automatically update (or listen) to values from within a bean/class and display them on the JSF when these changes happen?
As KayKay mentioned you can implement some sort of polling methodology using javascript to ask the server periodically to send updates if there are any. And unless you use ajax you will have to be content with only complete page refreshes.
JSF as good as it is, sits on top of basic stateless web technology. As such unless you use Ajax or some custom code the server will only respond to a request from the client. Some libraries like icefaces have incorporated a "push" component that allows what you are looking for (from what I understand, this is a fundamental part of icefaxes). That is, to push server side changes to the client.
You have to set up a listener on your end so that your bean will be notified when a value change happens on the server (like in your backing bean which is on the server). When the change happens you can ask say, 'icefaces push' (or another library like primefaces, which you indicate you don't want to use) to send a notice to the client. The client side code (usually ajax/javascript) will process the notice and then send a request for the whole object per normal request response. That is the notice tells the client something it's interested in changed so the client can ask for an update. Aside from the notice, still request/response.
I mention icefaces push because it seems to be the favoured library for this now. But others have this as well. I don't believe the standard JSF 2.0 AJAX libraries have this.
Here are a couple of resources to look at:
(The video is a good start to get the idea of what is going on, then use the rest of the site)
http://www.icesoft.org/demos/icepush-demos.jsf
Older but I think still relevant IBM tutorial on what you want to do, using inventory changes as an example:
http://www.ibm.com/developerworks/web/library/wa-aj-dynamic/index.html
And another stack question related:
Is there a better Ajax Push for JSF 2.0 than Icefaces
Unfortunately it looks like you cannot do this with just JSF, you will have to use one of these libraries or even harder, roll your own push mechanism.
I don't know of a JSF feature to do so. I would simply do some javascript polling, using for example jquery load method to refresh the parts of the page where the values are displayed.
It would help to know what you want to do : refresh the whole page when there is a change, update somes values that are displayed from the start, or add new values to the page.
i have a jsf application in which i have three frames,one for the header,one for side navigation and the other is the mainframe.I have built this in the spring framework.
I have a problem that when the HttpSession object gets timed out the apllication gets forwarded to the Login page(which is correct,and is the starting page of the app) but within the mainframe so i have a nested application.btw i am running this app in websphere and i can set the HttpSession timeout variable to a very high value so that this problem will occur less,but this is not a solution.
Any ideas on how i can get around this problem.
iFrames are really a bad thing!
What I suggest is to use the Facelets library, which allow you to easily create templates of pages. In your case, you will be able to create the three differents parts (header, navigation side and main page).
Once created, the result will be a single HTML page (i.e. no frames).
This way, you will not encounter your problem anymore.
You have several articles that explains the main features of Facelets, including the templating.