3

I would like to create a VF page and call a custom component inside it.

<apex:page controller="MyController">
<apex:form>
<c:mycomponent id="myId" attributeName="{attributevalue}"/>
</apexform>
<apex:page>

But this returns me: 'c:mycomponent' component cannot be nested within form tags'

I have tried to without the and call this page from another one using the tag, but it doesn't work either.

I read somewhere that is not possible to do what I need, but in the past I was allowed because I have some examples in my old code.

Is there a workaround now?

Thanks in advance

  • What API version is your page? – bigassforce May 17 '13 at 11:10
5

I think you need to check if c:mycomponent contains an apex:form tag and remove it.

Forms cannot be nested, and you can't cheat by wrapping it in a component ;-)

  • Possible workaround 1: mock out the apex:form with a plain vanilla form tag

  • Possible workaround 2: put component on a page in an apex:iframe to get the visual equivalent

| improve this answer | |
  • Yes, I have inside a form. I have added the code. And you are right, now it's not able to do it. But I have some old code with API 20.0 that allowed to me to do it. I was wondering if there was a workaround. – Agustina García May 17 '13 at 11:16
  • @AgustinaGarcía Can you replace the apex:form with just form? How about using an apex:iframe to give you the cosmetic equivalent without the nesting? – bigassforce May 17 '13 at 11:26
  • Thanks a lot, your answer helped me to solve some of my issues. But actually my error was that my component had a <apex:form> inside so, I was not able to call it from another <apex:form>. – Agustina García Jun 3 '13 at 7:16
  • N.B. while swapping the <apex:form> with <form> gets around the compile time error, you'll get a run time error such as Content cannot be displayed: <apex:selectList> (under <c:myComponent>) must occur between <apex:form></apex:form> tags. – cropredy Aug 12 '19 at 19:01
  • N.B. 2 - wrapping the custom component (if it has an apex:form therein) within an apex:iframe will not eliminate the compile time error in the OP – cropredy Aug 12 '19 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.