I get an error in visualforce page now. Saying:
Error:Unknown property 'tudent__cStandardController.d'
This happens when I add the delete commandLink button to the vf page. Before I add it it doesn't put out an error but on it doesn't display records on the page.
Thanks for help in advance
Visualforce code:
<apex:page standardController="tudent__c" extensions="vidsav">
<apex:form >
<apex:outputPanel id="check">
<apex:pageBlock title="Dodaj Študenta">
<apex:pageBlockSection columns="1">
<apex:inputField value="{! tudent__c.Name }"/>
<apex:inputField value="{! tudent__c.priimek__c }"/>
<apex:inputField value="{! tudent__c.Datum_rojstva__c }"/>
<apex:inputField value="{! tudent__c.letnik__c }"/>
<apex:inputField value="{! tudent__c.Naslov__c }"/>
<apex:inputField value="{! tudent__c.naziv_fakultete__c }"/>
<apex:inputField value="{! tudent__c.tudijski_program__c }"/>
<apex:inputField value="{! tudent__c.tip_tudija__c }">
<apex:actionSupport event="onchange" rerender="check" />
</apex:inputField>
<apex:inputField value="{! tudent__c.Samopla_nik__c }" rendered="{!IF( tudent__c.tip_tudija__c == 'izredni', true, false )}" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:outputPanel>
<apex:pageBlock title="Študenti">
<apex:pageBlockTable value="{!studentsR}" var="s" >
<apex:commandLink action="{!deleteStudent}" onclick="if(!confirm('Are you sure?')) return false;">`enter code here`Del
<apex:param value="{!d.Id}" name="idToDel" assignTo="{!SelectedStudentId}"/>
</apex:commandLink>
<apex:column value="{!s.Name}"/>
<apex:column value="{!s.priimek__c}"/>
<apex:column value="{!s.Datum_rojstva__c}"/>
<apex:column value="{!s.letnik__c}"/>
<apex:column value="{!s.Naslov__c}"/>
<apex:column value="{!s.naziv_fakultete__c}"/>
<apex:column value="{!s.tudijski_program__c}"/>
<apex:column value="{!s.tip_tudija__c}"/>
<apex:column value="{!s.Samopla_nik__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller:
public class vidsav {
public vidsav(ApexPages.StandardController controller) {
}
public List<tudent__c> studentsR {get;set;}
public String SelectedStudentId {get;set;}
public vidsav() {
loadData();
}
public void loadData() {
studentsR = [Select id,Name,priimek__c,Datum_rojstva__c,letnik__c,Naslov__c,naziv_fakultete__c,tudijski_program__c,tip_tudija__c,Samopla_nik__c, CreatedDate from tudent__c Order By CreatedDate desc];
}
public void deleteStudent(){
studentsR = [Select id,Name,priimek__c,Datum_rojstva__c,letnik__c,Naslov__c,naziv_fakultete__c,tudijski_program__c,tip_tudija__c,Samopla_nik__c, CreatedDate from tudent__c where id = :SelectedStudentId];
if(studentsR.size() > 0 || studentsR[0].Id != ''){
delete studentsR;
}
loadData();
}
}
Here is the updated code you should use ->
1) Update your PageBlockTable to this -
<apex:pageBlockTable value="{!studentsR}" var="s" >
<apex:column value="{!s.Name}"/>
<apex:column value="{!s.priimek__c}"/>
<apex:column value="{!s.Datum_rojstva__c}"/>
<apex:column value="{!s.letnik__c}"/>
<apex:column value="{!s.Naslov__c}"/>
<apex:column value="{!s.naziv_fakultete__c}"/>
<apex:column value="{!s.tudijski_program__c}"/>
<apex:column value="{!s.tip_tudija__c}"/>
<apex:column value="{!s.Samopla_nik__c}"/>
<apex:column>
<apex:commandLink action="{!deleteStudent}" onclick="if(!confirm('Are you sure?')) return false;" value="Del">
<apex:param value="{!s.Id}" name="idToDel" assignTo="{!SelectedStudentId}"/>
</apex:commandLink>
</apex:column>
You needed to put your commandLink
inside an apex:column in order for it to display correctly in the pageBlockTable
and also of course the d
had to be replaced with a s
since your table variable is s
(var="s").
2) Update your Controller to this -
public class vidsav {
public vidsav(ApexPages.StandardController controller) {
loadData();
}
public List<Account> studentsR {get;set;}
public String SelectedStudentId {get;set;}
public void loadData() {
studentsR = [Select id,Name,priimek__c,Datum_rojstva__c,letnik__c,Naslov__c,naziv_fakultete__c,tudijski_program__c,tip_tudija__c,Samopla_nik__c, CreatedDate from tudent__c Order By CreatedDate desc];
}
public void deleteStudent(){
studentsR = [Select id,Name,priimek__c,Datum_rojstva__c,letnik__c,Naslov__c,naziv_fakultete__c,tudijski_program__c,tip_tudija__c,Samopla_nik__c, CreatedDate from tudent__c where id = :SelectedStudentId];
if(studentsR.size() > 0 || studentsR[0].Id != ''){
delete studentsR;
}
loadData();
}
}
You were using two constructors and were calling loadData() from the wrong one and this is why it was not loading data. With this you will be able to delete records and reload your table.