You need to sign in to do that
Don't have an account?

Passing Value from controller to Page
After the method call, I am setting the flag value to true, but on the page it is always false. Can someone please look into this and let me know if i am m issing something.
<apex:page standardController="Opportunity" extensions="testcontroller">
<script type="text/javascript">
function testclick(Value){
testcheck(Value);
alert({!flag});
}
</script>
<apex:form >
<apex:actionFunction action="{!phaseCheck}" name="testcheck" reRender="">
<apex:param assignTo="{!pValue}" value="" name="someName"/>
</apex:actionFunction>
<apex:pageBlock >
<apex:inputCheckbox title="Test" id="chkbox" onclick="testclick('Test')"/>
<apex:outputLabel id="olabel" for="chkbox">Test</apex:outputLabel>
</apex:pageBlock>
</apex:form>
</apex:page>
public class testcontroller{
public testcontroller(ApexPages.StandardController controller) {
}
public Static String pValue{get;set;}
public Static boolean flag{get;set;}
public static void phaseCheck(){
system.debug('Test --->' + pValue);
flag = true;
system.debug('flag --->' + flag);
}
}
transient does not work.
Try this :
Hopefully it should work.
Copy and paste complete code :
<apex:page standardController="Opportunity" extensions="testcontroller">
<apex:form id="formId">
<script>
function testclick(Value)
{
testcheck(Value);
}
function handleRequest()
{
alert({!flag});
}
</script>
<apex:actionFunction action="{!phaseCheck}" name="testcheck" reRender="formId" oncomplete="handleRequest()">
<apex:param assignTo="{!pValue}" value="" name="someName"/>
</apex:actionFunction>
<apex:pageBlock >
<apex:inputCheckbox title="Test" id="chkbox" onclick="testclick('Test')"/>
<apex:outputLabel id="olabel" for="chkbox">Test</apex:outputLabel>
</apex:pageBlock>
</apex:form>
</apex:page>
All Answers
That was the problem with reRender.
Try this :
<apex:page standardController="Opportunity" extensions="testcontroller">
<apex:form id="formId">
<script>
function testclick(Value)
{
alert({!flag});
testcheck(Value);
}
</script>
<apex:actionFunction action="{!phaseCheck}" name="testcheck" reRender="formId">
<apex:param assignTo="{!pValue}" value="" name="someName"/>
</apex:actionFunction>
<apex:pageBlock >
<apex:inputCheckbox title="Test" id="chkbox" onclick="testclick('Test')"/>
<apex:outputLabel id="olabel" for="chkbox">Test</apex:outputLabel>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks for the reply, I tried your solution but unfortunately it doesnt work. I can see the value being setting in the controller but somehow it is not reflecting on the page.
You copy this complete code and paste in your visual force
<apex:page standardController="Opportunity" extensions="testcontroller">
<apex:form id="formId">
<script>
function testclick(Value)
{
alert({!flag});
testcheck(Value);
}
</script>
<apex:actionFunction action="{!phaseCheck}" name="testcheck" reRender="formId">
<apex:param assignTo="{!pValue}" value="" name="someName"/>
</apex:actionFunction>
<apex:pageBlock >
<apex:inputCheckbox title="Test" id="chkbox" onclick="testclick('Test')"/>
<apex:outputLabel id="olabel" for="chkbox">Test</apex:outputLabel>
</apex:pageBlock>
</apex:form>
</apex:page>
One more thing, First Check it and the Un-Check it.
You will find the difference.
It is returning a true, when I check it for the second time. I am trying display an error message when it is checked for the first time. If I do it this way it will not be captured the first time but it will done on second click, which defeats the purpose. Is there any other way to do this?
I will give it a try with the transient keyword and see if it works.
transient does not work.
Try this :
Hopefully it should work.
Copy and paste complete code :
<apex:page standardController="Opportunity" extensions="testcontroller">
<apex:form id="formId">
<script>
function testclick(Value)
{
testcheck(Value);
}
function handleRequest()
{
alert({!flag});
}
</script>
<apex:actionFunction action="{!phaseCheck}" name="testcheck" reRender="formId" oncomplete="handleRequest()">
<apex:param assignTo="{!pValue}" value="" name="someName"/>
</apex:actionFunction>
<apex:pageBlock >
<apex:inputCheckbox title="Test" id="chkbox" onclick="testclick('Test')"/>
<apex:outputLabel id="olabel" for="chkbox">Test</apex:outputLabel>
</apex:pageBlock>
</apex:form>
</apex:page>
Awesome, worked like a charm. Thanks for all the effort