0

We are trying to run Bootsfaces on Jsf2.1/Jsp 1.3. We are working on migrating a legacy jsp application which has more than 1500 Jsp files(JSF1.2) to JSF2.1, migrating to Facelets will be lot of effort as we have to convert each .jsp file to .xhtml .

So , I have started with a demo web application as you suggested and created a facelets login page which uses bootsfaces. It works fine and I am able to see bootsfaces content rendering. Now as I want to use bootsfaces with Jsp servlets , I create a new Jsp page

when I try to add bootsfaces tag lib

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://bootsfaces.net/ui" prefix="b" %>

I get an exception at line number 3 :

the absolute uri "http://bootsfaces.net/ui” cannot be resolved in either web.xml or jar files loaded with application

I look into bootsfaces-b.taglib.xml file in bootsfaces jar file , I see

<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<namespace>http://bootsfaces.net/ui</namespace>
<tag>
<tag-name>accordion</tag-name>
....

So I figured out the problem might be because bootsfaces jar is using faceless tag library and I am trying to use servlet tag library to use it and its not able to find it. So I wanted to experiment on this and manually created a tld file which has servlet tag

<?xml version="1.0" encoding="ISO-8859-1"?>

<taglib xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
   xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1">

I tested by adding one tag (inputText) description in .tld file , the format I changed to match the servlet tag lib format,

<!--made changes like  replaced<tag-name> with <name>-->    
<tag>
<name>inputText</name>
<tag-class>net.bootsfaces.component.inputText.InputText</tag-class>
<attribute>
 <description><![CDATA[Access key to transfer focus to the input element.]]></description>
 <name>accesskey</name>
 <required>false</required>
 <type>java.lang.String</type>
</attribute>
<attribute>
 <description><![CDATA[Activates AJAX. The default value is false (no AJAX).]]></description>
 <name>ajax</name>
 <required>false</required>
 <type>java.lang.Boolean</type>
</attribute> 

There is no compile time exception shown on login.jp page, but when I try to run the project I get this exception

PWC6197: An error occurred at line: 28 in the jsp file: /jsp/login/login2.jsp PWC6199: Generated servlet error: method get in class org.apache.jasper.runtime.TagHandlerPool cannot be applied to given types;

We get this error when trying to run this application

required: java.lang.Class found: java.lang.Class
reason: inferred type does not conform to upper bound(s) inferred: net.bootsfaces.component.inputText.InputText upper bound(s): javax.servlet.jsp.tagext.JspTag PWC6197: An error occurred at line: 28 in the jsp file: /jsp/login/login2.jsp

PWC6199: Generated servlet error: We get this error when trying to run this application cannot find symbol symbol: method setPageContext(javax.servlet.jsp.PageContext) location: variable _jspx_th_b_inputText_0 of type net.bootsfaces.component.inputText.InputText

Could you please suggest any alternate way of getting bootsfaces working on jsp

jklee
  • 2,198
  • 2
  • 15
  • 25

1 Answers1

0

Traditionally everybody says that it's not possible to mix JSP and JSF code. But I understand why you want to do this, and I think it's an interesting question to explore. So let me try to give you some hints - even if that's a slightly disappointing way of answering.

  • The bad news is that JSF 2 isn't meant to be mixed with JSP. The creators of the framework wanted to get rid of the countless pain-points caused by mixing Facelets, HTML and Java code. So I'm pretty sure it's not possible to mix JSF 2.x code with JSP code within the same file.

  • What does work is to define parts of the page as *.xhtml file and to include it using the URL. This comes in handy if you want to use the router of AngularJS. Unfortunately, that's not your use case, and the only way I know how to achieve that is using iframes. Maybe that works, but it's clumsy and awkward.

  • The *.xhtml files are parsed by a servlet (javax.faces.webapp.FacesServlet). That's why you can't simply add a namespace in the JSP way. JSF simply hasn't been designed that way. But servlets and JSP pages are closely related technologies, so maybe you can find a way to integrate both technologies. For instance, you could write a JSP tag using the FacesServlet to read and parse an *.xhtml file.

  • Maybe you can also start with a JSF file, using it as a template, and embed the JSP page into it.

  • Update Mar 18, 2017: A more flexible way to include servlets and JSF fragments is offered by AngularFaces. The idea is to write a tiny AngularJS controller defining the navigation routes. These fragments can be generated by an arbitrary technology - JSF, JSP, PHP, whatever. So you can mix your old JSP code with new JSF 2.x code on the same page. If done this in an presentation some time ago (template JSF page, AngularJS router, example JSF fragment).

Stephan Rauh
  • 3,069
  • 2
  • 18
  • 37
  • Thank you for detailed explanation and for providing me alternatives to achieve our mission, I will be tempted to try the last two hints. – Santosh San Mar 17 '17 at 09:17
  • I've added another option. AngularFaces might help you, too. It's a bit ugly to add an entire new technology stack, but then, trying to manipulate the JSF engine is even more complicated and probably even dangerous. – Stephan Rauh Mar 18 '17 at 09:07
  • AngularFaces would be different stack for us than what we were planning for, if everything else becomes complicated , we will try AngularFaces.Thank you – Santosh San Apr 04 '17 at 08:56