P
P
parkito2016-10-07 00:06:14
Java
parkito, 2016-10-07 00:06:14

How to make jsp and jsf friends?

Hello. Help, please, to solve a problem.

Wrote an application on EJB. I displayed variables on the page using jsf
index.xhtml :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <title>JSF 2.0</title>
</h:head>
<h:body>
    <h3>Enter tariff title</h3>
    <h:form>
        <h:inputText value="#{beanController.tariff}"></h:inputText>
        <br/>
        <br/>
        <h:commandButton value="Get report" action="#{beanController.getInfo}"></h:commandButton>
    </h:form>
</h:body>
</html>


However, I need to re-render this page. An example of design is in jsp. And this is where the problems begin. If you rename xhtml to jsp , jsf stops working, if vice versa, then jsp.
What is the correct way to make jsf tags work in jsp files?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2016-10-07
@zolt85

In my opinion JSP and JSF are 2 different versions of the same thing. Those. You need to use one. If we take JSP, then we need to use JSTL . We change the sign '#' to '$' and live happily ever after.

S
sirs, 2016-10-07
@sirs

It can be done, but as Eugene noted above, it does not make practical sense. The only case I can think of is the gradual migration of a project from jsp to jsf or vice versa.
Try configuring DEFAULT_SUFFIX and FACELETS_VIEW_MAPPINGS by adding to web.xml

<web-app>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.jsp</param-value>
    </context-param>

    <!-- Facelets pages will use the .xhtml extension -->
    <context-param>
        <param-name>facelets.VIEW_MAPPINGS</param-name>
        <param-value>*.xhtml</param-value>
    </context-param>     

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>

    <!-- Use prefix mapping for Facelets pages, e.g. http://localhost:8080/webapp/faces/mypage.xhtml -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
</web-app>

Although I can't say how much this will help without seeing the code in the controllers. Still, these are different ways of building applications.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question