You need to sign in to do that
Don't have an account?
Problems with get and set time of work and triggering actionFunction
The problem i have is with vf page. What i need to do is get two values which are Date type from user and after he click button based on those values gatther data from SF and show them in correct way.
I am at very begining of the road and I am blocked with that my variables do not get updated after button click. So i can't really sue them in my controller and what is more i can rerender content of page with other variable cause it is not changing for page as well...
Code page:
<apex:page controller="pageGenerator" docType="html-5.0">
<apex:form>
<script>
function sideSetter()
{
dataSetter();
document.getElementById('{!$Component.mainform.mainBlock.mainDisplay}').innerHTML = '{!mainTableArea}';
}
</script>
<apex:actionFunction name="dataSetter" action="{!dataSetter}" rerender="mainform.mainDisplay"/>
</apex:form>
<apex:form id="mainform">
<apex:pageBlock title="dynamictest" id="mainBlock">
<apex:pageBlockSection title="Filters" id="mainWork" columns="1">
<apex:input title="Start date" label="Start date" type='date' value="{!startDate}"/>
<apex:input title="End date" label="End date" type="date" value="{!endDate}"/>
<apex:commandButton value="Generate" onclick="sideSetter();" rerender="mainform.mainDisplay"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="renderedpart" id="mainDisplay">
Nothing yet....
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Code controller:
public class pageGenerator
{
public String mainTableArea {get;set;}
public Date startDate {get;set;}
public Date endDate {get;set;}
private void setMainTableArea( String theString )
{
this.mainTableArea = theString;
}
public pageGenerator()
{
mainTableArea = 'nicnicnic';
startDate = Date.today();
endDate = Date.today().addMonths(1);
}
public PageReference dataSetter()
{
setMainTableArea( String.valueOf(startDate) + ' ' + String.valueOf(endDate) );
system.debug( MainTableArea + ' ' + String.valueOf(startDate) + ' ' + String.valueOf(endDate) );
return null;
}
}
Can any one tell me what i do wrong. After clicking the button some times endDate get updated but never startDate and the mainTableArea varaible never get's updated when the dataSetter methods is being triggered.
By the way if you think this is bad way of doing what i want and i should use other technology let me know ;) we use only classic.
Hi Dheeraj sory fornot naswering but i had to fix one bug instantly. So i kind of fixed it all with just making it simpler:
<apex:page controller="ams_HRpageGenerator" docType="html-5.0">
<apex:form id="mainform">
<apex:pageBlock title="dynamictest" id="mainBlock">
<apex:pageBlockSection title="Filters" id="mainWork" columns="1">
<apex:input title="Start date" label="Start date" type="date" value="{!startDate}"/>
<apex:input title="End date" label="End date" type="date" value="{!endDate}"/>
<apex:commandButton value="Generate" action="{!dataSetter}" rerender="mainform"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="renderedpart" id="mainDisplay">
<apex:outputText value="{!mainTableArea}" escape="false" /> <br/>
{!startDate}<br/>
{!endDate}
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here is page and controller now using standart {get; set} works just fine :) But thx for help any way.
All Answers
Try with below updated code in apex controller and visualforce page. I would say use a outputPanel inside pageBlockSection and that should fix the issue. Also we don't need the action function for this. we can directly call the controller method on commandButton action and in rerender attribute of commandButton we can rerender outputPanel
Visualforce Page : Apex Controller :
Hit Kudos if this solve you problem and if this is what you are looking for then please mark it as a solution for other benefits.
Thanks
Dheeraj Kumar
Code as you provided is generating error: Unknown propery 'pageGenerator.dataSetter'.
I am not facing this problem with same code.
First we need to save the controller class which have dataSetter method. Then after try to save the visualforce page.
This error is saying that we don't have the property as dataSetter in controller. I think you are using this dataSetter method as property in visualforce.
Can you post your code of visualforce page and controller.
Thanks
Dheeraj Kumar
Hi Dheeraj sory fornot naswering but i had to fix one bug instantly. So i kind of fixed it all with just making it simpler:
<apex:page controller="ams_HRpageGenerator" docType="html-5.0">
<apex:form id="mainform">
<apex:pageBlock title="dynamictest" id="mainBlock">
<apex:pageBlockSection title="Filters" id="mainWork" columns="1">
<apex:input title="Start date" label="Start date" type="date" value="{!startDate}"/>
<apex:input title="End date" label="End date" type="date" value="{!endDate}"/>
<apex:commandButton value="Generate" action="{!dataSetter}" rerender="mainform"/>
</apex:pageBlockSection>
<apex:pageBlockSection title="renderedpart" id="mainDisplay">
<apex:outputText value="{!mainTableArea}" escape="false" /> <br/>
{!startDate}<br/>
{!endDate}
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Here is page and controller now using standart {get; set} works just fine :) But thx for help any way.
I am happy that your issue has been resolve now. Hit Kudos if above solution works for you and if this is what you are looking for then please mark it as a solution for better and clean community.
Thanks
Dheeraj Kumar