This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Using Facelets for action-based MVC views  RSS feed

 
Saloon Keeper
Posts: 10107
212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Discussion split from here.)

On that note, does anyone have experience using JSF 2.x as a template language only?
 
Saloon Keeper
Posts: 20641
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I follow you.

JSF has a built-in MVC controller system and it's responsible for compiling the View Templates and populating them, rendering them into transmitted HTML, then accepting data from the JSF forms, validating it, rejecting it if it's bad, applying it if it's good, and dispatching business logic. With an option for navigation to the next JSF View, if any.

You can (and frequently should) mix JSF and non-JSF code (for example, when creating PDF output). And JSF is not greedy. You can freely mix it with other MVC page processors such as Struts and Spring MVC.

But the Master Controller for JSF is the FacesServlet. What it renders is only suitable for processing by the FacesServlet. You can put non-JSF HTML forms on a JSF View Template, but you cannot use JSF control elements in them - you're basically no better off than if you'd simply done raw HTML without JSF.
 
Stephan van Hulst
Saloon Keeper
Posts: 10107
212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I mean is that I have an MVC 1.0 controller (this is pretty much the same as JAX-RS) that handles a request by doing business logic and then forwarding the result to a JSF page, which yes, is handled by FaceletServlet. The JSF page only performs presentation, no business logic.

From the MVC spec here, I gather that this is a valid option, but I need to avoid JSF forms:

MVC 1.0 Model-View-Controller Specification wrote:It is worth noting that if you opt to use Facelets as a view technology for your MVC application,
regular JSF post-backs will not be processed by the MVC runtime. The usage of <h:form /> and
depending form components like <h:inputText /> is not recommended as they would be the entry
point to a real JSF application.


So I guess what I'm wondering is, would there be enough of Facelets left to be able to use them easily for templates?

[edit]

I guess I'm confusing the terms JSF and Facelets here. I'm not looking to using JSF, I have MVC 1.0 for that. I just want to use Facelets for the view technology.
 
Tim Holloway
Saloon Keeper
Posts: 20641
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. I think I understand that.

Facelets was originally a third-party add-on to JSF version 1. It became integrated into the JSF standard in JSF version 2.0.

A lot of what Facelets does is like Apache Tiles, but Tiles was horrible, awkward, and (to me at least) inside-out. Facelets is a lot more straight-forward.

What you are describing sounds a lot like what I said about how JSF can happily co-habit with (multiple) non-JSF display technologies. What you are proposing, I believe, is simply to have a non-JSF input which dispatches to JSF output - a display-only JSF page. Nothing wrong with that. Although it's not MVC in the strict sense, since one View submits and another View receives, whereas to me "pure" MVC does its work using the same VIew and simply passes values back and forth to its Model(s).

Now if you wanted to back off one layer further and just use Facelets without the FacesServlet, I don't know if that would still work or not. The JSF internal tag structure for JSF 2 is considerably different than it was in JSF 1, where the JSF tags were essentially custom JSP tags. And definitely I wouldn't expect much joy from the non-Facelets tags - which means everything but the "ui" tag namespace.

So, as i said, any frontend you like should be able to forward to render via JSF and I've done so often. But I do recommend using JSF itself for forms data input. Forms are, after all, JSF's strongest feature.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!