Hello, in this video I will talk about bind variables and I will show you how you can sit and create this point variables I created a publication. So, now let us try to set some bind variables in the view and see how it will work for example, in the in believe you I need to set point I need to create point variable in the main query as I said in previous video point variable can be created in the main query or in the view criteria. So, let's start with the main query. Okay, so I need to create a view object and in this view object I need to set the department ID and I will need to get the employee for from this department ID. So I will right here we are where the movie department ID equal to defined by new variable race this column and write that bind variable name like the ID okay.
So, sorry, this is here it will ask you if you want to create bind variable for this of type, what what type if you want would you want okay it's string okay. So it will create here, a bind variable for this mean view object. This department ID for example, we need been the ones that login user wants as a user logged into the system. I will check what is the department ID sis user belongs to. And I need the employee view object to be always filtered depending on the user department. In that case, I need the mean in believe you object to the filter Start by department ID.
So in the mean we're close, I said where department ID equal column and the binding variable name. And here in the bind variables, we defined the same name, which we use it here of type string. Okay, that's fine. So, how we can set this point variables, as I said, there are multiple ways we can you can do this, I will show you two ways now, which is most commonly ways we can use. First first method is, first way is to use groovy expression which will point to method in the Java class. Here, once you select the department, this also is a bind variable, you can add a literal value literal value, like this would be fixed like 10.
Okay, but we don't want to either fix it very, very value. We need to be dynamic Sometimes user will send it. So, how we can do this first we need to create plus in the model layer and in this class, I should write a method, this method will return the department ID. And from here in this exhibition I will point to this method. So, let us now try to create a class. So, in your mean mode in your model you should create a Java class for example, I will call it model util okay and we can add a package called common for example, and okay so, now I am explain the way in which you can set a bind variable using groovy expression boy in two minutes method in a Java class.
So, now I create a Java class. And I need to write a method here, which returns a department ID. So this message should be public static method. So it will return a string because the bind variable department ID which we defined here is a type of string. So I need the method to return string value. And we can write get user dept, or ID.
This is like my method name. Okay, here, I need to get the department ID from the logged in user. So usually you will get it from the session scope, for example, so we can get it from session scope like it if we can import it. Okay. Don't get current Good session scope to get and write that session score key. So we can say, in user depth.
And we should because as string here we can write return. So this this method, actually, it will connect to the session scope. And we'll get the value of the key called user depth. So in the login, we should set this variable in the session scope with the user department ID. Okay, now I need this bind very bind to this method, how we can do this actually you should get it from the package dot class dot get in function name or method name. So, it should be something like this model just put it here dot more than you two don't get it dipped ID.
So, this is separation, which we will write it in supine variable to go into this method in this class. So, I will take it and go to here in the expression function, I will add it like this. This is one way so that you can sit somewhere bind variable from a missile in a Java class and of course here you can do an All you want you can connect to the database is using SQL you can get any view object you have and think is a very useful for it and you get the value. So, you can write your own business here to get the department ID and this department will be set the bind variable, but for now I need to get a valid value from the session scope because this is most commonly situation we always do as the ADF application. Okay, is it still one thing is missing okay.
So let us try now to run and see if we let's let's first try to create a bitch and this this way, we can call it user Emily's All we can create a login page. So lettuce here carry two pages user and Bill m UI and just assemble assemble the page, which will set a value in the session scope. Here for example, login and I will create a login if okay and you just need to go ahead Okay, so just two simple pitch is the login I just want to add a department ID as if the I will get it from the login user. But for now I just will add the in with test with one button and you can sit the session scope with a value which is a user will enter and we'll check so here I will add a button login and once a user receives this login, I need to set value in the session scope and navigate to the user in bV.
Okay, but I need as well to add empty guests and you also should in terms of department ID User It's okay. Enzo user, Louis, I just will drag him believe you. If you didn't sit the bind variable, the view will return Normal Table Table. Okay. Okay, so now, this is the table here I just want to create action So I would create been and I would create login action cancel it, it's a double check here action should be like this Okay. So now we need to get the value from this and put it in the session scopes then going to this user ID actually we can do it without any code but I most of the things which I will do during this course to to show you how you can do everything programmatic.
So here I will go for buying think and I will add a component called user and bought tickets. Okay, so let's go to the pin here and we will get the IP ID equal in user dipped in tickets to get a value and from here we should put this value into the session scope thickest okay so we will import this Just faked tickets okay. His trophies will take us to get current nice 10 get an external take his session map put I will put system ID to what is the variable name or session variable name we will use the same what we use it here. So, I will put this department ID onto this session scope variable and in the model return model util I will return the value from this variable. Okay after that I will need to To return the M to go to the other pitch of course, this m is a outcome here it should be.
So, should be here like this, okay. So let's now try to run and see if there is any problem or not runs a login. Yes, see this is what I am. I need to tell you about it. You will find this error when you try to bind bind variables To the missile in the back beam. So, to solve this out you go to the bind variable here you find trans expression is a property you will find here trust mode, you can right here trust it, okay.
So let's run again okay. So this is drawn. So now we let us enter the user department for example, let us enter 20 and login you will find here the employee is filtered by 20. So, let us try to enter any other department and see, for example, it was in 30 years and 30 Logan it will get St. Louis from 30. So this is one way that you can sit is a bind variable from method in Java class using groovy expression you can point to this method. But as I told you to do this in the bind variable it says you should trust more to be trusted.
Otherwise you will get an exception. This is one way of doing that. Next video I will show you another way to sit so bind variable. So see you in activity