cancel
Showing results for 
Search instead for 
Did you mean: 

Viewset - active view and data validation problem

Former Member
0 Kudos

Hey there,

I've a problem while using a viewset (1 col, 2 rows) and the data-validation in the wdDoBeforeAction() method.

My application works basically like this:

The first view is displayed with 2 mandatory input fields. Upon the evaluation result of the entered data in these fields, a corresponding second view will be displayed. The input fields in the first view are set to read only and a button named "Change" appears. This button triggers an action which fires and outbound-plug to an empty view, so that the second view disappears and resets the "read only" properties of the input fields in the first view, so that the user can enter new data.

The problem is, that the second view contains input fields itself, which are validated in the wdDoBeforeAction() method of this view. The navigation is cancelled if an error occurs. Well, this is fine if i want to submit (pressing the button "Approve" in the second view) this data and proceed, but if i want to go back to the first view (by hitting the "Change" button), i want to discard all information entered in the second view and i dont want this data to be validated. It's quite annoying if u just want to correct the first views data but have to enter correct values for the second view in order to get through the second views checks..

I hope that's clear enough, otherwise i will upload a screenshot to clarify.

Thx in advance

Regards

Pascal

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Pascal,

please tell me how you set up your context. Do you use a common context in the Component Conroller that is mapped to your views? If so, you could just delete the Context values when the change Button is pressed ...

This might be an option

Jan

Former Member
0 Kudos

Hey Jan,

I'm not sure if I understand you question correctly.

My context is set up like this:

--

View Controller of view 1 contains

Node1 - Attribute1 ID

- Attribute2 Profile

Attribute1 active (used as flag to set readonly)

--

View Controller of view 2 contains

Node1 - Attribute1 Startdate

- Attribute2 Enddate

--

Component controller contains

Node1 - Attribute1 ID

- Attribute2 Profile

- Attribute3 Startddate

- Attribute4 Enddate

--

The Attributes are bound to the corresponding UI Elements in the corresponding views.

But just for clarification: I've no problem with getting rid of the data or anything, it's really an UI Problem because I can't let the second view disappear without checking start- and enddate, even though its absolutely not required in this case (meaning getting back view 1).

Regards Pascal

Former Member
0 Kudos

Hi,

did you mark the Action that is triggered by the Change-Button as "non validating"? Should skip the automated validation process ...

jan

Former Member
0 Kudos

Hey Jan,

it is defined as non-validating, but it doesn't skipt the checks. Btw. I'm not talking about automated implied checks (like if in an integer field is really entered a number instead of a letter or so) but about checks i defined myself and which are executed in the above mentioned method. Just in case that makes any difference.

Regards

Pascal

Former Member
0 Kudos

ah, ok. post your coding inside doProcessBefore ... please then.

Former Member
0 Kudos

There is no doProcessBefore ...

Just in case u meant wdDoBeforeAction(), it goes like this:


// check of a mandatory field
wdThis.wdGetValidatorController().checkRequired(...);
// some more checks that are like this
// ...
// if an error occured while testing, raise the Exception
wdComponentAPI.getMessageManager().raisePendingException();

within the requiredCheck-Method (which is defined in the Custom Controller 'Validator'), the methods

reportContextAttributeMessage();

and cancelNavigation();

of the IWDMessageManager are called if the check fails.

Regards

Pascal

Edited by: Pascal Landau on Sep 7, 2009 5:17 PM

Edited by: Pascal Landau on Sep 7, 2009 5:22 PM

Former Member
0 Kudos

Hi

ok, I thin now I got you.

Why dont you just move the validating code to the action Handler that is used to continue, so it wont be called when you hit "change"?

Otherwise you could try to add Parameter-Mapping to the action, to determine which Button was klicked and use that information for a if/else statement.

Jan

Former Member
0 Kudos

Hey,

>

> Why dont you just move the validating code to the action Handler that is used to continue, so it wont be called when you hit "change"?

>

I thought that would be bad code style, because the wdDoBeforeAction should be responsible for data validation. Correct me if I'm wrong, I'm learning WD since 3 weeks

>

> Otherwise you could try to add Parameter-Mapping to the action, to determine which Button was klicked and use that information for a if/else statement.

>

Can I use this information in the wdDoBeforeAction? and if so, how can I get access to this information (sample code).

Former Member
0 Kudos

Hi,

The purpose of the method wdDoBeforeAction(IWDBeforeAction action) is to do some additional validations of user input before action is performed.

Yes it is responsible for data validation. But in your case, if it is submit to database - you need validations and if it is click on Change button to edit the values in View1 then u dont need validations.

So in one case u need to avoid validations and in another case you need validations.

Its not bad coding style or something. Becuase here u have different requrement for different actions.

And wdDoBeforeAction() is not capable of handling both of your requriements.

So in that case my suggestion is keep the validations in action event handlers insted of using wdDoBeforeAction().

Regards,

Charan

Former Member
0 Kudos

Hi Pascal,

although I wont prefer to do so for reasons of readability, you could use wdDoProcessbeforeAction to control your view-flow.

Take a look at the example, I have two Buttons with two actions, one is set on "Validate", the other is not (guess which on is the validating ).

You can get the action triggered inside the doBefore ... method and determine whether or not the checkbox is set.

So put your code to validate the input in the i(isValidting) branch and your problems are solved.

Keep in Mind: I would delegate the Validation from the view to the controller, handle the validation myself with custom coding and then check in the view controller if any errors occured.

hope that helped,

Jan


  //@@end
  public void wdDoBeforeAction(com.sap.tc.webdynpro.progmodel.api.IWDBeforeAction validation)
  {
    //@@begin wdDoBeforeAction
	  
	  

	  IWDAction currentAction = validation.getCurrentAction();
	  
	  if (currentAction == null) return;
	  
	  String action = currentAction.getText();
	  boolean isValidating = currentAction.isValidating();
	  
	  if (isValidating) {
		  wdComponentAPI.getMessageManager().reportException(action);
	  } else {

		  wdComponentAPI.getMessageManager().reportSuccess(action);
	  }
	  
	  
	  
    //@@end
  }

Edited by: Jan Galinski (Holisticon) on Sep 8, 2009 3:15 PM

Former Member
0 Kudos

Hey,

thx for your replies. Both solutions work fine.

I'm using Jan's proposal because in my opinion thats how to use all elements/methods as they are supposed to be. Otherwise the "validation" flag in an action would be kinda senseless, wouldnt it? Now I can keep all my validation in the wdDoBeforeAction() method and it's sufficient to mark the relevant actions as "validating" ones.

And there would be another disadvantage, if I had more than just 2 Actions. Lets assume there are 10 and 9 of them need the same check. Then I had to write this check in 9 different action-implementations - which is redundant and hard to maintain later on.

Keep in Mind: I would delegate the Validation from the view to the controller, handle the validation myself with custom coding and then check in the view controller if any errors occured.

Sry I don't get that, in WHICH controller would you perform the validation?

What do you mean with custom coding?

Regards

Pascal

Former Member
0 Kudos

Hi Pascal,

the "validate" flag at the action defintion also triggers the internal validation (date format, numbers, Dictionary types). So its not "useless".

Validation can be complicated, thats why I said "custom coding". Consider People entering a customers id, but validation requires more than just "field is filled" and "field contains numbers". Maybe you want to check if the company db contains the customer. Maybe you have to check permissions, bank data and so on.

So normally you use the "inside the view" validation only for very obvious details and then delegate (meaning: calling the Component Controller methods from inside the onAction method) the further processing and validation. You can still process all errors inside the view to report exceptions.

But lets keep it for now, just go with the solution provided and dig a bit deeper, I am positive you will understand what we mean when working with bigger examples. Even in the universe of WebDynpro there's not always just one way to do it.

and dont forget to mark thisquestion read since you found your solution.

cu

jan