JSF framework without JavaScript - jsf

Is there any JAva Server Faces framework implementation, that doesn't produce nor uses any JavaScript inside generated output?
No JavaScript nor AJAX, pure HTML with optional static resources like CSS.
If possible, also without using cookies." By framework.

You can just use the standard JSF implementation. The <h:commandLink>, <h:button> and <f:ajax> are the only components which generate and require JavaScript. If you just don't use them, then you're already set. As alternatives you could use <h:commandButton> or <h:link> respectively and then throw in some CSS to make it look like a link or button respectively.
As to cookies, this is only created when JSF makes (in)directly use of the HttpSession. Just toggle to client side state saving by setting javax.faces.STATE_SAVING_METHOD to client, or make JSF stateless by <f:view transient="true">. Also and don't use #SessionScoped managed beans. #ViewScoped is already not possible in stateless JSF — although "useless" is a better term — if you make JSF stateless). Stateless JSF only requires a minimum of Mojarra version 2.1.19, older versions didn't support it. You also need to keep in mind that stateless JSF is more sensitive to forgery attacks, but that's not JSF's fault.
See also:
When should I use h:outputLink instead of h:commandLink?
Difference between h:button and h:commandButton
Why JSF saves the state of UI components on server?

Related

Can I use more than one JSF implementation in the same project?

Can I use more than one JSF implementation in the same project?
Can I mix PrimeFaces with MyFaces for example?
What are implications of that?
No, you cannot mix JSF implementations. By the way, PrimeFaces is not a JSF implementation. MyFaces is a JSF implementation, just like Mojarra.
You could however mix component libraries like PrimeFaces. See for example how you can use both BootsFaces and PrimeFaces, or OmniFaces and PrimeFaces (OmniFaces is mainly a utility library, but has some components).
Note that you do need a JSF implementation in order to be able to use a JSF component library at all. If you are using a JavaEE server (like Payara or WildFly), the JSF implementation is already provided by the server.
See also:
JSF implementations and component libraries

Is JSF's Managed bean a stateful bean

I am trying to understand the life-cycle of JSF and I was reading through the following tutorial:
JSF tutorial
it says :
The view contains all the GUI components and there is a great deal of
state management by JSF to track the status of the view – typically
using HTML hidden fields.
I am confused that whether JSF Application keep that Managed bean's state during its interaction with the client is interacting, or it uses HTML hidden fields for the same, and mock a stateful bean.
The term "JSF state" does not concern managed bean properties (the model values). It concerns the UI component properties, such as required, valid, immediate, disabled, readonly, rendered, etc. This is basically referenced by only one hidden input field and not multiple fields as that tutorial seems to imply. That hidden input field is the one with javax.faces.ViewState prefix in the name.
Technically, JSF managed beans are always stateful. Statefulness is expressed by whether or not having mutable instance variables. Javabeans are basically always mutable and thus stateful. JSF managed bean state is however not stored in the "JSF state". JSF managed beans are just stored in server's memory, usually as an attribute of the HTTP request, session or application.
See also:
Why JSF saves the state of UI components on server?
Unrelated to the concrete problem, the tutorial you're reading is a JSF 1.x targeted one. JSF 2.x was introduced 5 years ago already. In case of developer tutorials, always pay attention to the publish date and also what version it treats. You can get started at our JSF wiki page.

JSF/Facelets backing beans and EJB3

I have a few questions on the various options and best practices when using JSF with EJB3.1. The mental model I have, given the daunting amount of choices and combinations available, is far from clear so some questions may not make sense.
JSF/Facelets reference backing beans (I am using the term "backing bean" for beans whose properties are written or read from Facelets pages) through EL code that is agnostic as to the actual annotations used in the bean classes (javax.faces.bean.* or javax.enterprise.context.*).
Is it correct to say that one can toggle between JSF and CDI scope annotations just by changing the imports in the bean classes without any changes to the Facelets xhtml code?
Is it an established pattern that JSF/Facelets should be used only for the xhtml markup code with all scope and lifecycle (plus injection) annotations done using CDI?
In a JBoss AS setting, where is the lifecycle management of the JSF backing beans (using either JSF or CDI annotations) taking place? In the web container or in the EJB3 container?
In a typical web application given that the SessionScoped beans can be provided by CDI, is there any need for using EJB3 beans other than those of type #Entity, e.g. for the last typical step in each "flow" when information is to be persisted in the database?
Is it correct to say that one can toggle between JSF and CDI scope annotations just by changing the imports in the bean classes without any changes to the Facelets xhtml code?
Yes.
Is it an established pattern that JSF/Facelets should be used only for the xhtml markup code with all scope and lifecycle (plus injection) annotations done using CDI?
JSF is moving towards CDI. The new #FlowScoped annotation of the upcoming JSF 2.2 is evidence of this as this extends from the CDI API. The only disadvantage is that CDI doesn't offer a standard annotation for the tremendously useful JSF #ViewScoped annotation. You'd need #ConversationScoped wherein you manually start and end the conversation, or take a look at a CDI extension like MyFaces CODI.
In a JBoss AS setting, where is the lifecycle management of the JSF backing beans (using either JSF or CDI annotations) taking place? In the web container or in the EJB3 container?
The web container (in flavor of a WAR). JSF is built on top of the Servlet API, so it's definitely the web container.
In a typical web application given that the SessionScoped beans can be provided by CDI, is there any need for using EJB3 beans other than those of type #Entity, e.g. for the last typical step in each "flow" when information is to be persisted in the database?
The #Entity is part of JPA, not of EJB. The #Entity is to be used on a model class which is mapped to a database table and usually solely meant to transfer data across the layers. What you're last describing sounds like candidate for a #Stateful EJB. To understand #Stateless vs #Stateful EJBs better, head to this detailed answer: JSF request scoped bean keeps recreating new Stateful session beans on every request?

Access busniess logic before showing page and share bean for multiple pages

I have a jsf 1.2 application where I need to show a page (jsp) which has a backing bean. Most examples I see for help show a blank jsp for user ot edit. In my case I need to get some Data from DB before jsp loads, how to accomplish this?
I tried #postconstruct on a backing bean method but if I share this bean with multiple JSPs it is initializing the info for all pages, I need different data for different page and each page should read some data from db before displaying in JSP.
I am coming from Struts background where I would invoke the URL for the Action which will call have Business logic to get data and then I would direct to JSP. For accomplishign this with JSF it seems not pretty straightforward.
I tried #postconstruct on a backing bean method but if I share this bean with multiple JSPs it is initializing the info for all pages, I need different data for different page and each page should read some data from db before displaying in JSP.
The page (view) should have its own request/view scoped backing bean which is not shared elsewhere. That should fix your "problem" (which is actually just a design matter). Do not use a single session scoped bean for multiple views. That's wrong use of the session scope.
I am coming from Struts background where I would invoke the URL for the Action which will call have Business logic to get data and then I would direct to JSP. For accomplishign this with JSF it seems not pretty straightforward.
JSF and Struts are very different. JSF is a component based MVC framework while Struts is an action based MVC framework. You should not design JSF backing bean classes while having Struts action classes in mind. Going through some decent JSF tutorials should put you on the right track. For an overview, see also the bottom of our JSF wiki page.
Please note that JSF 1.2 is completely outdated. JSF 2.0 has been released over 2 years ago already. If this is a new application or just hobbying, I recommend to forget JSF 1.2 and continue with JSF 2.0.

Best JSF framework/library for "conversation state"

What do people think is the best JSF framework or library for a saving state longer than request scope (but w/o using session scope) that is backbutton/new window safe -- i.e. you have a "wizard"/multi-page form.
For example, MyFaces has the 'SaveState' tag that allows you to maintain state across pages by saving state in the view's component tree. Any comments on SaveState (pros/cons) or suggestions for any better framework or library for this capability?
The t:saveState works perfectly. It's only a bit 'low level' and not tied to a particular bean. There are two other libraries/frameworks which comes to mind which provides control over conversation scope at higher level (e.g. bean-specific tags/annotations):
Apache MyFaces Orchestra (uses tags)
JBoss Seam (uses annotations)
Update: JSF2.0 has added a new scope which achieves a conversation-like state, the #ViewScope. Very useful if you can reuse the same view for subsequent actions.
i think Spring Web Flow is a good solution. you can define your flow as XML and it can integrate with JSF, Struts, Spring MVC, ZK,...
http://www.springsource.org/webflow

Resources