cancel
Showing results for 
Search instead for 
Did you mean: 

Hard Coding the values

Former Member
0 Kudos

Hi,

i have one custom controller named EmployeeCust and one view named EmployeeView . I have to pass one Employee Number from the custom controller(EmployeeCust ) to the view EmployeeView .

Depending on the Employee Number which i hardcode and pass, the Employee Details will be displayed in the EmployeeView.

This i have to do for testing purpose .I have to take one test data (employee number ) . Later on after integration the Employee Data will be displayed dynamically.

Can anybody suggest me the code which i should write so that i can hardcode the values from the Custom Controller to the View .In my case the test data(employee number) is : 10112567 .

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Hardcoding is not generally a good practice,

Wat you can do is, create many contexts(value attributes) in the view & copy-paste the same in the custom controller.

The you can map those contexts between the view and the controller.

Now, i am assuming, you have a UI which allows the user to enter the employee number, and on entering the number, the employee details are displayed.

If that is the case, then OnAction of the login button or enter key, call a method which will set the values of the contexts.

You can set the values of a context using the following code:

wdcontext.currentcontextelement.set<context name>(<value>)

The code to call the method which will hardcode the values is:

1..If the method is in the view itself:

wdthis.<mehthod name>

2..If the method is in the custom controller:

wdThis.wdGet<controller name>.<method name>()(

You map the contexts of the view to the UI elements which u will use to display the employee details.

In the method, you can have a <i>if</i> statement, which will check if your entered entered employee number is equal to 10112567

If true, then set the context values,

If false, then display a error message saying that login failed or no employee with that number exists

I hope this helps,

Regards,

Hanoz

Former Member
0 Kudos

Hi Hanoz,

Thanks a lot for the reply . I have just one more question .

Inside the custom controller i have one method called getdisplay() value from where i have to pass the hard coded value to the EmployeeView .

So should i write the code inside the method as ,

wdThis.wdGetEmployeeCust.setEmployeeName("10112567 ");

The data binding and the context mapping from custom controller to the view has been done correctly .

Thanks.

Former Member
0 Kudos

Hi,

No you dont.

Let me explain:

When you are trying to access a method present in the controller, through the view, thats when you use:

wdThis.wdGetEmployeeCust.<mehtod name>

If you want to access the contexts(value attirbutes) present in a view, form the same view(implementation tab), OR, contexts present in a controller, from the same controller(implementation tab), then you use the following code:

wdcontext.currentcontextElement.<context name>

So, in your case, if you have a context <i>EmployeeName</i> in the controller <i>EmployeeCust</i>, and you want to set its value to 10112567, then use the following code:

wdcontext.currentcontextelement.setEmployeeName("10112567")

if the context is of type <i>string</i>

OR

wdcontext.currentcontextelement.setEmployeeName(10112567)

if the context is of type <i>integer</i>

I hope you have the same named context present in your view as well & that you have mapped these two contexts.

Let me know if you are still not clear, its pretty straightforward acutally..:-)

Regards,

Hanoz

Former Member
0 Kudos

Hi Hanoz,

Thanks a lot for the reply . My doubt is cleared now .

Former Member
0 Kudos

hii,,,

anytime pal....we have all been there, through the same problems..

Do keep posting the progress of your application, and feel free to ask if you have any further queries, its a learning process for us all.

Btw, thanx for the points, i appreciate the gesture.

Regards,

Hanoz

Answers (0)