Hi Leonardo, 

thanks for your explanations. 
I worried that I have to refactor my c:imports or jsp:includes for JSF. 
Unfortunately there are some more than in my example. :) But I hope that the 
benefit using JSF will 
compensate the effort.

@John: Thanks for you suggestions. We have some more projects running which may 
use another technology.

Regards
Fabian

-----Ursprüngliche Nachricht-----
Von: Leonardo Uribe [mailto:lu4...@gmail.com] 
Gesendet: Mittwoch, 7. September 2011 21:34
An: MyFaces Discussion
Cc: carlso...@llnl.gov
Betreff: Re: Include Form into existing JSP


Hi

You are trying to mix jsp with facelets. Unfortunately that cannot be done, 
because both are different view declaration languages, with its own rules.

The following text on JSF 2.0 spec section 10.1.1 says this:

"... Facelets was the first non-JSP view declaration language designed for 
JavaServer Faces. As such, Facelets was able to provide a simpler and more 
powerful programming model to JSF developers than that provided by JSP, largely 
by leveraging JSF as much as possible without carrying backwards compatibility 
with JSP ..."

In few words, with JSF 2, most of the problems related to JSF 1 + JSP were 
solved.

The preferred way to solve your problem is convert your old jsp pages into 
.xhtml pages that can be loaded by facelets engine. The idea is just replace 
all your c:import or jsp:directive.include into facelets ui:include. Note it is 
also possible to have facelets and jsp pages on the same app, but you can't mix 
them on the same view. Other option is just create a duplicate of those jsp 
pages for facelets and later use them on your new views.

@John: it could be good to know if your reasons to object JSF. In my 
understanding JSF 2 solved many of the problems, and it have some very useful 
features. Maybe if some idea is enough useful, myfaces community can push to 
include it on next JSF 2.2 spec. Suggestions, critics and tomatoes are most 
welcome ;-). That's how innovation works, right?

regards,

Leonardo Uribe

2011/9/7 Carlson, John W. <carlso...@llnl.gov>:
> Get a grip.  JSF sucks.  Try Struts.  If you get an answer, let me 
> know.
>
> John
>
> -----Original Message-----
> From: Hagen, Fabian [mailto:fabian.ha...@talanx.com]
> Sent: Wednesday, September 07, 2011 5:56 AM
> To: users@myfaces.apache.org
> Subject: Include Form into existing JSP
>
> Hello,
>
> I have a litte problem and cannot believe that this problem is not 
> solved yet. I tried to find a solution via google but without success.
>
> For some of our new websites we want to use JSF 2.0 as our main 
> web-framework but most of our sites are standard JSP files which 
> include some other files for navigation etc.
>
> Here is a small snippet:
>
> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page";
> xmlns="http://www.w3.org/1999/xhtml";
>        xmlns:c="http://java.sun.com/jsp/jstl/core";
>        xmlns:xs="http://www.w3.org/2001/XMLSchema";
>        version="2.0">
>
>        <jsp:directive.include 
> file="/components/includes/header_core.jsp" /><!-- all the html-head 
> information -->
>        <body>
>                <jsp:directive.include 
> file="/components/includes/mainNav.jsp"/>
>              <jsp:directive.include 
> file="/components/includes/subNav.jsp"/>
>                 <div id="content">
>                        <c:import url="/forms/easyForm.jsp"/> <!-- 
> includes some simple html form fields -->
>                </div>
>        </body>
> </jsp:root>
>
> Our main purpose is to use the JSF 2.0 for our webforms, so I try like 
> something like this: <body>
>                <jsp:directive.include
> file="/components/includes/mainNav.jsp"/>
>              <jsp:directive.include
> file="/components/includes/subNav.jsp"/>
>                 <div id="content">
>                        <c:import url="/forms/jsfForm.xhtml"/> <!--
> includes some jsf form fields -->
>                </div>
> </body>
>
> Here is the form:
> <html xmlns="http://www.w3.org/1999/xhtml";
>        xmlns:h="http://java.sun.com/jsf/html";
>        xmlns:f="http://java.sun.com/jsf/core";
>        xmlns:c="http://java.sun.com/jsp/jstl/core";
>        xmlns:ui="http://java.sun.com/jsf/facelets";>
> <body>
>        <f:view>
>                <p>Bitte geben Sie die Daten ein:</p>
>                <h:messages showDetail="true" showSummary="false" />
>                <h:form id="eingabe">
>                        <h:panelGrid id="columns" columns="2">
>                                <h:outputLabel value="Vorname" 
> for="vorname" />
>                                <h:inputText id="vorname" 
> value="#{customer.vorname}" />
>                                <h:outputLabel value="Nachname" 
> for="name" />
>                                <h:inputText id="name" 
> value="#{customer.name}" required="true" />
>                                <h:outputLabel value="Use Credit Card:" 
> for="useCreditCard" />
>                                <h:selectBooleanCheckbox 
> id="useCreditCard"      value="#{customer.useCreditCard}"
>
> valueChangeListener="#{customer.useCreditCardChanged}"
>                                        immediate="true" 
> onclick="this.form.submit()" />
>                                <h:outputLabel value="Credit Card 
> Type:" for="ccType" rendered="#{customer.useCreditCard}" />
>                                <h:inputText 
> rendered="#{customer.useCreditCard}" id="ccType" 
> value="#{customer.creditCardType}"
>
> required="#{customer.useCreditCard}" />
>                                <h:outputLabel 
> rendered="#{customer.useCreditCard}"    value="Credit Card Number:" 
> for="ccNumber" />
>                                <h:inputText id="ccNumber" 
> value="#{customer.creditCardNumber}"
> rendered="#{customer.useCreditCard}"
>
> required="#{customer.useCreditCard}" />
>                        </h:panelGrid>
>                        <h:commandButton action="#{customer.save}" 
> value="Speichern"
>                                id="btn_Speichern" />
>                        <h:commandButton id="cancel" value="Cancel" 
> immediate="true"
>                                action="/de/forms/cancelled.xhtml" />
>                </h:form>
>        </f:view>
> </body>
> </html>
>
> and the web.xml:
> <!-- context Params -->
>        <context-param>
>                <param-name>javax.faces.PROJECT_STAGE</param-name>
>                <param-value>Development</param-value>
>        </context-param>
>
>        <context-param>
>        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
>        <param-value>.jsp</param-value>
>    </context-param>
>
>    <context-param>
>        <param-name>javax.faces.FACELETS_SUFFIX</param-name>
>        <param-value>.xhtml</param-value>
>    </context-param>
>
>        <!-- Facelets pages will use the .xhtml extension -->
>    <context-param>
>        <param-name>facelets.VIEW_MAPPINGS</param-name>
>        <param-value>/de/forms/*</param-value>
>    </context-param>
>
>        <!-- filter -->
>
>        <!-- Servlet -->
>        <servlet>
>                <servlet-name>Faces Servlet</servlet-name>
>
> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
>                <load-on-startup>1</load-on-startup>
>        </servlet>
>
>        <!-- ServletMapping -->
>        <servlet-mapping>
>                <servlet-name>Faces Servlet</servlet-name>
>                <url-pattern>*.xhtml</url-pattern>
>        </servlet-mapping>
>
> If I call the main-page I see the form, so far so good.
> But if the first action is fired, for example the checkbox or the 
> submit button or cancel-button, I get the following error:
>
> HTTP: 404
> /<%context%>/forms/jsfForm.jsp not found
>
> Here my question:
> Is it possible to use the JSF Forms with all the redirects and 
> forwards in a JSP environment? I cannot get the form running. Do I 
> have to implement the included jsp - files with JSF again? What would 
> be the best way to build a surrounding file where I can change the 
> c:import - part with different forms?
>
> Regards
> Fabian
>
>

Reply via email to