Validate data (server-side)
We set some (server-side) validations. Try them out by breaking the following rules:
- End date must be greater than start date
- Rows with Status "Closed" can not be changed
Validations are defined in a
custom database procedure.
It can be found inside the "uc_grid_examples" package in the "my_validation_proc" procedure or here:
code of the validation procedure
PROCEDURE my_validation_proc(p_crud_request IN OUT NOCOPY UC_GRID_CRUD_REQUEST_T)
AS
l_id NUMBER;
l_status VARCHAR2(30 BYTE);
l_start_date_str VARCHAR2(100);
l_end_date_str VARCHAR2(100);
l_start_date DATE;
l_end_date DATE;
l_date_formatmask VARCHAR2(10 char) := 'DD.MM.YYYY';
BEGIN
l_id := p_crud_request.get_value('ID');
l_status := p_crud_request.get_value('STATUS');
l_start_date_str := p_crud_request.get_value('START_DATE');
l_end_date_str := p_crud_request.get_value('END_DATE');
if l_start_date_str is not null
then
-- set custom Format mask
l_start_date := to_date(l_start_date_str, l_date_formatmask);
end if;
if l_end_date_str is not null
then
-- set custom Format mask
l_end_date := to_date(l_end_date_str, l_date_formatmask);
end if;
CASE p_crud_request.crud_request
WHEN 'DELETE' THEN
--no validations done on DELETE
NULL;
WHEN 'UPDATE' THEN
if (l_status = 'Closed') then
p_crud_request.add_exception(p_column_name => 'STATUS'
,p_exception_text => 'Change is not possible for "Closed" status.');
end if;
if (l_start_date IS NOT NULL AND l_end_date IS NOT NULL AND l_end_date < l_start_date) then
p_crud_request.add_exception(p_column_name => 'END_DATE'
,p_exception_text => 'End date must be greater than start date!');
end if;
WHEN 'INSERT' THEN
--no validations done on INSERT
NULL;
END CASE;
END my_validation_proc;