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.
Related
I am on a team that is interested in using ui:include to embed external resources in a HTML document. While investigating how to do this, I came across this post: JSF Facelets how to include external html?
BalusC clarifies that is the wrong tool for embedding external resources in a HTML document and suggested using iframes instead. My question is: why is it the wrong tool?
The team I'm on is especially concerned about security. The content is all going to be our own, but there is a concern about cross-site scripting when communicating between iframes. I've read that there are security benefits to using iframes, as well.
Since the answer likely depends on the use case, I will describe mine:
We're using a docking framework called wcdocker (http://docker.webcabin.org/), which allows panels to be added as divs (planning to use ui:include) or via iframes.
From what I've read/experienced so far, my main concern is that you would have to load the entire page for a given panel, even if the user might not actually open it. There will be multiple dockers, and each will have about 50 panels that can be opened. I am concerned that the client will be overwhelmed, compared to a simple link that may/may not be opened in the given docker.
My second concern is with conflicts if the user attempts to open the same panel twice (same ID tags, omnifaces socket conflicts where the backing bean declares a PushContext for a viewscoped recipient, etc.). I have read workarounds for some of this, sounds like a headache...
Their main concern is regarding communication between panels and cross-site scripting attacks. They believe the user's panel communication should be done directly on the client side, so that the server does not have to be hit at all. I believe the user's panel communication should be done on the server side via a custom publish/subscribe approach (not via JMS) where panel A publishes to a custom Java "topic" object and panel B subscribes to that topic.
For context, there will be a maximum of 50 users at a time, and the web application will be fairly complex.
After a lot of research, there is at least one issue with my question: our content will not be "external" at all. It will be content that resides on the same server as the main application.
Anyway, it seems that at least one concern with iframes is having too many view states. This thread is the most relevant to that problem: JSF multiple views limit. There is a limit to the number of views (15): (ViewExpiredException after upgrade to jsf2)
You can increase that limit in the web.xml file, but it may be difficult to identify the right number for the problem described above.
In another thread, BalusC indicates that ui:include is the best way to put an xhtml inside another xhtml (How to include another XHTML in XHTML using JSF 2.0 Facelets?). However, ui:include does not appear to be ideal for dynamic content. With wcdocker, a panel may be added/removed at any time. It may be worth using jquery's load method as an alternative. See this thread for more information, even though it's for PHP's ui:include: Best way of loading/including content? (jQuery's load() vs. PHP's include())
For anyone interested in using wcdocker in a JSF project while avoiding iframes, this code is a good starting point:
myDocker.registerPanelType('My Panel', {
onCreate: function (myPanel) {
var $mydiv = $('<div id="div1"></div>');
myPanel.layout().addItem($mydiv, 0, 1).css('text-align', 'right').stretch('1%', '');
myPanel.on(wcDocker.EVENT.LOADED, function() {
$("#div1").load("thepage.xhtml");
});
}
});
Finally, you may still run into an issue with conflicting id's, particularly if you load the same page twice. This thread may help you to resolve that concern, and it may even be wise to determine ID by a url parameter: Avoiding duplicate ids when reusing facelets compositions in the same naming container
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.
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.
first I have to admit this might be a pretty specific problem. In a JavaServer Faces Application I want to be able to let a script run on the server-side interact with the user.
To give you more of a detail I give you an example of what I want to do:
In my application a user can input data and on the server side there is a script which can check/modify this data. I don't know the exact script because the user is able to make a custom one. All in all so far there is no problem, but in the script it is possible to do interactions with the user in the way of a question dialog. In the following example, the further script execution depends on the answer of the user.
...
if( inputData.equals("Something") ){
if( askUser("Question?","Some question...") )
{
doSomething();
}
else
{
doSomethingElse();
}
}
...
As you can see the method "askUser" has to wait for the result before the script can continue. The script itself is a Beanshell-script and the method "askUser" is a Java method which is called by the Beanshell interpreter.
I had in my mind to use threads and Java synchronization methods to let the script pause, but thread creation is not allowed by EJB. Still I tried that way, but it failed due to the FacesContext not being available in user-created threads.
I hope I could make my intention clear and you have any idea how this could be done... Thanks in advance. :)
Your question demonstrates a complete misunderstanding of how not only JSF technology works, but also the inherently stateless nature of HTTP communication and web servers.
Typically in a desktop based application this simple algorithm you listed above can be easily implemented, probably with modal dialogs and events. Web applications do not work this way because they are inherently stateless. A user or browser agent makes an HTTP request to a web server, the server processes this request and formulates a response, then returns that HTTP response back to the browser agent to be rendered. Typically this data can be textual, HTML, XML, Javascript, CSS, images or even a file.
The problem with incorporating the algorithm above on a server is that the functionality for askUser cannot possibly be done by the server, because the server cannot just ask the user a question and wait for the response. That would be backwards. The user is the client and asks questions of the server.
So how is this common problem solved in a web application? In JSF, the server can send as a response a Javascript to the browser that will allow the browser to ask the question, then when the user makes the choice, the Javascript can then post back the selection of the user to the server in an HTTP request. If that selection involves any changes to the DOM or page elements at all then that information will be sent in the response.
JSF bridges the gap between desktop and web applications by allowing giving the illusion of desktop and event driven functionality to an otherwise stateless technology, and it does this by having an event lifecycle on the serverside and using Ajax to tightly control changes to document elements.
A good tutorial on JSF technology can be found here, however I recommend becoming more familiar with HTTP and Java Servlets before you delve too deep: http://www.mkyong.com/tutorials/jsf-2-0-tutorials/