function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
pcalpcal 

Best practices for handling nested forms?

Hi all.  I'm looking for general guidance on the best way to handle the following situation:  I have a high level structure like this:

Code:
<apex:page>
  <apex:form>
    <c:myComponent />
  <apex:form>
</apex:page>

where 'myComponent' is a component that ends up outputting another apex:form tag.

I gather that VF does not like the nested forms - it complains with something like

'c:myComponent' component cannot be nested within form tags

I believe this kind of thing is pretty unavoidable in our design - typically those components are outputting a commandLink or some other thing that requires an enclosing form.

We've considered a couple of alternatives for structuring our pages to avoid this.  The current frontrunner is to do the following:

- Declare a single apex:form at the page level
- Cordon off the various areas of responsibility using actionRegions instead of form tags

Does that seem like a reasonable solution, or should we consider another approach?

Thanks very much in advance.


Message Edited by pcal on 08-13-2008 06:18 PM
jwetzlerjwetzler
You're correct that VF does not like nested forms, because it is not valid HTML to have nested form tags.

In general you should strive to only use one form on your page -- it's rarely necessary to have more than that (and actionRegion, as you mentioned, makes it even more unnecessary).  I think your suggestion is not really a "workaround" (since this is not even valid in HTML) but rather it's the right thing to do.
pcalpcal


jwetzler wrote:
In general you should strive to only use one form on your page -- it's rarely necessary to have more than that (and actionRegion, as you mentioned, makes it even more unnecessary).



Ok, great, thanks.


  I think your suggestion is not really a "workaround" (since this is not even valid in HTML) but rather it's the right thing to do.


Fair enough - I altered my phrasing a bit. :smileywink:   Apologies, I'm a relative VF newbie and it just wasn't 100% clear what the right thing to do was.

Thanks for your help and very fast response.

-p


NickforceNickforce

What would be the best practice solution for when my markup's basic structure looks like the following:

 

<apex:page>
  <apex:form>
    <apex:tabpanel>
      <apex:tab>
        <apex:include pageName="page1" />
      </apex:tab>
      <apex:tab>
        <apex:include pageName="page2" />
      </apex:tab>
    </apex:tabpanel>
  </apex:form>
</apex:page>

 With this structure, if I put a form tag in either 'page1' or 'page2' then I will receive the nested form error message. Tell me if my use case for the includes component is the issue here, we are using the include though to serperate and organize very large pages to allow for easier management.

Rk094Rk094

Hello,

I have to include two pages into a Outer page.

Each inner page contains a inputText under form section.

 

Each Inner page:

 

<apex:page controller="TestClass">

<apex:form >

<apex:inputText value="{!pageOne}"/>

 </apex:form>

 </apex:page>

 

Outer Page:

 

<apex:page controller="TestClass">

<apex:form >

<apex:commandButton value="save" onclick="{!save}"/>

<apex:include pageName="page1"/>

<apex:include pageName="page2"/>

</apex:form>

</apex:page>

 

If i am including pages like this iam getting an error saying "Error: 'apex:form' component cannot be nested within form tags"

 

Post ur comments...