I am new to VisualForce and I am not able to get my head around how do I pass value from vf page to my apex class when I have list of data.
I am adding my code snippets below,
Vf Page:
<apex:page controller="PublicController">
<apex:form>
<apex:pageBlock id="one">
<apex:pageBlockTable value="{!credential}" var="account" id="theTable">
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputText value="{!account.Username__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Pass</apex:facet>
<apex:outputText value="{!account.Password__c}"/>
</apex:column>
<apex:column >
<apex:commandButton value="click" action="{!LoginHere}">
<apex:param name="accid" value="{!account.Id}" assignTo="{!accid}" />
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Class:
public class PublicController {
List<Credential__c> Credential=new List<Credential__c>();
public string accid {set;get;}
public void LoginHere(){
System.debug(accid);
for(Credential__c currCredential : credential){
if(currCredential.Id == accid){
System.debug('CurrCredential'+currCredential);
break;
}
}
}
public List<Credential__c> getCredential(){
Credential = [SELECT id,Username__c,Password__c FROM Credential__c];
return Credential;
}
}
Do let me know if you need anything else from my side for better clarification.