0

As per HTML standard nested form not allowed and JSF follow same thing but if we have design like below

MainPage.xhtml

 <ui:composition template="../templates/home.xhtml">
        <ui:define name="content">
            <h:form>
                <rich:panel>
..........................................
..........................................
                </rich:panel>
  <rich:panel>
    <ui:insert name="createLinkTemplate">
     <ui:include src="../pages/page.xhtml" />
    </ui:insert>
  </rich:panel>
<h:form>
</ui:define>
</ui:composition>

Content inside page.xhtml

<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:ui="http://java.sun.com/jsf/facelets"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:head>
</h:head>
<h:body>
    <h:form id="formID">

        <rich:panel>
..........................
............................
............................
        </rich:panel>
</h:form>
</h:body>
</html>

is this come under the nested case ?

home-template.xhtml content

<?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"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
...................................................
...................................................
...................................................
<rich:panel styleClass="tabs-main" id="tabsMain">
       <h:form id="contentform">
          <ui:insert name="content"/>
        </h:form>
 </rich:panel>
</h:body>
</html>

Along with that one more question First i am alnding to Main.xhtml page from here i am going to page.xhtml and when from there i am coming back all the value which i write in textbox or select from drop down gone and i got a empty form .

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
  • Does it give any errors? – Nurjan Oct 13 '16 at 09:09
  • 1
    Just don't use `` in the master template. Instead use it in template clients whenever needed. Multiple parallel forms are perfectly fine (the term "nested forms" is something completely different). – Tiny Oct 13 '16 at 09:20
  • @Tiny do you mean one `h:fom` outside `ui:include` or `ui:insert` and one inside `h:form` is not a nested form ? – Subodh Joshi Oct 13 '16 at 09:26
  • @Nurzhan I am not getting any error. But one issue which i updated in question – Subodh Joshi Oct 13 '16 at 09:27
  • @BalusC Any hint why all form value empty when coming back from another page. – Subodh Joshi Oct 13 '16 at 09:59
  • 2
    Because nested forms are not allowed *in HTML.* JSF has nothing to do with it. – user207421 Oct 13 '16 at 10:00
  • The duplicate clearly tells that JSF is just a HTML code generator. Have you ever done rightclick, *View Source* in webbrowser? If JSF has done its job right, you should not see any JSF tag in there. – BalusC Oct 13 '16 at 10:11
  • @BalusC If i am using `binding` attribute then going other page coming back persist the data in components but if i am not using that all field rendered empty when coming back . – Subodh Joshi Oct 13 '16 at 12:00
  • Apparently you're storing components in session. http://stackoverflow.com/q/14911158 – BalusC Oct 13 '16 at 12:06
  • @BalusC My Managed Bean is session scoped so without binding also value should be persist but in my case only value persist when binding is their in component if not all value added in corresponding component going null – Subodh Joshi Oct 13 '16 at 12:09

1 Answers1

1

Forms are nested when they are nested in the resulting page - the shape of templates and includes has nothing to do with this.

Browser has no way of knowing where <form> tags come from. All it sees is that there are two form tags, one placed in the other.

fdreger
  • 12,264
  • 1
  • 36
  • 42
  • Please have a look here http://stackoverflow.com/questions/379610/can-you-nest-html-forms – Subodh Joshi Oct 13 '16 at 09:34
  • 3
    @SubodhJoshi: what does that change? Nesting forms is forbidden and it has nothing to do with how facelet templates are arranged. – fdreger Oct 13 '16 at 09:51