function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Repost:Help with validation of input fields in a pageblock table

Hi All,


I have developed a vf page in which once a user chooses a pricebook , he will be able to see the list of products tied to that pricebook in a pageblock table. In order to accomplish this I have used the wrapper class which has a checked field and some input field along with fields from PRoduct2 object.


I have two options to write a validation to check the quqntity is not 0 if the product checkbox is checked .


1) From javascript ---client side validation:


I want to write a validation in javascript , when the checkbox is checked i.e that product is selected, I need to validate the quantity column in th table and alert if the quantity is 0.


When I read the checkbox field from javascript though it is checked or unchecked I am getting  a value of null always :


alert(document.getElementById('{!$Component.theForm.ProductDetail.ProductDetails.table.selectLine1}'));----returns null
and  alert(document.getElementById('{!$Component.selectLine1}')); ------retruns null



2) From Apex controller ---server side validation


I ama ble to read the values from the apex class perfectly fine i.e, checked as false initially and once user selects the product it is true.


And if the product is checked and the quantity field is 0 I am displaying a error message like below:


ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Please Enter Quantity  for the Product Selected!!') );
                     return null; ---------> When I return this pagereference  all the information enters by the user disappears and the page is clear of all the user inputted data.


How can I retain the information entered by the user and display a validation message .


Any help on client side or server side validation is highly appreciated.






Suresh RaghuramSuresh Raghuram

Hi Harini,


generally if iam in your place, I will write a seperate method for allvalidation checks and call the  validationMethod() with in the save method. if this go through then only i will work on the next save and other things.


If the above solution does n't work for your first problem use the action function or action support tag.


Even these things doesnt work use Database.SavePoint(). rollback;.


you can make use of 1st and 2nd together. 

if there is any integration work is going with in your code then the savepoint and rollback will run you into more complexity. 


Choose according to your requirement.


If this helps you make this as a solution and give kudos please.







All I am trying to do is a client side validation and server side validation for the entered input text fields in the pageblock table.


I want both validations to be doubly sure the data is valid. I am able to do client side validation to some extent but the problem is with the server side validation.


I am performing the validation on click of a button (here in the function call action="{!productSelected}" is called) and the return type will be  apage reference. Once I do the validation I am displaying an error message see below and returning a null to be on the same page.


ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'xyz'));

return null; ------This is clearing  the pageblock table of the user inputted data.


Per your suggestion if I segregrate the validation in to another function what should be the return type of that function, inorder to restrict the user to go ahead with the submission and displaying a validation message.


Any suggestion are greatly appreciated.








Per the suggestion od suree(suresh) I have segregated the validation into an another function and on click of a button calling this function to validate.


public static Boolean validateInput(List<wrapperclass> wraplist>)



 -----do some validation -----

  if fails --- ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, 'Pleasefill in the xyz field!!') );

    return false

 or return true;




public pagereference onclickFunctioncall(){

errormsg= validateInput(xyz);

Though the return of function call is false, the user is taken to next page // How do I restrict htis Return null does bot work as the user inputted values in the pageblocktable are wiped off and the fresh table is returned.





Any help is appreciated

Hi Harini,

i am getting the same issue?

Did you solve this issue?

if it was solved please give me the guidance for client side validation and server side validation for the entered input text fields in the pageblock table.

if error diplayed on the form ......user inputted values in the pageblocktable are wiped off and the fresh table is returned.

How to solve this...... Please HELP me on this.

Any help is appreciated.