Wow! Thank you for such a great informative reply.
I am well versed in MVC but as you pointed out, my understanding was much more in tune with Struts and others where I write the "extension" controller code.
I am glad my understanding of how to use EL is in line with what you said. I do not want to pollute my classes with the old JSP style scriplets and such. I was not totally aware of JSTL at this point but with your reply and Mr Tsang's I have a much clearer picture of MVC with JSF, although I am not quite sure yet how I do looping and conditionals without it? I don't know enough of the JSF components and such to understand how I won't need JSTL for loops and conditionals.
I am not sure if you're familiar with Ext-js? I was originally going to use it, but was told it's not nearly as performance capable for potentially well trafficked sites. I liked that it had really nice ajax and UI controls like pop up dialogs and a slick layout system that took care of cross platform and browser layout issues.. of which my expertise lies on the back end and not in the front UI. Is there anything within the JSF framework that mimics what Ext-JS offers in the way of pop up dialogs, layouts and such? I assume not as I haven't seen anything with regards to that.. I believe I need to handle all the CSS, layouts of components and such myself?
As for form actions, I am doing as Mr TSang mentioned.. I have a pojo that is JUST for model data, and a separate backing bean with the login method that uses a private instance of my pojo. In my form I have like he showed, #{login.user.username} for the input value. Does that sound right with what you are saying.. separating the pojos from the beans as much as possible? Also, perhaps I am doing things wrong, but in my previous use of Jersey with REST representations, I shared the model pojo with the rest representation class AND the back end entity bean using model delegation. For example I had something like this:
The above allowed me to share a common pojo model with the front facing REST representation class (which we hand coded rather than use JAXB to generate from an XSD for other reasons as well) AND the back end entity bean. When ever we modified the model, we'd just modify the representation and entity beans as well. It would allow me to handle a rest call to say create a user like so:
OK..so the reason I wanted to share this is to ask you if this seems to make sense in that I am sharing a POJO (separting it not only from the JSF annotations, but also the entity annotations) with the JSF (or in my example, REST representation) and the back end database. It also would allow me to more rapidly switch out either the front end or back end without breaking the model. I like the way this works out, and the only caveat is the little bit of extra code in each method to use delegation to the underlying model.
I think this fits well with what you are saying too.. in that I am breaking out the underlying model pojo from the rest of the system, keeping it clean and not dependent on anything specific. What do you think?
I do have a question.. something I am about to try out.. reading through the JSF 2.2 and JEE7, it looks like a big part of JEE7 is allowing for CDI in more places in the code. I know in JEE6, I could use @EJB (and @Resource) in servlets, and thus anything extending them including my resource classes like the example I have above. So can I use @EJB and @Resource (and I guess @Inject) inside of JSF backing beans? I want my login() method in the JSF backing bean to be able to call the EJB session bean that uses the user entity bean to look up the username and password. Is that now allowed (or was it even in JSF 2.x and JEE6)? If not, how then would a login method in the backing bean be able to call the EJB session bean to work with entities? I'll be trying this soon myself and may discover my own answer, but just in case I am hoping it can be answered here.
Also, I totally agree with you in using the JEE security model.. however I've never done that and I am not sure where best to discover how to implement that in a pretty JSF UI while using the JEE container login process? I've added a ProtectedResourceFilter to the web.xml filter section, so ensure nothing in my /secured/* can be reached IF the user is not logged in (which will result in a Session object in the HttpSession if they are). This is something I found online and looked reasonable to protect "inside" resources. Is this OK..or is this ALSO a bad way to do it and the JEE/Realm stuff should be used here as well? If you have a link or two that could point me to info on how best to implement that (especially in JEE7 if it's improved over JEE6), that would be fantastic.
Something else that EXT-JS had that I thought was nice is the notion of fragments.. or maybe I am forgetting the
word now.. but the idea was you could put together a few pages, backing code, etc.. and then insert that on any page where you wanted and it worked alone (you would pass in data no doubt). I am not sure if it could interact with other elements on the page, but it made it very reusable whenever you needed it. Naturally this would be like any JSF component now, but you could build up your own custom UI and code, and insert it as a fragment. I am currently using a template for my basic layout (header/content/footer) but thinking templates are a bit too abstract for what I am referring to. I'd want to not have to change a template layout to insert a fragment in some pages but not others. I'd even like the fragment to be potentially dynamically inserted.. perhaps a user selects something or changes something and now the fragment can be shown. I don't know well enough if templates are that dynamic but I think from what I've read you have to define them ahead of time. Giving a user say a selection of cool components they could just put wherever would make a template not the ideal choice in this case. So is there anything like a fragment where I can build up say a number of components into one fragment and reuse on any page?
And, finally. JSF is based on a state machine which tracks a lifecycle from the receipt of an incoming HTTP request to the transmission of the corresponding response. It is essential for anyone who wants to become competent in JSF to know that lifecycle and to understand the primary and secondary paths through the JSF lifecycle.
Yes.. I understand it to some degree, the request phase, validation phase, render phase, etc. But I am not an expert with it yet. This sort of reminds me of Android life cycle. I'll definitely learn it as I work with JSF.
One thing more. Some rules to live by:
1. JSF is designed to wrap functionality around POJOs. The more JSF-specific code you have written (excepting JSF model objects) in a backing bean, the more likely you did it wrong.
I assume this fits well with my example above if I understand you correctly? I completely put NO anything in my model pojos, just pure pojos, then with delegation and in the case of my login bean with the login method, it references the User pojo. Thus, did I do it correctly?
2. EL is not intended as a programming language. Its primary use with JSF is to define references to JSF backing bean properties and actions. If you code application logic on the View, you not only pollute the idiotlogical purity of the MVC paradigm, you create a mess, where you never know if logic is located in the Model or the View or in some unholy interacting cross-connection of both. Complex EL statements are also a royal pain to debug.
3. No, you shouldn't mix JSP's JSTL and JSF view definitions. Even though Oracle's documentation may suggest it. JSTL doesn't play that well with JSF, and almost anything that you can do with JSTL has a much cleaner JSF equivalent.
As I asked above, if I use pure EL with no JSTL, I am sure I'll learn but I assume there is a replacement for loops and conditionals? I think I saw the render attribute on components which when bounded with a backing bean property could conditionally control if it's displayed or not? I assume also then that putting a number of components (or like my question about a fragment above) inside a panel and tying it all with the panel redner attribute to a property in a bean, an entire section of components could be displayed/hidden?
The last remaining thought of mine is how to do this all with ajax? For example, instead of waiting to render or not redner a component with a bounding property, how about hiding/showing elements based on ajax requests/repsonses? That is.. I have a drop down with YES and NO. The user selects YES and a fragment shows up without a page refresh/redirect... they select NO and it disappears? I know how to write some javascript code to hide/show ids/classes.. I am just wondering if the JSF AJAX support can handle this for me without having to write javascript code myself? If so, I don't include any javascript code myself do I? Or do I need to say, include a jquery.js file to get some of this to work?
Thank you again for so much good info and appreciate any responses you can provide to my questions above.