on 01-13-2015 3:01 PM
Hello experts,
as I could not find a solution to my problem in the web, may I ask you for help.
I have built a small MVC test application. My view contains a htmlb:dropdownListBox, a button to submit and an inputField to display the selection. My problem: the selected value of this box is not transfered into the model attribute and the box does not keep the selected value when I click the submit-button. My understanding was, that the model is bound to the view so that the selected value should be transferred after submit to the model-attribute automatically. May be this is wrong. Could you help me to complete my coding?
Here the details for you:
--- Controllerclass ----
method do_init.
data: slistentry type ihttpnvp.
me->model ?= create_model( class_name = 'zcl_test_ddfeld_mo'
model_id = 'test_ddfeld_mo' ).
clear slistentry.
slistentry-value = 'Entry 1'.
slistentry-name = 'e1'.
append slistentry to me->model->dd_values.
slistentry-value = 'Entry 2'.
slistentry-name = 'e2'.
append slistentry to me->model->dd_values.
slistentry-value = 'Entry 3'.
slistentry-name = 'e3'.
append slistentry to me->model->dd_values.
endmethod.
method do_request.
data: view type ref to if_bsp_page.
dispatch_input( ).
view ?= create_view( view_name = 'default.htm' ).
view->set_attribute( name = 'model' value = me->model ).
call_view( view ).
endmethod.
method do_handle_event.
if htmlb_event_ex is bound.
case htmlb_event_ex->event_server_name.
when 'onClick_btn1'.
* Here further code will be implemented later
when others.
endcase.
endif.
endmethod.
Attributes:
MODEL as Ref to my modelclass
--- Modelclass ----
Attributes:
SELECTED_VALUE type string.
DD_VALUES type TIHTTPNVP. "Filled in Controller Do_init
--- View ----
<%@page language="abap"%>
<%@extension name="htmlb" prefix="htmlb"%>
<htmlb:content design="design2003">
<htmlb:page title = "Startseite ">
<htmlb:form>
<htmlb:button text = "Submit"
onClick = "onClick_btn1" />
<htmlb:dropdownListBox id = "dd_list1"
nameOfKeyColumn = "name"
nameOfValueColumn = "value"
table = "//model/dd_values"
selection = "//model/selected_value" />
<htmlb:inputField id = "inf_selected"
value = "//model/selected_value"
disabled = "true" />
</htmlb:form>
</htmlb:page>
</htmlb:content>
Pageattributes:
MODEL as Ref to my modelclass
You can pull the value out of the form fields:
METHOD do_handle_event.
...
DATA: thisevent TYPE REF TO cl_htmlb_event.
DATA: formfields TYPE tihttpnvp.
DATA: wa_formfields TYPE ihttpnvp.
...
IF html_event IS BOUND.
thisevent = cl_htmlb_manager=>get_event( request ).
...
WHEN 'dd_list1'.
CALL METHOD request->get_form_fields
CHANGING
fields = formfields.
IF thisevent IS NOT INITIAL AND thisevent->server_event = 'dd_list1'.
READ TABLE formfields INTO wa_formfields
WITH KEY name = 'model_selected_value'.
model->selected_value = wa_formfields-value.
ENDIF.
...
----------------------------
.html:
<htmlb:dropdownListBox id = "dd_list1"
onSelect = "dd_list1"
...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.