+ Start a Discussion
Kevin Jackson 11Kevin Jackson 11 

Why are my variables not being called

I cannot figure out what I am doing wrong here.  This was working before.  

MY VF Page
<apex:page Controller="TestP" showHeader="false">

<apex:pageBlock><apex:pageBlockSection>
    <apex:form>
   Email given: {!cemail} 
   Email Returned: {!IdentifyUser.email} 
   Name: {!IdentifyUser.name}
    </apex:form>
    </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>

My Controller
 
public class TestP {
    Public string cemail {get;set;} 
    Public Contact IdentifyUser {get;set;}
    Public Contact x {get;set;}
    
    // IDENTIFY USER BASED ON EMAIL ADDRESS
    Public Contact getIdentifyUser(){       
     cemail='kevin@caberu.be';   
       Contact x = [SELECT Id, firstname, email, name             
              FROM Contact 
              WHERE email = :cemail 
                              LIMIT 1]; 
        Return x;

    }
}

The VF page does not show any of the variables.

Any help is appreciated.  Where is the bug?
Best Answer chosen by Kevin Jackson 11
LBKLBK
If you have the variable (a property in apex) assigned to the inputText, you can capture the changes in value in APEX.

However, for the changes in SObject values to be retained, you need to save the values before rerendering (and call it using a command button or some other means). Your code will look like this
<apex:page Controller="TestP" showHeader="false">
<apex:pageBlock>
<apex:pageBlockButtons>
	<apex:commandButton value="Save" action="{!save}" rerender="myPageBlockSection"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="myPageBlockSection">
    <apex:form>
	   Email given: <apex:inputText value="{!cemail}" id="txtEmail"/>
	   Email Returned: <apex:inputField value="{!x.email}" /> 
	   Name: <apex:inputField value="{!x.name}" />
    </apex:form>
    </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>


public class TestP {
    Public string cemail {get;set;} 
    Public Contact x {get;set;}
    
    // IDENTIFY USER BASED ON EMAIL ADDRESS
    public TestP(){       
     cemail='kevin@caberu.be';   
       x = [SELECT Id, firstname, email, name             
              FROM Contact 
              WHERE email = :cemail 
                              LIMIT 1]; 
    }
	public PageReference save(){ 
		update x; 
		return null; 
	}
}

All Answers

LBKLBK
Where are you calling your getIdentifyUser method?

Try the following code.
VF Page
<apex:page Controller="TestP" showHeader="false">

<apex:pageBlock><apex:pageBlockSection>
    <apex:form>
   Email given: {!cemail} 
   Email Returned: {!x.email} 
   Name: {!x.name}
    </apex:form>
    </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>
APEX Code
public class TestP {
    Public string cemail {get;set;} 
    Public Contact x {get;set;}
    
    // IDENTIFY USER BASED ON EMAIL ADDRESS
    public TestP(){       
     cemail='kevin@caberu.be';   
       x = [SELECT Id, firstname, email, name             
              FROM Contact 
              WHERE email = :cemail 
                              LIMIT 1]; 
    }
}
Let me know if this helps.
 
Kevin Jackson 11Kevin Jackson 11
LBK,  This works.  Just one follow up question.  If I want to have an inputtext {!cemail} or inputfield {!x.email} for the lookup in the VFP how do I get it to rerender properly when I change the value?

Thanks.
LBKLBK
If you have the variable (a property in apex) assigned to the inputText, you can capture the changes in value in APEX.

However, for the changes in SObject values to be retained, you need to save the values before rerendering (and call it using a command button or some other means). Your code will look like this
<apex:page Controller="TestP" showHeader="false">
<apex:pageBlock>
<apex:pageBlockButtons>
	<apex:commandButton value="Save" action="{!save}" rerender="myPageBlockSection"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="myPageBlockSection">
    <apex:form>
	   Email given: <apex:inputText value="{!cemail}" id="txtEmail"/>
	   Email Returned: <apex:inputField value="{!x.email}" /> 
	   Name: <apex:inputField value="{!x.name}" />
    </apex:form>
    </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>


public class TestP {
    Public string cemail {get;set;} 
    Public Contact x {get;set;}
    
    // IDENTIFY USER BASED ON EMAIL ADDRESS
    public TestP(){       
     cemail='kevin@caberu.be';   
       x = [SELECT Id, firstname, email, name             
              FROM Contact 
              WHERE email = :cemail 
                              LIMIT 1]; 
    }
	public PageReference save(){ 
		update x; 
		return null; 
	}
}
This was selected as the best answer
Kevin Jackson 11Kevin Jackson 11
Thanks VERY MUCH!