Thursday, December 28, 2006

DG Tournament updated with PW-Error Handling

Patrick Wolf and I exchanged some mails in the last weeks. I promised him to test his "ApexLib Framework" in my application.

As you can see on the picture, the package is integrated and works nicely. Patrick explains well how to integrate the package on his blog. I didn't follow the steps exactly like he wrote, for ex. I didn't make a region on page 0, but integrated a part in my template and a part in the page where I wanted to use the advanced error handling package. I also saved the javascript file as a static file in APEX.

You can't see this package working in DG Tournament for real, as I implemented this error-handling in the editor/admin part of the application. I didn't choose to implement it in the "Your Bets" page as I use (client side) javascript in that page to avoid "human"-errors. For ex. you can only type numbers in the score fields, so I don't need to check if a number was entered (and I avoid a round-trip to the server). But the picture shows you a nice error.

The ApexLib package is good, it shows very nicely what you can do and how you can improve APEX, but there's still room for improvement:
- check also if there's a number as value (now if you type 'A' the error isn't "right")
- more client-side scripting instead of server-side round-trips (but that also counts for APEX in general)

The page validation I used:
DECLARE
vMin NUMBER(3) := 0;
vMax NUMBER(3) := 99;
BEGIN
FOR i IN 1 .. ApexLib_TabForm.getRowCount
LOOP
IF ApexLib_TabForm.hasRowChanged(i)
THEN
IF ApexLib_TabForm.NV('HOME_SCORE', i) NOT BETWEEN vMin AND vMax
THEN
ApexLib_Error.addError
( pError => 'The score of the home team has to be a number between %0 and %1'
, pColumnName => 'HOME_SCORE'
, pRow => i
, p0 => vMin
, p1 => vMax
);
END IF;
IF ApexLib_TabForm.NV('VISIT_SCORE', i) NOT BETWEEN vMin AND vMax
THEN
ApexLib_Error.addError
( pError => 'The score of the visit team has to be a number between %0 and %1'
, pColumnName => 'VISIT_SCORE'
, pRow => i
, p0 => vMin
, p1 => vMax
);
END IF;
END IF;
END LOOP;
RETURN ApexLib_Error.getErrorStack;
END;

* Update 30-Dec:

If you specify a format mask for your text field, the error is as expected. In my case I had to specify for HOME_SCORE and VISIT_SCORE format mask 90.

2 comments:

  1. Hi Dimitri,

    great that you have integrated it!

    About the "check also if there's a number as value". Have you defined a format mask, eg 90 for the number column? Because the date/number check is detected based on the format mask. If no format mask is set I assume it's a varchar2.

    BTW, your posting shows as 28-Dec, but showed up today on google reader. I assume you have hit this annoying blogspot bug that the draft date is used for the final posting :-(

    Great to see ApexLib in the first public APEX application. :-)

    Have a happy new year!
    Patrick

    ReplyDelete
  2. Hi Patrick,

    Yep, I started the post on 28-Dec, but only finished it today...

    And you're correct, I didn't have a format mask, I included it and now it works like I expected.

    I'll update the post.

    Thanks and happy new year too ;-)
    Dimitri

    ReplyDelete