Call apex mathod in VF page

How to call the apex methods in a Visualforce page:

Public class demo
{
Public pageReference show()
{
 return null;  // when we given null it willcome back to the back to the samepage.
  }
}

<apex:commandButton value="click" actiopn="{!show}"
  • when we click on the "click" button it will invoke pagereference show() method.
  • Pagereference is the return type of every method that we have called from Visualforce Page.

Public class Example1
{
      Public string name;
        Public string getName()
          {
              return name;
              }
        Public void setName(string name)
             {
        this.name=name;
                }
Public PageReference show()
     {
        name='this is my name' +name;
              return null;
          }
      }

<apex:page controller="Example1">
<apex:form>
          <apex:outputLabel> enter Name </apex:outputLabel>
           <apex:inputText value="{!name}"/>
           <apex:commandButton value="click" reRender="one" action="{!show}"/>
            <apex:outputLabel id="one">{!name} </apex:outputLabel>
<apex:form>
</apex:page>






No comments:

Post a Comment