You need to sign in to do that
Don't have an account?
Passing parameter from VF page to controler method
Hi,
I have controler method that takes 2 string parameter as input and accordingly after processing internal logic return a boolean value. For Ex. the below
UserCredentialcheck(){
if(ud <> UID && pw <> PWD){
return false;
}
else{
return true;
}
}
Here UID and PWD are predefined values defined earlier on top of the class.
I would like to call this method from VF page along with the parameter. How shall I acheive this. Please suggest and guide.
Thanks in advance
Ashish
I have controler method that takes 2 string parameter as input and accordingly after processing internal logic return a boolean value. For Ex. the below
UserCredentialcheck(){
if(ud <> UID && pw <> PWD){
return false;
}
else{
return true;
}
}
Here UID and PWD are predefined values defined earlier on top of the class.
I would like to call this method from VF page along with the parameter. How shall I acheive this. Please suggest and guide.
Thanks in advance
Ashish
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_param.htm
You can use this to pass values from your page to your custom controller for business logic.
Apex:
VF:
Mark this as Best Answer, if this helps solve your problem.
here is an example with a button, I hope it help you.
VISUALFORCE CODE:
<apex:commandButton value="Send" action="{!doSomething}">
<apex:param assignTo="{!parameter1}" value="{Object.field}" />
</apex:commandButton>
CONTROLLER CODE:
public Integer parameter1 { get; set; }
public yourTye Send() {
String str= ApexPages.currentPage().getParameters().get('parameter1');
....
....
}
VF -
<apex:page controller="apxLoginCheck">
<apex:form >
<apex:pageblock >
<apex:pageblockSection columns="4">
UID: <apex:inputText value="{!UID}"/>
PWD: <apex:inputText value="{!PWD}"/>
</apex:pageblockSection>
<apex:pageblockButtons >
<apex:commandButton value="Check" action="{!buttonClick}" oncomplete="show()"/>
</apex:pageblockButtons>
<script type="text/javascript">
function show(){
var res = '{!isValidCredential}';
if(var==true){
alert('Login Success');
}
}
</script>
</apex:pageblock>
</apex:form>
</apex:page>
Controler -
public class apxLoginCheck {
// variables referred in VF
public String UID{get;set;}
public String PWD{get;set;}
public boolean isValidCredential{get; set;}
//variables initialized in controller (Apex class)
// make sure to use same data types for (ud,UID) & (pw,PWD) in apex and in VF
String ud;
String pw;
public apxLoginCheck(){
// followinf values just for example
ud='somename';
pw='****';
}
// function called from VF on button click
public void buttonClick(){
isValidCredential = UserCredentialcheck();
}
// your function
public Boolean UserCredentialcheck(){
If(UID!=ud && PWD!=pw)
return false;
else
return true;
}
}
Still the JS alert message is not working
Regards
Ashish
(added reRender attribute in commandbutton tag, assigned Ids to VF tags)
Mark this as Best Answer, if this solves your problem.