function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shivshiv 

the commandButton tag is not calling the my Apex function : : any help plz..

Hello can anybody find the error behind my code for why the commandButton's action attribute is not calling the Apex function??
 
I am actually trying to get a valid Account ID from user(in the first outputPanel). If its a valid one, it should display the corresponding Account's details in the same(second outputPanel) page (with just few properties). And if it is an invalid one, it has to show the error Text.
 
VF code:
 
<apex:page controller="ApexPopups" tabStyle="Account">
    <apex:sectionHeader title="Accounts" subtitle="Home"/>
    <apex:outputPanel id="out1">
        <apex:form id="form1">
            <apex:pageBlock title="Get Account Details">
               
                <apex:outputText>Enter the Account Id</apex:outputText>                                &nbsp;&nbsp;&nbsp;&nbsp;
               
                <apex:inputText id="accid" value="{!id1}" style="width:130px;font-size:12px;"/>                                            &nbsp;&nbsp;&nbsp;&nbsp;
                <apex:outputText value="{!dispText}" style="font-color:red;font-weight:bold;"/>        <br/><br/>
               
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
               
                <apex:commandButton action="{!checkId}" value="Fetch Account Details" rerender="out1,out2"/><br/>
               
            </apex:pageBlock>
        </apex:form>
    </apex:outputPanel>
    <apex:outputPanel id="out2" rendered="{!isrendered}">
        <apex:form id="form2">
            <apex:pageBlock title="Account Details">
                <apex:pageBlockTable value="{!acc}" var="ac">
                    <apex:outputLabel value="{!ac.name}"/>
                    <apex:outputField value="{!ac.phone}"/>
                    <apex:outputField value="{!ac.billingCity}"/>
                </apex:pageBlockTable>
            </apex:pageBlock>
        </apex:form>
    </apex:outputPanel>
</apex:page>
 
 
 
Apex code:
 
public class ApexPopups {
   
    Boolean isrendered=false;
    Account acc;
    Id id1;
    String dispText='';
   
    public String getDispText() {
        return dispText;
    }
    public void setDispText(String ab){
        dispText=ab;
    }
   
    public boolean getIsrendered() {
        return isrendered;
    }
    public void setIsrendered(Boolean ab){
        isrendered=ab;
    }
   
    public void checkId(){
        acc=[select id,name,phone,billingCity from Account where id =: id1];
        if(acc!=null){
            isrendered=true;
            dispText='';
        }
        else{
            dispText='Invalid Id. Please Enter a Valid Id';
            isrendered=false;
        }
    }
   
    public Account getAcc() {       
        return acc;
    }
    public void setAcc(Account a){
        acc=a;
    }
    public Id getId1(){
        return Id1;
    }
   
    public void setId1(Id a){
        id1=a;
    }
}
Ron HessRon Hess
this method

public void checkId(){


should be

public PageReference checkId(){



and return a page reference or null


Check out the docs on action methods and navigation.
dchasmandchasman
Not true - it is perfectly acceptable for an action method to have a void return type - it is actually preferable and much better stylistically if the action is always going to return null.
Ron HessRon Hess
Got it, well there must be some other issue, the code looks simple enough.

Suggest that you put a system.debug() message into your action method to verify that it is being called.




Message Edited by Ron Hess on 12-16-2008 07:05 AM