I would like to know I would be able to convert the following codes into apex equivalent.

<button type="submit">

I can't use <apex:commandButton>, as it is being rendered as <input> which is a single tag. I need to add an icon into the button that's why I have a <span> inside the button tag as I am using bootstrap.

  • You can use that code directly without modification, you can call an apex:action function on click if you need to do so
    – Eric
    Jul 21 '15 at 19:42

To further illustrate Eric's comment, You would implement his suggestion like so:

Define your button (the button calls the javascript function doSomething) that is defined by the actionFunction:

<button type="submit" onclick="doSomething()">

Define your controller action:

public PageReference doSomething(){
    //do something
    return null;

Define your actionFunction (this calls the controller action):

<apex:actionFunction name="doSomething" action="{!doSomething}"
    rerender="someApexObjectOnThePageEgAPanel" />
  • Thanks for the answer. Just a follow up question, the original element that calls the action is <apex:commandButton action="{!search}">. Should i put the action in the button tag as onclick="{!search}" or onclick="search()"?
    – GibiDroidZ
    Jul 21 '15 at 21:10
  • if your action is "{!search}" then you should have the actionFunction call the "search" method on the controller. Your onclick event calls the NAME of the actionFunction - if you call it "search" then your onclick would be onclick="search()" if you call it "searchAction" then your onclick would be onclick="searchAction()" Jul 21 '15 at 21:21

You can try like

<apex:commandLink action="{!actionMethod}"  styleclass="slds-button slds-modal__close slds-button--icon-inverse">
   <svg class="slds-button__icon slds-button__icon--large" aria-hidden="true">
    <use xlink:href="{!URLFOR($Asset.SLDS, '/assets/icons/utility-sprite/svg/symbols.svg#close')}"></use>

where i'm displaying the close icon and on clicking it I need to call "actionMethod" of controller.

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.