Step 5. Complete the Image Command Handler
VFW080 – Using an Explorer Component
1. In the
view, drag and drop your Find Employee Image form (iiiVFW15) onto the Employee Image CH reusable part (iiiVFW16).This will create a Find_Image:
for iiiVFRW15. Select the tab and change the of iiiVFW15 toDefine_Com Class(#IIIVFW15) Name(#Find_Image) Componentversion(2)
2. An Instance List command handler is invoked by the Framework, when an entry is selected in the business object Instance list and its
method is invoked.Create the
method routine. This must redefine the method which is already defined in the ancestor VF_AC010. It should invoke the method in the ancestor.Your code should look like the following:
Mthroutine Name(uExecute) Options(*redefine)
#com_ancestor.uExecute
Endroutine
3. Your
logic, needs to do the following:a. Get the employee number for the current instance list entry
b. Fetch the employee image field (iiiEmpImg) from file iiiEmpImages
c. Set the image component filename property from the retrieved employee image
d. Handle a not found error, when the employee has no image.
Your new code should look like the following:
#avlistmanager.getCurrentInstance Akey1(#empno)
Fetch Fields(#iiiempimg) From_File(iiiEmpImages) With_Key(#empno) Val_Error(*next)
If_Status Is(*okay)
#IMGE_1.fileName := #iiiempimg.fileName
Else
#IMGE_1.fileName := *null
#IMGE_1.updateDisplay
Endif
4. The
button event, simply needs to invoke the image form, as a modal form.Your completed Find button
event should look like the following:Evtroutine Handling(#PHBN_FIND.Click)
#Find_Image.ShowModalForm
Endroutine
5. When an image is selected in the
form, the user will click the button. This will signal the event, passing the image path and filename.In the
command handler, add an event handling routine, which sets the image filename (IMGE_1.filename).Your code should look like the following:
Evtroutine Handling(#Find_Image.uImageSelected) Ufilename(#FileName)
#IMGE_1.fileName := #FileName
Endroutine
6. The
button routine, needs to do the following:a. Set the field value for iiiEmpImg to the image filename property
b. check for an existing entry in file iiiEmpImages
c. Update or Insert to the file iiiEmpImages as appropriate.
Your code should look like the following:
Evtroutine Handling(#PHBN_SAVE.Click)
#iiiempimg := #IMGE_1.fileName
Check_For In_File(iiiEmpImages) With_Key(#empno) Val_Error(*next)
If_Status Is(*equalkey)
Update Fields(#iiiempimg) In_File(iiiEmpImages) With_Key(#empno)
Else
Insert Fields(#empno #iiiempimg) To_File(iiiEmpImages)
Endif
Endroutine
7. Compile your command handler iiiVFW16.