{"id":8,"date":"2006-11-28T21:58:07","date_gmt":"2006-11-29T01:58:07","guid":{"rendered":"http:\/\/hardlikesoftware.com\/weblog\/2006\/11\/28\/web-app-investigation-part-1-jsf\/"},"modified":"2006-11-28T21:58:07","modified_gmt":"2006-11-29T01:58:07","slug":"web-app-investigation-part-1-jsf","status":"publish","type":"post","link":"https:\/\/hardlikesoftware.com\/weblog\/2006\/11\/28\/web-app-investigation-part-1-jsf\/","title":{"rendered":"Web app investigation part 1 &#8211; JSF"},"content":{"rendered":"<p>One of my main interests right now is web application development. About 8 or 9 years ago I created my first simple web application (just a few pages) as an <abbr title=\"Internet Server Application Programming Interface\"><a class=\"gloss\" title=\"Internet Server Application Programming Interface\" href=\"\/weblog\/glossary#ISAPI\">ISAPI<\/a><\/abbr> <abbr title=\"Dynamic Link Library\"><a class=\"gloss\" title=\"Dynamic Link Library\" href=\"\/weblog\/glossary#DLL\">DLL<\/a><\/abbr>. I was not paying any attention to HTML standards at this time. It didn&#8217;t seem like many people were. I don&#8217;t think I even knew what CSS was back then.<\/p>\n<p><!--more-->More recently I worked on a web application in Java using Struts. This project was done under great time pressure and there was little time to investigate different frameworks. Struts seemed a safe bet just by its reputation. By that time I was aware of web standards and the importance of following them. Still there wasn&#8217;t much time to learn all the details but we tried. Working with Struts had its frustrations but looking back Struts was a good choice for this project.<\/p>\n<p>After this I got a chance to learn C# and .NET. I didn&#8217;t get much hands on experience but learned a little. This was my first exposure to view state and it struck me as a bad idea then and I haven&#8217;t changed my mind about it yet. We had to work with an in-house developed web <abbr title=\"User Interface\"><a class=\"gloss\" title=\"User Interface\" href=\"\/weblog\/glossary#UI\">UI<\/a><\/abbr> framework on top of .NET. For simple things it was very simple but anytime you wanted to do something more interesting it got extremely difficult.<\/p>\n<p>I decided to do some investigation in web application development. I wanted to get a feel for some of the different frameworks as well as to learn more details about doing HTML and CSS the right way. The idea was to create a very simple web <abbr title=\"application\">app<\/abbr> with a few different sets of technologies. It only needed two pages but it should also have some depth so that I could get a feel for internationalization, error handling and reporting, input validation, and separation of presentation from business logic.<\/p>\n<p>The app is very simple as I said. It prompts for two numbers then on submit displays a page that shows their sum and difference with a link to go back to the first page. To explore input validation a little more I later added a radio button group to constrain the input numbers to both be even, both be odd or allow any numbers.<\/p>\n<p>I had already worked with Struts so there was no need to investigate it any more. I also didn&#8217;t feel a strong need to try other Model 2 frameworks similar to Struts. I may go back and look at some of these later. I choose Java Server Faces (JSF) + Facelets, Servlet + StringTemplate, and raw servlet as a baseline. I was very interested in <abbr title=\"Java Server Faces\">JSF<\/abbr> because of the buzz about it. I choose StringTemplate because the paper &#8220;<a title=\"mvc.templates.pdf\" href=\"http:\/\/www.cs.usfca.edu\/~parrt\/papers\/mvc.templates.pdf\">Enforcing Strict Model-View Separation in Template Engines<\/a>&#8221; really resonated with me.<\/p>\n<p>I used the latest <a href=\"http:\/\/tomcat.apache.org\/\">Tomcat<\/a> and <a href=\"http:\/\/www.mysql.com\/\">MySQL<\/a> mostly because I had used older versions of them in the past and liked them. I was going to be learning many new things and didn&#8217;t need to learn a new servlet engine and database. I also wanted to use the new <abbr title=\"Java Development Kit\">JDK<\/abbr> 5.0.<\/p>\n<p>One of the first things I learned was that JSF 1.2 doesn&#8217;t work with Tomcat 5 because JSF 1.2 requires the latest <abbr title=\"Java Server Pages Standard Tag Library\">JSTL<\/abbr>. From what I read it didn&#8217;t seem worth it to use an older version of <abbr title=\"Java Server Faces\">JSF<\/abbr>. Also I didn&#8217;t want to switch to GlassFish because it would be something additional to learn. I wanted to stick with Tomcat if at all possible. I found that JSF 1.2 could be used with Tomcat 5 if you use Facelets rather than <abbr title=\"Java Server Pages\">JSP<\/abbr>. After reading more it seems to me that Facelets are the way to go anyway &#8211; much better than <abbr title=\"Java Server Pages\">JSP<\/abbr> + <abbr title=\"Java Server Faces\">JSF<\/abbr>.<\/p>\n<p>The simple app went together quickly with most of the time spent learning JSF and getting my environment set up (for example installing a bunch of plugins to Eclipse for web development).<\/p>\n<p>The next thing I learned about JSF was that, like .NET, it uses view state. When I looked at the generated HTML for my simple page with two labels, two edit controls, and a button I found a hidden input for the view state that was 1873 bytes. All this for a page that was 3280 bytes in total. The view state accounted for more than half the size. My simple application didn&#8217;t need any of this overhead.<\/p>\n<p><abbr title=\"Java Server Faces\">JSF<\/abbr> has built-in support for <abbr title=\"Internationalization\"><a class=\"gloss\" title=\"Internationalization\" href=\"\/weblog\/glossary#i18n\">i18n<\/a><\/abbr> of text strings that uses standard Java resource bundles and the Facelets tags h:outputText and h:outputFormat. Simple validation is also very easy, but all validation is done server side which is not the best thing to do. Client side validation can be done but requires more work (I didn&#8217;t bother).<\/p>\n<p>I wanted to explore how to do complicated validation such as when the value of one control depends on the value of another (this is when I added the radio control). This caused a problem because the UI has no idea about the dependencies in the backing bean. So how do you do validation in the backing bean when the validation depends on other fields that will not be updated until all validation passes? I solved the problem by using a change listener on the radio button group. When it changed I updated the model constraints field. This did not work correct at first because the listener was being called after the validation. I had to also use the immediate attribute on the selectOneRadio control. I think this is very cumbersome. In general I find the whole request processing lifecycle to be more complicated than needed (as compared to the servlet API for example).<\/p>\n<p>The bottom line is that JSF is not the right framework for me. Building up a tree of controls on every GET or POST request just to throw them away again seems wasteful to me as is the view state. JSF can do client side validation and <abbr title=\"Asynchronous JavaScript and XML\"><a class=\"gloss\" title=\"Asynchronous JavaScript and XML\" href=\"\/weblog\/glossary#AJAX\">AJAX<\/a><\/abbr> but it doesn&#8217;t out of the box. I guess I was hoping for a richer set of controls. It looks to me like there is a lack of focus on the HTML, JavaScript and CSS that is generated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of my main interests right now is web application development. About 8 or 9 years ago I created my first simple web application (just<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/hardlikesoftware.com\/weblog\/2006\/11\/28\/web-app-investigation-part-1-jsf\/\">Continue reading<span class=\"screen-reader-text\">Web app investigation part 1 &#8211; JSF<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/posts\/8"}],"collection":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":0,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/posts\/8\/revisions"}],"wp:attachment":[{"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/media?parent=8"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/categories?post=8"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hardlikesoftware.com\/weblog\/wp-json\/wp\/v2\/tags?post=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}