You need to sign in to do that
Don't have an account?
pacstrats
Visualforce Wizard Issues
I'm fairly new to Visualforce but a long-time user of SFDC. I am trying to create a simple wizard to walk users through 5 pages of one form instead of one long form per the usual SFDC UI. I am running into a major issue:
I have a number of validations set-up and beyond requiring certain fields, I have no idea how to prevent the user from continuing to the next page if there are validation issues. This is an issue since the whole process crashes if the user saves the record without fixing the issues.
I tried to copy as much from the example in the Cookbook but I've hit a wall.
Here is my code (substitute x for < due to posting issues):
Page 1 of 5 (all of the VF pages use the same logic/framework)
xapex: page standardController="Penrose_Project__c" extensions="PenroseProjectWizard" tabStyle="Penrose_Project__c">
xapex:sectionHeader title="New Project"
subtitle="Location - Step 1 of 5"/>
xapex:form >
xapex: pageBlock >
xapex: pageBlockButtons >
xapex:commandButton action="{!cancel}" value="Cancel"/>
xapex:commandButton action="{!step2}" value="Next"/>
x/apex: pageBlockButtons>
xapex: pageBlockSection columns="2" title="Location Information">
xapex: outputField value="{!PenProj.Name}"/>
x/br>
xapex:inputField id="building" value="{!PenProj.P_Building__c}" required="TRUE"/>
x/br>
xapex:inputField id="floor" value="{!PenProj.P_Floor__c}" required="TRUE"/>
x/apex: pageBlockSection>
xapex: pageBlockSection columns="2" title="Departments Affected">
xapex:inputField id="above" value="{!PenProj.Above__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="below" value="{!PenProj.Below__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="north" value="{!PenProj.North__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="south" value="{!PenProj.South__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="east" value="{!PenProj.East__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="west" value="{!PenProj.West__c}" required="TRUE"/ style="width:300px">
x/apex: pageBlockSection>
xapex: pageBlockSection columns="2" title="Project Dates">
xapex:inputField id="start" value="{!PenProj.Project_Start_Date__c}" required="TRUE"/>
xapex:inputField id="end" value="{!PenProj.Project_End_Date__c}" required="TRUE"/>
x/apex: pageBlockSection>
x/apex: pageBlock>
x/apex:form>
x/apex: page>
Controller:
public class PenroseProjectWizard {
Account account;
Penrose_Project__c PenProj;
public Penrose_Project__c getPenProj(){
if(PenProj == null) PenProj = new Penrose_Project__c();
return PenProj;
}
public PenroseProjectWizard(ApexPages.StandardController stdController){
PenProj = (Penrose_Project__c) stdController.getRecord();
PenProj.Location__c = ApexPages.currentPage().getParameters().get('location');
PenProj.Name = ApexPages.currentPage().getParameters().get('name');
PenProj.RecordTypeId = [SELECT r.Id FROM RecordType r WHERE r.SobjectType = 'Penrose_Project__c' AND r.Name = :ApexPages.currentPage().getParameters().get('recordtype')].Id;
}
public PageReference cancel() {
PageReference Cancelled = new PageReference('/' + PenProj.Location__c);
Cancelled.setRedirect(true);
return Cancelled;
}
public PageReference step1() {
return Page.newphproject1;
}
public PageReference step2() {
return Page.newphproject2;
}
public PageReference step3() {
return Page.newphproject3;
}
public PageReference step4() {
return Page.newphproject4;
}
public PageReference step5() {
return Page.newphproject5;
}
public PageReference save() {
insert PenProj;
PageReference ProjectStep = new PageReference('/' + PenProj.id);
ProjectStep.setRedirect(true);
return ProjectStep;
}
}
Custom Button:
https://na6.salesforce.com/apex/newphproject1?
location={!Account.Id}&
name="Pending"&
recordtype={!Account.RecordType}
Any help, tips or tricks would be greatly appreciated.
Travis
Message Edited by pacstrats on 11-14-2008 12:49 AM
Message Edited by pacstrats on 11-14-2008 12:49 AM
Message Edited by pacstrats on 11-14-2008 12:50 AM
Message Edited by pacstrats on 11-14-2008 12:54 AM
Message Edited by pacstrats on 11-14-2008 12:56 AM
I have a number of validations set-up and beyond requiring certain fields, I have no idea how to prevent the user from continuing to the next page if there are validation issues. This is an issue since the whole process crashes if the user saves the record without fixing the issues.
I tried to copy as much from the example in the Cookbook but I've hit a wall.
Here is my code (substitute x for < due to posting issues):
Page 1 of 5 (all of the VF pages use the same logic/framework)
xapex: page standardController="Penrose_Project__c" extensions="PenroseProjectWizard" tabStyle="Penrose_Project__c">
xapex:sectionHeader title="New Project"
subtitle="Location - Step 1 of 5"/>
xapex:form >
xapex: pageBlock >
xapex: pageBlockButtons >
xapex:commandButton action="{!cancel}" value="Cancel"/>
xapex:commandButton action="{!step2}" value="Next"/>
x/apex: pageBlockButtons>
xapex: pageBlockSection columns="2" title="Location Information">
xapex: outputField value="{!PenProj.Name}"/>
x/br>
xapex:inputField id="building" value="{!PenProj.P_Building__c}" required="TRUE"/>
x/br>
xapex:inputField id="floor" value="{!PenProj.P_Floor__c}" required="TRUE"/>
x/apex: pageBlockSection>
xapex: pageBlockSection columns="2" title="Departments Affected">
xapex:inputField id="above" value="{!PenProj.Above__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="below" value="{!PenProj.Below__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="north" value="{!PenProj.North__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="south" value="{!PenProj.South__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="east" value="{!PenProj.East__c}" required="TRUE"/ style="width:300px">
xapex:inputField id="west" value="{!PenProj.West__c}" required="TRUE"/ style="width:300px">
x/apex: pageBlockSection>
xapex: pageBlockSection columns="2" title="Project Dates">
xapex:inputField id="start" value="{!PenProj.Project_Start_Date__c}" required="TRUE"/>
xapex:inputField id="end" value="{!PenProj.Project_End_Date__c}" required="TRUE"/>
x/apex: pageBlockSection>
x/apex: pageBlock>
x/apex:form>
x/apex: page>
Controller:
public class PenroseProjectWizard {
Account account;
Penrose_Project__c PenProj;
public Penrose_Project__c getPenProj(){
if(PenProj == null) PenProj = new Penrose_Project__c();
return PenProj;
}
public PenroseProjectWizard(ApexPages.StandardController stdController){
PenProj = (Penrose_Project__c) stdController.getRecord();
PenProj.Location__c = ApexPages.currentPage().getParameters().get('location');
PenProj.Name = ApexPages.currentPage().getParameters().get('name');
PenProj.RecordTypeId = [SELECT r.Id FROM RecordType r WHERE r.SobjectType = 'Penrose_Project__c' AND r.Name = :ApexPages.currentPage().getParameters().get('recordtype')].Id;
}
public PageReference cancel() {
PageReference Cancelled = new PageReference('/' + PenProj.Location__c);
Cancelled.setRedirect(true);
return Cancelled;
}
public PageReference step1() {
return Page.newphproject1;
}
public PageReference step2() {
return Page.newphproject2;
}
public PageReference step3() {
return Page.newphproject3;
}
public PageReference step4() {
return Page.newphproject4;
}
public PageReference step5() {
return Page.newphproject5;
}
public PageReference save() {
insert PenProj;
PageReference ProjectStep = new PageReference('/' + PenProj.id);
ProjectStep.setRedirect(true);
return ProjectStep;
}
}
Custom Button:
https://na6.salesforce.com/apex/newphproject1?
location={!Account.Id}&
name="Pending"&
recordtype={!Account.RecordType}
Any help, tips or tricks would be greatly appreciated.
Travis
Message Edited by pacstrats on 11-14-2008 12:49 AM
Message Edited by pacstrats on 11-14-2008 12:49 AM
Message Edited by pacstrats on 11-14-2008 12:50 AM
Message Edited by pacstrats on 11-14-2008 12:54 AM
Message Edited by pacstrats on 11-14-2008 12:56 AM
David
Message Edited by David VP on 11-14-2008 08:48 PM
*apex:actionRegion >
*apex: pageBlockSection title="Noise" columns="1">
*apex: pageBlockSectionItem >
*apex: outputLabel value="Noise Generated?"/>
*apex: outputPanel >
*apex:inputField id="noise" value="{!PenProj.Noise_Generated__c}" required="true">
*apex:actionSupport event="onchange" rerender="step3"
status="noise"/>
*/apex:inputField>
*apex:actionStatus startText="applying value..." id="noise"/>
*/apex: outputPanel>
*/apex: pageBlockSectionItem>
*/apex: pageBlockSection>
*/apex:actionRegion>
*apex: pageBlockSection columns="2"
rendered="{!PenProj.Noise_Generated__c == 'Yes'}">
*apex:inputField id="who_noise" value="{!PenProj.Who_Contacted_Noise__c}"/ required="true">
*apex:inputField id="when_noise" value="{!PenProj.When_Contacted_Noise__c}"/ required="true">
*/apex: pageBlockSection>
but if it works ...
David
P.S. Use the SRC button to insert code in your posts, it will make it a lot more readable. Happy coding !
This really didn't solve the validation issue but rather forces the user to complete the form as intended, which is what the validation code was ultimately used for.
T
As far as your validation issues go, the problem is that most field validations happen at the API level on update or insert, and those validations aren't going to happen until you actually attempt to save the object, which usually happens in your last step. So that means you might need to do your own validation in your controller -- check for invalid values in your fields and add an error message to your page so you don't continue on to step 2 if there's an error in step 1.
How do you display the validation error NEXT TO EACH FIELD - seems like all messages go to top of page when Apex:Messages or PageMessages tag is used. If I don't use the tag, no messages are shown.
I am using try/catch in my custom controller with ApexPages.addMessages(e) in catch exception.
If I don't catch the exception, I was hoping that validation rules will prevent a crash but the system crashes.