You need to sign in to do that
Don't have an account?
Gaurav Sinha 15
Wiered Behaviour for a custom Object
Hi All,
I have created a custom object Student__c. Now the problem i am having is object of Student__c is not getting called in the vf page. I am not able to understadn the reason. if i create a variable and call that it's working.
Below is my apex code.
public class DemoClass {
String countries = '';
public List<Student__c> stu {get;set;}
public String fname{get;set;}
public Student__c student = new Student__c(First_name__c = '2212121212121');
public DemoClass(){
stu = [select name,First_name__c, Last_Name__c,Age__c,Sex__c from Student__c limit 10];
//student = new Student__c();
}
public PageReference test() {
return null;
}
public Student__c getstudent(){
return student;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
/* options.add(new SelectOption('US','USA'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
*/
for(Student__c temp:stu){
options.add(new SelectOption(String.valueOf(temp.ID),temp.name));
}
return options;
}
public String getCountries() {
student = getS();fname=student.First_name__c;
student.First_name__c = '222222';
return countries;
}
public void setCountries(String countries) {
setS((ID)countries);
this.countries = countries;
}
public Student__c getS() {
// countries = 'asdasda';
System.debug('x154865 the loop'+student);
return student;
}
public void setS(ID rec) {
// countries = '11111';
Student__c temp1 = null;
System.debug('before the loop '+ rec);
for(Student__c temp:stu){
if(rec==temp.id){
System.debug('inside the loop '+ rec);
temp1=temp;
}
}
this.student = temp1;
System.debug('X154865'+temp1+' - '+this.student);
}
}
VF page
<apex:page controller="DemoClass" >
<apex:form>
<apex:selectList value="{!countries}" multiselect="false" onchange="func();">
<apex:selectOptions value="{!items}"/>
</apex:selectList><p/>
<apex:actionFunction name="func" action="{!test}" rerender="out" status="status"/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
<apex:outputPanel id="out">
<apex:inputText value="{!student.First_Name__c}"/>
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel>
<p>You have selected:</p>
<apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
{!student.Name}
hi hi hi {!student.ID} {!student.First_name__c}
<h1>
name is {!fname}
</h1>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:form>
</apex:page>
Please help me thorugh. Let me know if any further details are required from my end
I have created a custom object Student__c. Now the problem i am having is object of Student__c is not getting called in the vf page. I am not able to understadn the reason. if i create a variable and call that it's working.
Below is my apex code.
public class DemoClass {
String countries = '';
public List<Student__c> stu {get;set;}
public String fname{get;set;}
public Student__c student = new Student__c(First_name__c = '2212121212121');
public DemoClass(){
stu = [select name,First_name__c, Last_Name__c,Age__c,Sex__c from Student__c limit 10];
//student = new Student__c();
}
public PageReference test() {
return null;
}
public Student__c getstudent(){
return student;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
/* options.add(new SelectOption('US','USA'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
*/
for(Student__c temp:stu){
options.add(new SelectOption(String.valueOf(temp.ID),temp.name));
}
return options;
}
public String getCountries() {
student = getS();fname=student.First_name__c;
student.First_name__c = '222222';
return countries;
}
public void setCountries(String countries) {
setS((ID)countries);
this.countries = countries;
}
public Student__c getS() {
// countries = 'asdasda';
System.debug('x154865 the loop'+student);
return student;
}
public void setS(ID rec) {
// countries = '11111';
Student__c temp1 = null;
System.debug('before the loop '+ rec);
for(Student__c temp:stu){
if(rec==temp.id){
System.debug('inside the loop '+ rec);
temp1=temp;
}
}
this.student = temp1;
System.debug('X154865'+temp1+' - '+this.student);
}
}
VF page
<apex:page controller="DemoClass" >
<apex:form>
<apex:selectList value="{!countries}" multiselect="false" onchange="func();">
<apex:selectOptions value="{!items}"/>
</apex:selectList><p/>
<apex:actionFunction name="func" action="{!test}" rerender="out" status="status"/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
<apex:outputPanel id="out">
<apex:inputText value="{!student.First_Name__c}"/>
<apex:actionstatus id="status" startText="testing...">
<apex:facet name="stop">
<apex:outputPanel>
<p>You have selected:</p>
<apex:dataList value="{!countries}" var="c">{!c}</apex:dataList>
{!student.Name}
hi hi hi {!student.ID} {!student.First_name__c}
<h1>
name is {!fname}
</h1>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</apex:form>
</apex:page>
Please help me thorugh. Let me know if any further details are required from my end
Thanks for the reply, really appreciate the help, problem is solved, the problem was this page i was calling in the Dalseforce site, and since i do not had the permission for the Guest user so the the data was not coming in the VF page.
Again thanks for the reply,
All Answers
but if <apex:inputText value="{!fname }"/> is used the text input is appearing
You are unable tie an apex:inputField to the student fields as you haven't provided a public getter - add the following method and you should be good to go:
I Have Made Changes to Your Code
Try This One...
public class DemoClassTest{
public String countries{get;set;}
public List<Student__c> stu {get;set;}
public String fname{get;set;}
public Student__c student{get;set;}
public DemoClassTest(){
stu = [select name,First_name__c, Last_Name__c,Age__c,Sex__c from Student__c limit 10];
student = new Student__c();
}
public PageReference test() {
setS(ID.ValueOf(countries));
fname=student.First_name__c;
return null;
}
/*public Student__c getstudent(){
return student;
}*/
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
for(Student__c temp:stu){
options.add(new SelectOption(String.valueOf(temp.ID),temp.name));
}
return options;
}
public void setS(ID rec) {
// countries = '11111';
Student__c temp1 = null;
System.debug('before the loop '+ rec);
for(Student__c temp:stu){
if(rec==temp.id){
System.debug('inside the loop '+ rec);
temp1=temp;
}
}
this.student = temp1;
System.debug('X154865'+temp1+' - '+this.student);
}
}
Thanks for the reply, really appreciate the help, problem is solved, the problem was this page i was calling in the Dalseforce site, and since i do not had the permission for the Guest user so the the data was not coming in the VF page.
Again thanks for the reply,