Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Error management from Java side control  (Read 11076 times)
seb
Newbie
*
Posts: 8


View Profile Email
« on: January 30, 2009, 07:45:13 »

Hi,

I'm quite new to Puremvc and Flex and I'm trying to use Flex with an existing Java framework that we already developped and used. This framework only deals with the model part = accessing to the database for CRUD operations or validating when the user fills forms (eg the user pseudo may be unique and things like that...).
To access the model, the framework has Service objects (like USerService) and it returns a ServiceResponse object that can contain a List of Object (simple POJO) if everything is OK, or a List of ServiceError objects if there was errors (not Exceptions). This ServiceError object contains the error message, the name of the property that has an error (in the case of filling a form for instance), and the severity of the error.
In the Flex side, I have a ServiceResponse.as and a ServiceError.as classes linked to the ServiceResponse.java and the ServiceError.java.
What I would like to do, is linking the error message contained in the ServiceError object to the property in error and displaying errors like Flex Validators do this = the form input in error in a red square and a tooltip with the error message for example.
I was thinking to inspect the ServiceResponse to determine if errors exist and in this case to dispatch a ValidationResultEvent containing ValidationResult objects with the properties of my ServiceError objects. I think this could link the errors to the right property in error?
But.... with Puremvc where can/may I dispatch Events to the view part to imitate the Validator behavior?

As I'm quite new to Flex/Puremvc, I'm maybe completely wrong... Maybe there is another cleaner solution?

Thanks for your help and sorry for the long post!

Sebastien
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 02, 2009, 07:14:23 »

If you have already done the valdation in the server and have the error in question you don't have to trigger Flex validation. You can just set the 'errorString' prop of the component. The only problem is linking the fieldname with the message. The proxy would send a FIELD_ERROR note with the error message as the body and the fieldname as the type. Interested mediators would check to see if the type of the note (note.getType()) was one of the fields owned by their view components. The one mediator whose comp has that field would act by setting the field's errorString.
-=Cliff>
Logged
seb
Newbie
*
Posts: 8


View Profile Email
« Reply #2 on: February 03, 2009, 03:18:21 »

Thanks a lot Cliff

After trying a few possibilities a tried your solution and it's OK. But...
In the ServiceError object there are 2 interesting properties : "propertyName" and "errorMessage". What I'm now trying to do is to set the errorMessage of the TextInput that failed validation with the errorMessage of the ServiceError using the propertyName like this (inside the Mediator) :

case ApplicationFacade.USER_CREATE_FAILURE_NOTIFICATION:
   var errors:ArrayCollection = userBusinessProxy.errors;
   for (var i:int=0; i<errors.length; i++) {
      var err:ServiceError = errors;
      creationCompteUtilisateurView.(err.propertyName).errorString =                                            err.errorMessage;
   }
        break;

"creationCompteUtilisateurView" is the view component associated with this Mediator.

The red part of code doesn't work... there are no errors at compilation, but during execution I got "TypeError: Error #1123: Filter Operator not supported on type fr.gogaya.view.components.CreationCompteUtilisateur."

Is it just possible to do this? Accessing to a property of an Object from the name of this property that is given by the value of another object property?
If not, how can I do this?

Thanks for your help!

Sebastien
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: February 04, 2009, 10:05:32 »

try:

creationCompteUtilisateurView.[err.propertyName].errorString

although you'll probably have to cast:

UIComponent(creationCompteUtilisateurView.[err.propertyName]).errorString

-=Cliff>
Logged
seb
Newbie
*
Posts: 8


View Profile Email
« Reply #4 on: February 04, 2009, 01:02:02 »

Thanks Cliff,

I'm sorry but it seems it doesn't work...
I tried :
TextInput(creationCompteUtilisateurView.[err.propertyName]).errorString = err.errorMessage;
and :
UIComponent(creationCompteUtilisateurView.[err.propertyName]).errorString = err.errorMessage;

and I got compilation errors : something like "syntax error : identifier missing before leftbraket" (it's in french...) and "syntax error : rightparen missing before rightbrace"

Any idea?

Sebastien
Logged
seb
Newbie
*
Posts: 8


View Profile Email
« Reply #5 on: February 04, 2009, 03:25:01 »

OK, I have it! the correct syntax is :

TextInput(creationCompteUtilisateurView[err.propertyName]).errorString = err.errorMessage

and it works great!

Thanks for your help Cliff
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #6 on: February 05, 2009, 06:36:07 »

If you want to use the same code to set messages onto any control, you probably want to walk up the component hierarchy a bit and not use TextInput specifically.

For instance, the value entered into a NumericStepper could not be marked in error using this line. You want to cast to the class that defines the errorText property for all UI controls. I thought that was UIComponent, but it might be down the tree a bit if you tried it and it didn't work.

-=Cliff>
Logged
Pages: [1]
Print