dip
dip

Reputation: 1261

<apex:commandbutton> not working

I am working on button.

My component code is as follows.

<apex:commandButton action="{!sendAction}" 
value="SEND" styleClass="Button" rerender="messageId" immediate="true"/>

<apex:outputpanel rendered="{!showmsg}" id="messageId">
            <apex:outputtext value="{!outputMessage}" style="color:red;font-size:13px;font-weight:bold;"/>
            <br />    
        </apex:outputpanel> 

My controller code is as follows.

public PageReference sendAction()
{ 
    showmsg=true;                     
    outputMessage='working';             
     return null;                        
 }

But my action method sendAction is not getting called. When I open my page containing in new window , function is getting called. But in same window it is not getting called.

Any help is really appreciate.

Upvotes: 2

Views: 4432

Answers (2)

Mohit Arora
Mohit Arora

Reputation: 121

You can try the following approaches in the case when your<apex:commandButton> or <apex:commandLink> doesn't seem to call the apex controller method.

  1. Try setting the attribute immediate = true for these two. That works in some cases.

  2. Try calling the apex controller method using the <apex:actionFunction>.

  3. If somehow you're still unable to call the apex controller method using the <apex:actionFunction>, refer to this link.

Upvotes: 0

Samuel DR
Samuel DR

Reputation: 1231

If, as Matthew already hinted your controller is refered by your page or component I believe it may be caused by the showmsg variable.

If the messageId outputpanel is not renderd because showMsg is initially false, it will also not rerender, and thereby not display your message. If i'm right, the following would make more sense, and fix your problem.

<apex:outputpanel  id="messageId">
        <apex:outputtext rendered="{!showmsg}" value="{!outputMessage}" style="color:red;font-size:13px;font-weight:bold;"/>
        <br />    
    </apex:outputpanel> 

Upvotes: 2

Related Questions