cancel
Showing results for 
Search instead for 
Did you mean: 

Data is not Passing between the controller class and Model class

Former Member
0 Kudos

Hi All,

Im new to BSP, I created the controller class and model class for a application which will add two numbers and display the result.

Im giving the two numbers from the BSP page using <b>input field</b>.

I have no error in the application but the data is not passed from the BSP page for process but i got the result when i tried by hard coding the values.

Please guide me,

Thanks,

Sarath.C

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You have done Static Binding in your code.

<htmlb:inputField id = "value1"

value = "<%= model->value1 %>" />

So, you need to catch the value explicitly in do_handle_event.

Like this:

<i>DATA: data TYPE REF TO CL_HTMLB_INPUTFIELD.

data ?= CL_HTMLB_MANAGER=>GET_DATA( request = runtime->server-request

name = 'inputField'

id = 'value1' ).</i>

Or else, use Dynamic Binding in the Layout. Like this:

<htmlb:inputField id = "value1"

value = "//model/value1" />

Hope it helps!

Regards,

Kapali

Former Member
0 Kudos

Thank u very much Kapali, I got the answer.

DATA: data TYPE REF TO CL_HTMLB_INPUTFIELD.

data ?= CL_HTMLB_MANAGER=>GET_DATA( request = runtime->server-request

name = 'inputField'

id = 'value1' ).

The above gave me an error saying SERVER is an object reference and hence does not have a component called REQUEST.

but this solved my problem,

<htmlb:inputField id = "value1"

value = "//model/value1" />

Answers (5)

Answers (5)

Former Member
0 Kudos

Please paste the code of you have written in the "Layout" i.e. your BSP Page/View.

Regards,

Kapali

Former Member
0 Kudos

> Please paste the code of you have written in the

> "Layout" i.e. your BSP Page/View.

>

> Regards,

> Kapali

<%@page language="abap"%>

<%@extension name="htmlb" prefix="htmlb"%>

<htmlb:content design="design2003">

<htmlb:page title = "Main Page ">

<htmlb:form>

<htmlb:tray id = "tray1"

width ="100%" >

<center>

<htmlb:textView text = "ADDITION"

design = "EMPHASIZED" />

<br>

<htmlb:gridLayout id = "maingrid"

width = "70%"

cellSpacing = "2"

columnSize = "2"

rowSize = "4" >

<htmlb:gridLayoutCell

id = "cell11"

rowIndex = "1"

columnIndex = "1"

style = "TRANSPARENT">

<htmlb:textView text = "Enter First Value : "

design = "EMPHASIZED" />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell id = "cell12"

rowIndex = "1"

columnIndex = "2">

<htmlb:inputField id = "value1"

value = "<%= model->value1 %>" /> <br>

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell

id = "cell21"

rowIndex = "2"

columnIndex = "1"

style = "BORDER">

<htmlb:textView text = "Enter Second Value : " />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell id = "cell22"

rowIndex = "2"

columnIndex = "2">

<htmlb:inputField id = "value2"

value = "<%= model->value2 %>" />

</htmlb:gridLayoutCell>

<br><br>

<% if model->result is not initial. %>

<htmlb:gridLayoutCell id = "cell31"

rowIndex = "3"

columnIndex = "1" >

<htmlb:textView text = "The Result is : " />

</htmlb:gridLayoutCell>

<htmlb:gridLayoutCell id = "cell32"

rowIndex = "3"

columnIndex = "2" >

<htmlb:inputField id = "result"

value = "<%= model->result %>" />

</htmlb:gridLayoutCell>

<%endif.%>

<br><br>

<htmlb:gridLayoutCell id = "cell32"

rowIndex = "4"

columnIndex = "1"

horizontalAlignment = "RIGHT" >

<htmlb:button id = "addition"

text = "Add"

onClick = "add" />

</htmlb:gridLayoutCell>

</htmlb:gridLayout>

</htmlb:tray>

</htmlb:form>

</htmlb:page>

</htmlb:content>

Former Member
0 Kudos

Ok. Could you please paste your code from the layout then?

Regards,

Kapali

Former Member
0 Kudos

Here is the code,

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

method DO_INIT.

DATA: model TYPE REF TO zmodel_bsp_7936.

model ?= create_model( class_name = 'ZMODEL_BSP_7936'

model_id = 'model_main' ).

clear: model->value1,model->value2,model->result.

endmethod.

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

method DO_REQUEST.

DATA: main_view TYPE REF TO if_bsp_page,

model TYPE REF TO zmodel_bsp_7936.

dispatch_input( ).

model ?= get_model( 'model_main' ).

main_view = create_view( view_name = 'main.htm' ).

main_view->set_attribute( name = 'model' value = model ).

call_view( main_view ).

endmethod.

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

method DO_HANDLE_EVENT.

DATA: model TYPE REF TO ZMODEL_BSP_7936.

model ?= get_model( 'model_main' ).

IF htmlb_event->server_event = 'add'.

model->result = model->value1 + model->value2.

ENDIF.

endmethod.

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

Former Member
0 Kudos

Did u call dispatch_input( ) in your DO-REQUEST of the controller?

it should be the 1st statement of your do_request method.

Regards,

Kapali

Former Member
0 Kudos

Yes Kapali I have written the method after the declaration for the model class object in do_request..

Former Member
0 Kudos

I had similar problem. To me help when I set method (in controller and model) like public. The example which I saw before, had in controller private classes.

Former Member
0 Kudos

Change the BSP properties, Status to 'Stateful' application and try it.

Former Member
0 Kudos

HI,

I have created both the classes as PUBLIC class only, but the data is not passed from the screen level.

But when i change value in runtime in the DO_HANDLE_EVENT i get the output.

Former Member
0 Kudos

Hi Ramki,

I change the status to STATEFUL but the data is not passed yet.

Former Member
0 Kudos

Hi,

You need to catch the Input field values in your controller class method:

do_handle_data or

do_handle_request

and add them by using your model class method.

This code from F1 help might be helpful!

<i><i>DATA: data TYPE REF TO CL_HTMLB_INPUTFIELD.

data ?= CL_HTMLB_MANAGER=>GET_DATA( request = runtime->server-request

name = 'inputField'

id = 'myInputField1' ).</i></i>

Regards,

Kapali

Former Member
0 Kudos

Thanks for replying Kapali,

I tried wht u said but it throws an error saying

<b>SERVER</b> is an object reference and does not have any components called <b>REQUEST</b>

Former Member
0 Kudos

TRY This

DATA: data TYPE REF TO CL_HTMLB_INPUTFIELD.
data ?= CL_HTMLB_MANAGER=>GET_DATA( request = runtime->server->request
name = 'inputField'
id = 'myInputField1' ).

what kind of binding you are using for the variable on the view.. if you are using

<%=model->myinput %>

Try using

<%=//model/myvalue%>.

Cheers

Amandeep

Former Member
0 Kudos

Hi Kapali

Thanks for the reply,

But still im not getting it.

Its throwing an error saying that <b>//model/result</b> is unknown

Former Member
0 Kudos

Can you please paste the Code of you view you are haveing problems for and pls let us know whicjh field's binding is causing problem.

amandeep