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

Problem on rerender dynamicComponent
Hi,
I have a problem with my visualforce page.
This the kind of page/result I want to (in a simplified version):
<apex:page controller="Test1" > <apex:form > <apex:pageBlock> <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!saveNewRecord}" rerender="newRecordForm" /> </apex:pageBlockButtons> <apex:pageBlockSection id="newRecordForm" > <apex:inputField value="{!newRecord['Name']}"/> <apex:inputField value="{!newRecord['Date__c']}" required="true"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
public with sharing class Test1 { public sobject newRecord{get;set;} public Test1(){ this.newRecord = Schema.getGlobalDescribe().get('MyObject__c').newSObject(); } public void saveNewRecord(){ //Save Here } }
When I just fill the "Name" field and save, it works fine:
Name: |
| Date: |
Now I try do the same but with a dynamicComponent (I need to for my non-simplified page):
<apex:page controller="Test2" > <apex:form > <apex:pageBlock> <apex:pageBlockButtons location="top"> <apex:commandButton value="Save" action="{!saveNewRecord}" rerender="newRecordForm" /> </apex:pageBlockButtons> <apex:dynamicComponent componentValue="{!newRecordForm}"/> </apex:pageBlock> </apex:form> </apex:page>
public with sharing class Test2{ public sobject newRecord{get;set;} public Test2(){ this.newRecord = Schema.getGlobalDescribe().get('MyObject__c').newSObject(); } public Component.Apex.PageBlockSection getNewRecordForm(){ Component.Apex.PageBlockSection form = new Component.Apex.PageBlockSection(id = 'newRecordForm'); Component.Apex.inputField nameField = new Component.Apex.inputField(); nameField.expressions.value = '{!newRecord[\'Name\']}'; Component.Apex.inputField dateField = new Component.Apex.inputField(required = true); dateField.expressions.value = '{!newRecord[\'Date__c\']}'; form.childComponents.add(nameField); form.childComponents.add(dateField); return form; } public void saveNewRecord(){ //Save Here } }
When I just fill the "Name" field and save, the "Name" value disappears on rerender:
Name: |
| Date: |
The newRecord controller variable doesn't seems to be updated here. But if I fill both fields, there is no error and the saveNewRecord() method retrieves both values...
I hope I was clear and that someone could help me.
Thanks
There have been some issues with inputField losing input values when a validation error occurs. Sounds like you ahve found another one. You should open a support case.
I did, but if it's an Apex/VF bug it won't be resolved before a long time and I need it now...
Worst solution ever:
With something like:
I'm waiting for my case response because I really don't like this "solution".
dirty solution but still one solution ...
I ameliorated a bit your saveInputFunction to get also select fields. This looks now like that:
I'm not sure how that works with multiselect but I don't need that for my code so that's fine.