cancel
Showing results for 
Search instead for 
Did you mean: 

MVC Drop Down List Event Handler

Former Member
0 Kudos

Hello,

I am trying to create a bsp page using MVC design pattern. I have 3 drop down list fields which are dependent on each other. Example: When you select a value in list 1, drop down list 2 becomes enabled for selection with values based on list 1. At this point of time list 3 should be disabled. Once you select value from 2, list 3 becomes enabled with values based on list 2 selection.

I have seen a webblog on this topic from Raja but it was designed for bsp page flow design. Could you please guide how do I achieve this in MVC?

Please help.

This is what I did:

I have 1 controller and 1 view.

In my view:

=========================================================

<htmlb:gridLayoutCell columnIndex="2" rowIndex="1">

<htmlb:dropdownListBox id = "DDLB_PLANT"

tooltip = "Plant"

table = "<%= v_plants %>"

onSelect = "DDLB_PLANTEvent"

selection = "<%= v_plantsel %>">

nameOfKeyColumn = "WERKS"

nameOfValueColumn= "DESC_TEXT">

</htmlb:dropdownListBox>

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell columnIndex="2" rowIndex="2">

<htmlb:dropdownListBox id = "DDLB_SHIFT"

tooltip = "Shift"

table = "<%= v_shifts %>"

onSelect = "DDLB_SHIFTEvent"

selection = "<%= v_shiftsel %>">

nameOfKeyColumn = "SHIFT"

nameOfValueColumn= "SDESC">

</htmlb:dropdownListBox>

</htmlb:gridLayoutCell>

where v_plants and v_shifts are page attributes (table) that is being populated in DO_REQUEST method of controller. v_plantsel and v_shiftsel are type string (page attribute).

In DO_HANDLE_EVENT (controller)

DATA: event_id TYPE REF TO if_htmlb_data,

ddlb_event TYPE REF TO cl_htmlb_event_selection,

data TYPE REF TO cl_htmlb_dropdownlistbox.

event_id = cl_htmlb_manager=>get_event( request ).

IF event_id IS NOT INITIAL.

ddlb_event ?= event_id.

IF ddlb_event->id EQ 'DDLB_PLANTEvent'.

c_plantsel = ddlb_event->selection.

ELSEIF ddlb_event->id EQ 'DDLB_SHIFTEvent'.

c_shiftsel = ddlb_event->selection.

CLEAR data.

data ?= cl_htmlb_manager=>get_data( request = runtime->server->request

name = 'dropdownListBox'

id = 'DDLB_PLANTEvent'

).

IF data IS NOT INITIAL.

c_plantsel = data->selection.

ENDIF.

ENDIF.

ENDIF.

=========================================================

Thanks,

Partho

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

I though I was able to bind my dropdown return value but this is the error I am getting:

"Field symbol has not yet been assigned"

Here is what I am doing:

Model

=====

  • populate plants

SELECT werks name1

FROM T001W

INTO TABLE M_PLANTS

order by name1.

where m_plants & m_plantcode has been defined as model attributes.

Controller

==========

DO_INIT

*create model instance

cmodelsetup ?= create_model( model_id = 'm'

class_name = 'ZPES_SETUP_MODEL' ).

if cmodelsetup is bound.

cmodelsetup->getplants( ).

endif.

DO_REQUEST

data: v_setupreview type ref to if_bsp_page.

dispatch_input( ).

if is_navigation_requested( ) is not initial.

return.

endif.

  • create view instance

v_setupreview = create_view( view_name = 'zsetupreview.htm').

v_setupreview->set_attribute( name = 'vmodelsetup' value = cmodelsetup ).

call_view( v_setupreview ).

View

====

<htmlb:gridLayoutCell columnIndex="1" rowIndex="1">

<htmlb:label for = "plant" text="Plant" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell columnIndex="2" rowIndex="1">

<htmlb:dropdownListBox id = "DDLB_PLANT"

tooltip = "Plant"

table = "//vmodelsetup/m_plants"

onSelect = "DDLB_PLANT"

selection = "//vmodelsetup/m_plantcode"

nameOfKeyColumn = "WERKS"

nameOfValueColumn= "DESC_TEXT">

</htmlb:dropdownListBox>

</htmlb:gridLayoutCell>

PLEASE HELP!!!

Thanks,

Partho

Former Member
0 Kudos

Hi Partho,

As you are using model's parameter in selection parameter, it will set the value of WERKS corresponding to the selected desc_text in the model's attribute 'c_plantsel'.

try this one:

In Do_Request() :

****Put your select qwery to populate the table 'v_plants'.

Append Initial line to v_plants.

clear model_instance_name->c_plantsel.

In Do_Handle_Event():

DATA: event_id TYPE REF TO if_htmlb_data,

ddlb_event TYPE REF TO cl_htmlb_event_selection,

event_id = cl_htmlb_manager=>get_event( request ).

IF event_id IS NOT INITIAL.

ddlb_event ?= event_id.

IF ddlb_event->id EQ 'DDLB_PLANTEvent'.

        • put here select query to populate your ****table 'v_shifts'.

****like

SELECT * FROM ztablename INTO TABLE v_shifts WHERE plant EQ model_instance_name->c_plantsel.

APPEND INITIAL LINE TO v_shifts.

CLEAR model_instance_name->c_shiftsel.

ENDIF.

ENDIF.

Now see, as you have appended an initail line to table v_shifts and the selection attribute c_plantsell is cleared up in Do_Request, your dropdown oof plants will be having values but a blank line will be selected initially.

As you will select a value, it will set the attribute c_plantsel in the model automatically and the Do_Handle Event will populate your shifts dropdown.

I hope you will now be able to do it.

Regards,

Pragya

Former Member
0 Kudos

Ok, I got one part working. In the do_handle_event I am able to react accordingly and populate the other list boxes.

Now, a very basic question:

In my drop down list element:

<htmlb:dropdownListBox id = "DDLB_PLANT"

tooltip = "Plant"

table = "<%= v_plants %>"

onSelect = "DDLB_PLANT"

??? selection= "//vmodelpes/c_plantsel">

nameOfKeyColumn = "WERKS"

nameOfValueColumn= "DESC_TEXT">

</htmlb:dropdownListBox>

What should be the attribute/value for the selection?

I have passed the reference of my model instance to the view page attribute "vmodelpes" and I am saying selection= "//vmodelpes/c_plantsel"> where c_plantsel is an instance attribute of the model. How would you typically populate the selection parameter of the dropdown element?

Thanks

Former Member
0 Kudos

Hi Partho,

just try out the code below but first modify it with proper select statements.

In <b>DO_REQUEST</b> method of controller:

***populate v_plants by anappropriate select statement.

In <b>Do_Handle_Event</b> method:

DATA: event_id TYPE REF TO if_htmlb_data,

ddlb_event TYPE REF TO cl_htmlb_event_selection,

data TYPE REF TO cl_htmlb_dropdownlistbox.

event_id = cl_htmlb_manager=>get_event( request ).

IF event_id IS NOT INITIAL.

ddlb_event ?= event_id.

IF ddlb_event->id EQ 'DDLB_PLANTEvent'.

c_plantsel = ddlb_event->selection.

        • put here select query to populate your ****table 'v_shifts'.

****like select * from ztablename into table v_shifts ****where plant eq c_plantsel.

ELSEIF ddlb_event->id EQ 'DDLB_SHIFTEvent'.

c_shiftsel = ddlb_event->selection.

ENDIF.

ENDIF.

Now when your view will appear first time,It will be showing values only in 'DDLB_PLANT'.

When you will select a value,it will trigger event and the values will be populated in "DDLB_SHIFT".

In the same way you can handle the third dropdown also.

You also mentioned that you are having a problem in selection attribute. what is that?

Regards,

Pragya

Former Member
0 Kudos

I just can't make it work.

Could you please provide me a sample code:

2 list boxes (drop down)

1 view 1 controller

code in:

DO INIT

DO REQUEST

DO HANDLE EVENT

Also, the selection attribute in dropdownlistbox is causing me problem. I have a table (code, desc_text) and I am saying:

<htmlb:dropdownListBox id = "DDLB_PLANT"

tooltip = "Plant"

table = "<%= v_plants %>"

onSelect = "DDLB_PLANTEvent"

selection = "<%= v_plantsel %>">

nameOfKeyColumn = "CODE"

nameOfValueColumn= "DESC_TEXT">

where v_plantsel is defined as type CODE .

Please help.

Former Member
0 Kudos

Hi Partho,

What you can do is...

In Do_Request(), do not fill all three tables.

Just populate v_plants with the values.

In Do_Handle_Event(), you can populate the v_shifts table on the bases of the selected value in v_plants.

Hope this will help you,

pragya