You need to sign in to do that
Don't have an account?
Scott.M
Extra DML Validation Error Display
Hi all,
I've created a visual force page with a controller extension that makes edits to a custom object and a list of related custom objects. I've added a custom validation rule to the related object and I would like the error messages for the related object to appear correctly in the page however only error messages for the parent object which the standard controller handles displayes the validation error correctly. If there is a validation error in the child objects it throws the exception and goes to an ugly exception page.
Here's the save function:
I thought about using a try catch to catch the exceptions and store them in an array then display them
But there's no if type statements in the visualforce tag library so I'm not sure how I would check to see if there are errors and if there are display them, and if not don't display anything. Any help is much appreciated.
Message Edited by Scott.M on 06-03-2008 06:47 AM
I've created a visual force page with a controller extension that makes edits to a custom object and a list of related custom objects. I've added a custom validation rule to the related object and I would like the error messages for the related object to appear correctly in the page however only error messages for the parent object which the standard controller handles displayes the validation error correctly. If there is a validation error in the child objects it throws the exception and goes to an ugly exception page.
Here's the save function:
Code:
public PageReference save(){ upsert PartOrder; for(PartOrderPart p: PartOrderParts) { p.pop.Part_Order__c = this.PartOrder.Id; upsert p.pop; } PageReference poPage = new PageReference('/' + PartOrder.id); poPage.setRedirect(true); return poPage; }
I thought about using a try catch to catch the exceptions and store them in an array then display them
Code:
for(PartOrderPart p: PartOrderParts) { try { p.pop.Part_Order__c = this.PartOrder.Id; upsert p.pop; } catch (System.DmlException e) { //store error in an array } }
But there's no if type statements in the visualforce tag library so I'm not sure how I would check to see if there are errors and if there are display them, and if not don't display anything. Any help is much appreciated.
Message Edited by Scott.M on 06-03-2008 06:47 AM
Then in the visualforce page doing something like this will show the error only if there is an error message
Pretty slick and no need for if statements. Hopefully this helps someone in the future
Message Edited by Scott.M on 06-04-2008 07:16 AM
Message Edited by Scott.M on 06-04-2008 07:18 AM
All Answers
Then in the visualforce page doing something like this will show the error only if there is an error message
Pretty slick and no need for if statements. Hopefully this helps someone in the future
Message Edited by Scott.M on 06-04-2008 07:16 AM
Message Edited by Scott.M on 06-04-2008 07:18 AM
As a side note rendered is very often the best fit once you get used to this style of conditional rendering. With that said there are times when we know that something more along the lines of an if-then-else style or case statements would be useful (can always be acoomplished with rendered but when we're talking about one or more releated alternatives this can seem a bit unnatural or cumbersome) and we are evaluating additional components that would support this.
http://ideas.salesforce.com/article/show/10089418/Add_conditional_block_Visualforce_components_eg_ltapexif_ltapexcase_etc?skin=null
Please promote/vote on this idea if you want to see us add this functionality :-)
Message Edited by dchasman on 06-06-2008 10:24 AM
{!PartOrderPart.ErrorMessage != null}
is great for generating truth value for rendered component, I am finding it hard to generate conditional output to be used in regular html element attributes.
For example, I want to generate title of an anchor for jquery-cluetip. For my case, The title attribute should be either empty string or a pipe character prepended to tooltip text. This is what I want to do
title = " ({!tooltip != null}) ? (|{!tooltip}) : (''))
If getTooltip() returns something like 'test', title is set to
(true) ? (|test) : ('')
instead of just
|test
What am I missing here?
I can prepend the pipe character in getTooltip method but that would be my last resort. Please help.
Thanks.
so for now this is a slightly more verose way to achieve the same thing:
Message Edited by dchasman on 06-18-2008 03:50 PM