JSF calls actions on CDI bean when page is loaded - jsf-2

In a JSF file addLink.xhtml I use a CDI bean LinkAdapter. When the JSF file is processed, every method in the LinkAdapter is called several times, although most of them aren't even referenced anywhere in the whole project by now.
The LinkAdapter is #Named and #SessionScoped. But I think that this is not relevant, since it seems to happen with every other bean in any other JSF file.
Can anyone tell me the reason of this behavior?
I use JBoss AS 7.0.2, prettyfaces (JSF2) 3.3.2 and Weld 1.0.0.Final

Related

faces-config.xml keep updating itself

I have 2 faces-config.xml file.
I created a new page and added bean into the second file.
However, the first faces-config file automatically keeps adding bean to it as well.
Thus, every time I tried to refresh a page there is a classNotFoundException because there are 2 classes
for that page.
Can anyone tell me the cause and how to fix this?
(I am using ibm rad6)

Some managed beans are not loaded

I have an issue with a perfectly working application (JSF 2, primefaces, tomcat 6). I have many Managed Beans that work just fine, but lately when I try to add a new Managed Bean the views dont seem to recognize it. Even more, there is no error message the application manages to ignore controls refering to the new managed bean and even by using debugging I don't have access to the #PostConstruct method when the view loads. this seems to be the issue for whatever control I put in my view.

icefaces 3 - Cannot reach the backing bean from pages inside WEB-INF

I upgraded icefaces version from 1.8 to 3 and I'm facing the following problem:
everytime I call a method in a backing bean form pages inside WEB-INF, I have the error "Network connection interrupted" and, in firefox I see when I hover the button, POST mypage.jsf , STATUS 404 Not Found.
Can anybody help me, please?
If I move the pages outside WEB-INF it works, but I wouldn't change all the structure of my project...
Thank you very much
I suggest you to move pages outside WEB-INF. This directory has a specific meaning in web application deployment. It holds configuration and (e.g.) classes used by servlet.
Web container should not serve the content of this directory, if in 1.8 this happen, probably it's a bug that has been fixed.

JSF 2 Mojarra and Primefaces in WebSphere 7+

I have been struggling with the unholy alliance that is WebSphere 7+ and Mojarra 2.0.4 and have run into something of a showstopper.
I followed the directions as specified at this forum post and got Mojarra 2.0.4 initializing properly: http://forum.primefaces.org/viewtopic.php?f=3&t=6860
Basically I created an isolated classloader shared library that refers externally to the Mojarra and Primefaces jars, added the shared library to the webapp and reversed the classloader to go PARENT_LAST. All of that works.
When I attempt to access my web app http://server:port/context/index.xhtml it is hitting the FacesServlet correctly but then instantly the Request Dispatcher is redirecting to index.jsp???
I don't have any JSP specified ANYWHERE in my code, my app, my web.xml, and in fact I specified DEFAULT-SUFFIX to be .xhtml and that didn't help. All my web pages are .xhtml extension and FacesServlet is mapped correctly to *.xhtml.
I have tried adding XHTML as a mime type to WebSphere, disabling the Request Dispatcher, all to no avail. I have been able to get this running correctly on Tomcat 6-7, JBoss 6 and Glassfish 3 with no problems but for some reason WebSphere insists on a JSP file extension?
I appreciate any help you might have.
WAS7 sometimes does not undeploy the web applications properly. Clearing WAS_PROFILE_HOME/temp and WAS_PROFILE_HOME/wstemp may help.

Why do we need beans.xml while working with JSF web application?

I started web development using JSF, after studying JSP and Servlets for a while.
When you create a JSF web application you always(may be often but I am not sure if it always or not) have to create beans.xml and you don't write anything in it. But, if that file doesn't exist the JSF web app will not work.
What is the reason behind that?
Why we need that file?
Please, detailed explanation.
Adding to the answer of Micheal; CDI is not only useful in combination with JSF because of the injection support, but also because of its support to be used with EL (expression language). This is a feature JSF heavily depends upon.
In fact, CDI beans can almost entirely replace JSF managed beans and therefor you'll find lots of examples using them and a good amount of JSF books advising their use. For JSF applications CDI beans have e.g. the following advantages:
Can inject smaller scopes into larger scopes. E.g. request scoped GET parameters can be injected into a session scoped bean. This is not possible with JSF managed beans.
Can take advantage of the conversation scope; a scope that spawns multiple different pages.
Very unfortunate is that in JSF 2.0 and 2.1 the extremely handy view scope is not supported by CDI beans by default, although extensions like Seam can add these. (update: in JSF 2.2 there's a new view scope that does work with CDI beans)
All in all the confusion between JSF Managed beans and CDI beans is such that there's a JSF spec issue for this, see http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-976
The presence of a beans.xml file signals the servlet container that the application uses JSR-299 (Contexts and Dependency Injection) - without it, the application's classes will not be scanned for CDI annotations either and dependency injection will not be performed. If you don't use CDI (e.g. you only use plain JSF managed beans), you don't need beans.xml. If you do, you can use the file (instead of annotations) to define CDI configurations - this allows you, for example, to provide a test configuration where some dependencies are replaced with mocks.
From Getting Started with Contexts and Dependency Injection and JSF 2.x
When the application is deployed the server looks for CDI managed beans. In a Java EE 7 application, the classes on the path are scanned for CDI annotations by default. In a Java EE 6 application, the classes are scanned for CDI annotations if the module contains a beans.xml file.

Resources