You need to sign in to do that
Don't have an account?
opening a new window from apex-code after validation
I have a button on a visualforce page that will generate a report using a url in another window, similar to the code below:
<apex:commandButton value="Submit" action="{!controlleraction}" onClick="window.open('/apex/VFPage');"/>
What I want to do is to stop the onClick event from happening if the controlleraction has an error. Basically when they click the button I need to run some validations to make sure the report won't be blank or contain in correct data. So I want to first run a validation routine in the controller, if it passes then I want the report to generate. If not, I don't need the report to open; the controller method will return an error to the page.
I'm a big fan of action functions, and rerenders I use as little apex as possible when it comes to interface logic. Here is how I would approach the situation:
Create a "success" boolean in your controller that can be set to true or false during yoru controller action.
Use an action function to call the controller action, and on complete: rerender an area of the page with the resulting success boolean as a javascript variable
Use the javascript variable to determine if the user should get redirected, or not
Something like this:
This way you neve rhave to use those silly pageReferences, and you can add as much logic before the button click, and after
All Answers
Here you can do as follow.
when u do validation check using some method and if this validation didn't went through you will raise some error message.
so do a check on the error message == null. then call the method which will generate the report.
the only thing just do check like message.size() ==null or message == null which ever fit over there and then do the as usual task that you are doing now.
If this answers your make this as a solution and Give KUDOs. PLZ.
Thanks,
Suresh.
I'm a big fan of action functions, and rerenders I use as little apex as possible when it comes to interface logic. Here is how I would approach the situation:
Create a "success" boolean in your controller that can be set to true or false during yoru controller action.
Use an action function to call the controller action, and on complete: rerender an area of the page with the resulting success boolean as a javascript variable
Use the javascript variable to determine if the user should get redirected, or not
Something like this:
This way you neve rhave to use those silly pageReferences, and you can add as much logic before the button click, and after
This is what I needed, Thanks!