BSP / HowTo: Exploring BSP Development with MVC 2b_1
-
Create pointer to model<br>
model ?= get_model( ‘mf’ ).
clear lt_data.
lt_data = model->GET_FAQ_CAT( ).
if selectedRowIndex IS INITIAL.
selectedRowIndex = -1.
endif.
-
Data definitions<br>
data: default_view type ref to if_bsp_page.
-
Create view<br>
default_view = create_view( view_name = ‘obj/cat.htm’ ).
default_view->set_attribute( name = ‘lv_data’
value = lt_data ).
default_view->set_attribute( name = ‘iterator’
value = me ).
default_view->set_attribute( name = ‘sri’
value = selectedRowIndex ).
default_view->set_attribute( name = ‘lv_desc’
value = lt_desc ).
default_view->set_attribute( name = ‘lv_id’
value = lt_id ).
default_view->set_attribute( name = ‘lv_name’
value = lt_name ).
default_view->set_attribute( name = ‘lv_src’
value = lt_src ).
default_view->set_attribute( name = ‘lv_edit’
value = lt_edit ).
-
Call view<br>
call_view( default_view ).
endmethod.
|
DO_HANDLE_EVENT |
> |
-
Table Types<br>
data: wa TYPE ZFAQ_CAT.
-
Object definitions<br>
data: lt_event TYPE REF TO if_htmlb_data.
method DO_REQUEST .
-
Create pointer to model
model ?= get_model( ‘mf’ ).
clear lt_data.
lt_data = model->GET_FAQ_CAT( ).
if selectedRowIndex IS INITIAL.
selectedRowIndex = -1.
endif.
-
Data definitions
data: default_view type ref to if_bsp_page.
-
Create view
default_view = create_view( view_name = ‘obj/cat.htm’ ).
default_view->set_attribute( name = ‘lv_data’
value = lt_data ).
default_view->set_attribute( name = ‘iterator’
value = me ).
default_view->set_attribute( name = ‘sri’
value = selectedRowIndex ).
default_view->set_attribute( name = ‘lv_desc’
value = lt_desc ).
default_view->set_attribute( name = ‘lv_id’
value = lt_id ).
default_view->set_attribute( name = ‘lv_name’
value = lt_name ).
default_view->set_attribute( name = ‘lv_src’
value = lt_src ).
default_view->set_attribute( name = ‘lv_edit’
value = lt_edit ).
-
Call view
call_view( default_view ).
endmethod.
method DO_HANDLE_EVENT .
-
Table Types
data: wa TYPE ZFAQ_CAT.
-
Object definitions
data: lt_event TYPE REF TO if_htmlb_data.
data: table TYPE REF TO CL_HTMLB_TABLEVIEW.
data: table_event TYPE REF TO cl_htmlb_event_tableview.
lt_event = cl_htmlb_manager=>get_event_ex( request ).
if lt_event IS NOT INITIAL.
table ?= CL_HTMLB_MANAGER=>GET_DATA( request = request
name = ‘tableView’
id = ‘cat_cattable’ ).
if table IS NOT INITIAL.
table_event = table->data.
selectedRowIndex = table_event->SELECTEDROWINDEX.
READ TABLE lt_data INTO wa index selectedRowIndex.
lt_id = wa-id.
lt_desc = wa-cat_desc.
lt_name = wa-name.
lt_src = wa-src.
endif.
CASE event.
WHEN ‘del’.
IF selectedRowIndex NE 0.
DELETE FROM ZFAQ_CAT WHERE ID = lt_id.
selectedRowIndex = 0.
lt_data = model->GET_FAQ_CAT( ).
lt_edit = ”.
SELECTEDROWINDEX = -1.
ENDIF.
WHEN ‘edit’.
IF selectedRowIndex NE 0.
lt_edit = ‘X’.
ENDIF.
WHEN ‘add’.
CLEAR wa.
IF request->GET_FORM_FIELD( name = ‘cat_id’ ) IS NOT INITIAL.
wa-ID = request->GET_FORM_FIELD( name = ‘cat_id’ ).
wa-NAME = request->GET_FORM_FIELD( name = ‘cat_name’ ).
wa-SRC = request->GET_FORM_FIELD( name = ‘cat_src’ ).
wa-CAT_DESC = request->GET_FORM_FIELD( name = ‘cat_desc’ ).
UPDATE ZFAQ_CAT FROM wa.
lt_data = model->GET_FAQ_CAT( ).
ELSE.
“* Assign automatic ID for the next DATA entry
wa-ID = model->GET_NEXT_DATA_ID( table = ‘ZFAQ_CAT’ ).
wa-NAME = request->GET_FORM_FIELD( name = ‘cat_name’ ).
wa-SRC = request->GET_FORM_FIELD( name = ‘cat_src’ ).
wa-CAT_DESC = request->GET_FORM_FIELD( name = ‘cat_desc’ ).
INSERT INTO ZFAQ_CAT VALUES wa.
lt_data = model->GET_FAQ_CAT( ).
ENDIF.
lt_edit = ”.
ENDCASE.
endif.
endmethod.
Fingers cramping yet? So moving on…
ZFAQ_C_CL_SUBJECT
ZFAQ_C_CL_SDNLINKS
The nice thing about these classes are that they are not much differnt than the one we just made. So let’s save ourselves some time and just copy it to the new names, then we’ll go through and clean it up a bit.
Have your two copies made now? OK, then let’s look and see what is different and make some changes.
ZFAQ_C_CL_SUBJECT
LT_SRC
You can remove it from the
Attributes
as we don’t need that one, then in the
DO_REQUEST
you can remove the line where we assign the value of
LT_SRC
to the
default_view
and modify the line where we assign data to
LT_DATA
you will need to use the method
lt_data = model->GET_FAQ_SUBJECT( )
. Also
highly
important is to change the line in
DO_REQUEST
to default_view = create_view( view_name = ‘obj/subject.htm’ ).
Then under
Method
the IF_HTMLB_TABLEVIEW_ITERATORRENDER_CELL_START</b>, remove all the code from there, however, do not “undefine it” just remove the code. This of course leaves us with the <b>DO_HANDLE_EVENT</b> and <b>IF_HTMLB_TABLEVIEW_ITERATORGET_COLUMN_DEFINITIONS
-
Table Types<br>
data: wa TYPE ZFAQ_SUBJECT.
-
Object definitions<br>
data: lt_event TYPE REF TO if_htmlb_data.
method DO_HANDLE_EVENT .
-
Table Types
data: wa TYPE ZFAQ_SUBJECT.
-
Object definitions
data: lt_event TYPE REF TO if_htmlb_data.
data: table TYPE REF TO CL_HTMLB_TABLEVIEW.
data: table_event TYPE REF TO cl_htmlb_event_tableview.
lt_event = cl_htmlb_manager=>get_event_ex( request ).
if lt_event IS NOT INITIAL.
table ?= CL_HTMLB_MANAGER=>GET_DATA( request = request
name = ‘tableView’
id = ‘subject_subjecttable’ ).
if table IS NOT INITIAL.
table_event = table->data.
selectedRowIndex = table_event->SELECTEDROWINDEX.
READ TABLE lt_data INTO wa index selectedRowIndex.
lt_id = wa-id.
lt_desc = wa-subject_desc.
lt_name = wa-name.
endif.
CASE event.
WHEN ‘del’.
IF selectedRowIndex NE 0.
DELETE FROM ZFAQ_SUBJECT WHERE ID = lt_id.
selectedRowIndex = 0.
lt_data = model->GET_FAQ_SUBJECT( ).
lt_edit = ”.
SELECTEDROWINDEX = -1.
ENDIF.
WHEN ‘edit’.
IF selectedRowIndex NE 0.
lt_edit = ‘X’.
ENDIF.
WHEN ‘add’.
CLEAR wa.
IF request->GET_FORM_FIELD( name = ‘subject_id’ ) IS NOT
INITIAL.
wa-ID = request->GET_FORM_FIELD( name = ‘subject_id’ ).
wa-NAME = request->GET_FORM_FIELD( name = ‘subject_name’ ).
wa-SUBJECT_DESC = request->GET_FORM_FIELD( name =
‘subject_desc’ ).
UPDATE ZFAQ_SUBJECT FROM wa.
lt_data = model->GET_FAQ_SUBJECT( ).
ELSE.
“* Assign automatic ID for the next DATA entry
wa-ID = model->GET_NEXT_DATA_ID( table = ‘ZFAQ_SUBJECT’ ).
wa-NAME = request->GET_FORM_FIELD( name = ‘subject_name’ ).
wa-SUBJECT_DESC = request->GET_FORM_FIELD( name =
‘subject_desc’ ).
INSERT INTO ZFAQ_SUBJECT VALUES wa.
lt_data = model->GET_FAQ_SUBJECT( ).
ENDIF.
lt_edit = ”.
ENDCASE.
endif.
endmethod.
ZFAQ_C_CL_SDNLINKS
LT_SRC
You can remove it from the
Attributes
as we don’t need that one, then in the
DO_REQUEST
you can remove the line where we assign the value of
LT_SRC
to the
default_view
and modify the line where we assign data to
LT_DATA
you will need to use the method
lt_data = model->GET_FAQ_RSSLINKS( )
. Now a bit differnt to the last as well we are going to change
LT_DESC
to
LT_LINK
. So change it under
Attributes
and then in
DO_REQUEST
as well. Also
highly
important is to change the line in
DO_REQUEST
to default_view = create_view( view_name = ‘obj/sdnlinks.htm’ ).
Then under
Method
the IF_HTMLB_TABLEVIEW_ITERATORRENDER_CELL_START</b>, remove all the code from there, however, do not “undefine it” just remove the code. This of course leaves us with the <b>DO_HANDLE_EVENT</b> and <b>IF_HTMLB_TABLEVIEW_ITERATORGET_COLUMN_DEFINITIONS
-
Table Types<br>
data: wa TYPE ZFAQ_SDNRSSLINK.
-
Object definitions<br>
data: lt_event TYPE REF TO if_htmlb_data.
method DO_HANDLE_EVENT .
-
Table Types
data: wa TYPE ZFAQ_SDNRSSLINK.
-
Object definitions
data: lt_event TYPE REF TO if_htmlb_data.
data: table TYPE REF TO CL_HTMLB_TABLEVIEW.
data: table_event TYPE REF TO cl_htmlb_event_tableview.
lt_event = cl_htmlb_manager=>get_event_ex( request ).
if lt_event IS NOT INITIAL.
table ?= CL_HTMLB_MANAGER=>GET_DATA( request = request
name = ‘tableView’
id = ‘sdnlinks_sdnlinkstable’ ).
if table IS NOT INITIAL.
table_event = table->data.
selectedRowIndex = table_event->SELECTEDROWINDEX.
READ TABLE lt_data INTO wa index selectedRowIndex.
lt_id = wa-id.
lt_link = wa-link.
lt_name = wa-name.
endif.
CASE event.
WHEN ‘del’.
IF selectedRowIndex NE 0.
DELETE FROM ZFAQ_SDNRSSLINK WHERE ID = lt_id.
selectedRowIndex = 0.
lt_data = model->GET_FAQ_RSSLINKS( ).
lt_edit = ”.
SELECTEDROWINDEX = -1.
ENDIF.
WHEN ‘edit’.
IF selectedRowIndex NE 0.
lt_edit = ‘X’.
ENDIF.
WHEN ‘add’.
CLEAR wa.
IF request->GET_FORM_FIELD( name = ‘sdnlinks_id’ ) IS NOT
INITIAL.
wa-ID = request->GET_FORM_FIELD( name = ‘sdnlinks_id’ ).
wa-NAME = request->GET_FORM_FIELD( name = ‘sdnlinks_name’ ).
wa-LINK = request->GET_FORM_FIELD( name =
‘sdnlinks_link’ ).
UPDATE ZFAQ_SDNRSSLINK FROM wa.
lt_data = model->GET_FAQ_RSSLINKS( ).
ELSE.
“* Assign automatic ID for the next DATA entry
wa-ID = model->GET_NEXT_DATA_ID( table = ‘ZFAQ_SDNRSSLINK’ ).
wa-NAME = request->GET_FORM_FIELD( name = ‘sdnlinks_name’ ).
wa-LINK = request->GET_FORM_FIELD( name =
‘sdnlinks_link’ ).
INSERT INTO ZFAQ_SDNRSSLINK VALUES wa.
lt_data = model->GET_FAQ_RSSLINKS( ).
ENDIF.
lt_edit = ”.
ENDCASE.
endif.
endmethod.
Each of these controllers will handle all of our setup and configuration tasks that we will associate with this application.