+ Start a Discussion
Numaan A.MNumaan A.M 

HTML tags or Apex tags

Hello All,

I want to know what is the difference between using html tags and apex tags. I am good at html tags so if i use it is there would be any problem. Thanks.
Best Answer chosen by Numaan A.M
Grazitti TeamGrazitti Team
Hi Numaan,

You can use both apex/vf tags and HTML tags. It depends on the scenarios. I have written one small example to explain both scenarios.

If you use the HTML tags then you have to write Javascript functions to call apex methods like in below example ( Scenario 1 ).

Scenario 1. Using HTML tags:

1. HTML

<script type="text/javascript">
      jQuery(document).ready(function(){
            jQuery('.btn').click(function(){
                         callTestMethod();
            });
     });
</script>

<apex:page>
    <apex:actionfunction name="callTestMethod" action="{!testMethod}" />
    <input type="button" value="Test"  Class="btn"/>
</apex:page>

If you use VF tags then you can directly call apex methods through action attribute ( scenario 2 ).

Scenario 2: Using Apex/VF tags:

<apex:page controller="testClass">
     <apex:form>
           <apex:commandButton styleClass="btn " value="test" action="{!testMethod}"/>
    </apex:form>
</apex:page>

Apex Class:

Public class testClass{
    
      public PageReference testMethod(){
            PageReference retVal = page.TestPage;
            retVal.setRedirect(true);
            return retVal;
     
      }

}



 For the VF performance and best practices please refer to the following links:

http://www.salesforce.com/docs/en/cce/salesforce_visualforce_best_practices/salesforce_visualforce_best_practices.pdf  (http://www.salesforce.com/docs/en/cce/salesforce_visualforce_best_practices/salesforce_visualforce_best_practices.pdf)
http://www.salesforce.com/us/developer/docs/pages/Content/pages_best_practices_performance.htm



Please mark as best answer if it solves your problem.

Regards,
Grazitti Team
www.grazitti.com

All Answers

Ankit AroraAnkit Arora
Not a problem, when you use native tags (apex/visualforce) on visualforce page, it becomes easy as no need of styling etc.. also less issues with rendering. Also if you use apex/visualforce tags on VFP then at backend they compile in HTML, but it's always recommended to use native tags.
Grazitti TeamGrazitti Team
Hi Numaan,

You can use both apex/vf tags and HTML tags. It depends on the scenarios. I have written one small example to explain both scenarios.

If you use the HTML tags then you have to write Javascript functions to call apex methods like in below example ( Scenario 1 ).

Scenario 1. Using HTML tags:

1. HTML

<script type="text/javascript">
      jQuery(document).ready(function(){
            jQuery('.btn').click(function(){
                         callTestMethod();
            });
     });
</script>

<apex:page>
    <apex:actionfunction name="callTestMethod" action="{!testMethod}" />
    <input type="button" value="Test"  Class="btn"/>
</apex:page>

If you use VF tags then you can directly call apex methods through action attribute ( scenario 2 ).

Scenario 2: Using Apex/VF tags:

<apex:page controller="testClass">
     <apex:form>
           <apex:commandButton styleClass="btn " value="test" action="{!testMethod}"/>
    </apex:form>
</apex:page>

Apex Class:

Public class testClass{
    
      public PageReference testMethod(){
            PageReference retVal = page.TestPage;
            retVal.setRedirect(true);
            return retVal;
     
      }

}



 For the VF performance and best practices please refer to the following links:

http://www.salesforce.com/docs/en/cce/salesforce_visualforce_best_practices/salesforce_visualforce_best_practices.pdf  (http://www.salesforce.com/docs/en/cce/salesforce_visualforce_best_practices/salesforce_visualforce_best_practices.pdf)
http://www.salesforce.com/us/developer/docs/pages/Content/pages_best_practices_performance.htm



Please mark as best answer if it solves your problem.

Regards,
Grazitti Team
www.grazitti.com
This was selected as the best answer
Numaan A.MNumaan A.M
Thank you Ankit Arora and Grazitti Team