Let’s see how to make use of the download and upload components in this section. We will upload a file to show it on the browser and then change contents of the file and download it.
Upload Screen which leads to…Download Screen
Download Screen which goes back to…Upload screen
Context for Component controller
In the init of the component controller we will initiate the used components and get reference to the respective assistance class. For the download component we fill the file node with the file name and mime type.
Events handler
METHOD wddoinit . * Download component lo_cmp_usage = wd_this->wd_cpuse_download_file( ). lo_cmp_usage->create_component( ). lo_ziwci_wdrc_download_file = wd_this->wd_cpifc_download_file( ). wd_this->o_model_download = lo_ziwci_wdrc_download_file->get_model( ). * Give file name and specify mime type * navigate from <CONTEXT> to <FILE> via lead selection lo_nd_file = wd_context->get_child_node( name = wd_this->wdctx_file ). * get element via lead selection lo_el_file = lo_nd_file->get_element( ). ls_file-filename = 'up_down_text.txt'. ls_file-mimetype = 'Text'. * set all declared attributes lo_el_file->set_static_attributes( EXPORTING static_attributes = ls_file ). * Upload component lo_cmp_usage = wd_this->wd_cpuse_upload_file( ). lo_cmp_usage->create_component( ). lo_ziwci_wdrc_upload_file = wd_this->wd_cpifc_upload_file( ). wd_this->o_model_upload = lo_ziwci_wdrc_upload_file->get_model( ).
Upload event handler reads the data by calling the assistance class method get_mapped_file and binds the node table_data to the returned table.
Download event handler does a bit more than upload event catcher. It has to convert the data in the node table_data into file structure. It does that by calling the method covert_struc2file in the assistance class. Once the conversion is done then call the interface method download_file of download WD component that will push the file out of the browser.
METHOD catch_upload . wd_this->o_model_upload->get_mapped_file( IMPORTING e_t_mapped_file = lt_data ). * navigate from <CONTEXT> to <TABLE_DATA> via lead selection lo_nd_table_data = wd_context->get_child_node( name = wd_this->wdctx_table_data ). lo_nd_table_data->bind_table( EXPORTING new_items = lt_data ).
The views are simple, they just have a view container to display the component WD and a table element to display edit. There is also button to navigate between the views.
METHOD catch_download . * navigate from <CONTEXT> to <TABLE_DATA> via lead selection lo_nd_table_data = wd_context->get_child_node( name = wd_this->wdctx_table_data ). * @TODO handle not set lead selection * Get table data lo_nd_table_data->get_static_attributes_table( IMPORTING table = lt_data ). * Send data to be converted TRY . wd_this->o_model_download->convert_struc2file( EXPORTING i_t_data = lt_data i_seperator = cl_abap_char_utilities=>horizontal_tab i_flag_header = abap_true ). CATCH zcx_library. * get message manager lo_api_controller ?= wd_this->wd_get_api( ). lo_message_manager = lo_api_controller->get_message_manager( ). * report message lo_message_manager->report_error_message( message_text = 'Error in conversion' ). * Start download lo_interfacecontroller = wd_this->wd_cpifc_download_file( ). lo_interfacecontroller->download_file( ).
Upload view