JSF and JSP-tags in XML format
Hi!
I am testing out a couple of technologies right now to use further on in one of our larger projects. The technologies include JSF together with JSP and then Facelets to handle HTML templating.
Well, I got so far with the JSF that I felt comfortable with it (read Hnas Bergsten's book and everything) and decided to get the last piece of the puzzle working - templates. Facelets are pretty easy on paper and especially for me since I won't use the fancy stuff, I just want one nice template and then change the body part of it between my different pages.
Well, when using Facelets one needs to specify JSP tags in XML format. That was a first for me but there's no problem really. But I am having problems with the parsing of the JSP page however! Let me illustrate this by an example:
In my test.jsp:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<html>
<body>
Test text
</body>
</html>
</jsp:root>
This code works as expected, it produces
<html>
<body>
Test text
</body>
</html>
And that is ALL it produces, nothing else. As I said, as expected. But! If we look at how things are when I add some JSF parsing to the code, a totally different behaviour is shown! I will also add a small piece scriptlet code to show the real problems:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<html>
<body>
<h:outputText value="Test text" />
</body>
</html>
<jsp:scriptlet>
System.out.println("Hello!");
</jsp:scriptlet>
</jsp:root>
This JSP (which has to be called by pointing the browser to /test.faces instead of /test.jsp) should print the standard html-body with the text "Test text" and also print "Hello" to the system console (which it does if you run it without any JSF tags and use the browser with the .jsp ending)
This is the result, note how the jsp:root and jsp:scriplet tags are forwarded to the browser, they haven't been parsed! It feels like the JSP compiler hasn't even had a quick look at this source before sending it to the browser:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<html>
<body><span id="_tagId0">Test text</span>
</body>
</html>
<jsp:scriptlet>
System.out.println("Hello!");
</jsp:scriptlet>
</jsp:root>
This means that I can't use any scriptlets nor other nifty pieces of code in the pages themselves and that is something that I put a lot of value in.. So, I need to understand how JSF and JSP work together, or do they? What am I missing here?
Kind regards,
Marcus Hjortzen (Sweden)
Ok, so now I've found some clues at least... I think the problem relates to Facelets
In my faces-config.xml I have this row specified under the <application> element:
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
This is to enable the facelets in the future, for the time being I'm not using any Facelet code in my test examples. But!
If I remove the row and reload the application I get well formatted output and the System.out.prinltln is executed! (Not forwarded as text to the browser as it did earlier)
If I put the row back in face-config the problem reappear.
So, there's something with the facelets parsing that is causing me problems...
Anyone have any suggestions?
Kind regards,
Marcus
Hi
i have the similar problem.for me i wrote the jsf tags in the <body > tags
but when i view the souce the body tag is empty the jsf code is before the body tag
beloww is my code what shall i need to do that my code should be in <body
><form id="subbody:hi:_id27" name="subbody:hi:_id27" method="post" action="/actsys/mortage.jsf" enctype="application/x-www-form-urlencoded"><table border="0"><tbody><tr><td><span class="text">Applicants should complete this form as "Borrower" or "Co-Borrower", as applicable.Co-Borrower information must aslo be provided(and the appropriate box checked)</span></td></tr>
<tr><td><table border="0"><tbody><tr><td><input type="checkbox" name="subbody:hi:_id27:_id32" value="true" />the income or assest of a person other than the "Borrower"(including the Borrower's spouse) will be used as a basis for loan qualification.</td><td><input type="checkbox" name="subbody:hi:_id27:_id35" value="true" />the income or assests of the Borrowers's spouse will not be used as a basis for loan qualification,but his or her liabilities must be considered because the borrower resides in a community property state,the security property is located in a community property state,or the Borrower is relying on other property located in a community state as a basis for repaymnet of the loan.</td></tr>
</tbody></table></td></tr>
<tr><td><table border="0" cellpadding="1" cellspacing="2"><tbody><tr><td><span class="text">Mortage applied for:</span></td><td><table id="subbody:hi:_id27:MortageApp"><tr><td><label><input type="checkbox" name="subbody:hi:_id27:MortageApp" value="va" onblur="validateCheck(this);" /> VA</label></td><td><label><input type="checkbox" name="subbody:hi:_id27:MortageApp" value="conv" onblur="validateCheck(this);" /> Conventional</label></td><td><label><input type="checkbox" name="subbody:hi:_id27:MortageApp" value="other" onblur="validateCheck(this);" /> Others</label></td><td><label><input type="checkbox" name="subbody:hi:_id27:MortageApp" value="fha" onblur="validateCheck(this);" /> FHA</label></td><td><label><input type="checkbox" name="subbody:hi:_id27:MortageApp" value="usda" onblur="validateCheck(this);" /> USDA/RHS</label></td></tr></table></td><td><span class="text">Agency Case Number:</span></td><td><input id="subbody:hi:_id27:agencycasenumber" name="subbody:hi:_id27:agencycasenumber" type="text" value="" onfocus="validateagency('MortageApp');" onchange="checkNumber(this);" /></td><td><span class="text">Lender Case Number:</span></td><td><input id="subbody:hi:_id27:lendercasenumber" name="subbody:hi:_id27:lendercasenumber" type="text" value="" onchange="checkNumber(this);" /></td></tr>
<tr><td><span class="text">Amount:</span></td><td><input id="subbody:hi:_id27:amount" name="subbody:hi:_id27:amount" type="text" value="" onchange="checkNumber(this);" /></td><td><span class="text">Interest Rate:</span></td><td><input id="subbody:hi:_id27:interestrate" name="subbody:hi:_id27:interestrate" type="text" value="" onchange="checkNumber(this);" /></td><td><span class="text">No. of Months:</span></td><td><input id="subbody:hi:_id27:Noofmonths" name="subbody:hi:_id27:Noofmonths" type="text" value="" onchange="checkNumber(this);" /></td></tr>
<tr><td><span class="text">Authorization Type:</span></td><td><table id="subbody:hi:_id27:Authorization"><tr><td><label><input type="checkbox" name="subbody:hi:_id27:Authorization" value="fr" onblur="validateCheck(this);" /> Fixed Rate</label></td><td><label><input type="checkbox" name="subbody:hi:_id27:Authorization" value="other" onblur="validateCheck(this);" /> Other</label></td><td><label><input type="checkbox" name="subbody:hi:_id27:Authorization" value="gpm" onblur="validateCheck(this);" /> GPM</label></td><td><label><input type="checkbox" name="subbody:hi:_id27:Authorization" value="arm" onblur="validateCheck(this);" /> ARM</label></td></tr></table></td><td></td><td></td><td></td><td></td></tr>
</tbody></table></td></tr>
</tbody></table><input type="hidden" name="subbody:hi:_id27_SUBMIT" value="1" /></form>
<body>
</body>
thnaks in advance
i would be greatful if u can help