cancel
Showing results for 
Search instead for 
Did you mean: 

MVC Data binding problem

Former Member
0 Kudos

Hi @all,

I would like to develop a dynamic/generic BSP extension for an inputField. Now i have the following Problem. I have a view with a number of parameters. The model instance of the calling BSP is also passed as an attribute to my view. Now the view simply contains an InputField:

<htmlb:inputField id="<%=vh_id%>"

type="string"

visible="true"

disabled="false"

value="//model/client.clientno"

maxlength="<%=vh_width%>"

size="<%=vh_width%>" />

If I call it like this the InputField is filled with the value of //model/client.clientno. Now I would like to parametrize the value Attribute too:

<htmlb:inputField id="<%=vh_id%>"

type="string"

visible="true"

disabled="false"

value="<%=vh_value%>"

maxlength="<%=vh_width%>"

size="<%=vh_width%>" />

Now if I pass "//model/client.clientno" as vh_value in the call of my BSP-Extension:

<bsp:parameter name="vh_value" value="//model/client.clientno" />

it doesn't fill in the value but it simply writes "//model/client.clientno" (without the quotation marks) into the input field.

I know there is a workaround like this:

<bsp:parameter name="vh_value" value="<%=model->client-clientno%>" />

But with this the workaround if I change the value of my InputField in the browser the changed value is never returned to the model.

any ideas?

thx in advance,

Stefan

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member689397
Active Participant
0 Kudos

Hi Stefan,

How to create dynamic input field in MVC method?pls..help me..

Thnx .sun

Message was edited by: Sun

former_member181879
Active Contributor
0 Kudos

Stefan,

The problem is actually complex.

When the compiler sees a tag, it generates code to execute it.


<u><b>The BSP compiler sees:</b></u>
<tag:element a1 = "v1"/>
<u><b>It generates code::</b></u>
DATA: _t1 TYPE REF TO CL_TAG_ELEMENT.
CREATE OBJECT _t1.
_t1->a1 = 'v1'.
...code to execute tag...

The problem is now what happens if the attribute is of type integer, or of type ref to data, and we have model binding. Then it is not possible to place the binding string inside the attribute (not matching types). So for this reason, once model binding is set for a specific attribute, there are configured two attributes. The one is of the configured type, the other (prefixed with _) is of type string for the binding path. Only one is set.


<u><b>The BSP compiler sees:</b></u>
<tag:element a1 = "//model/m1"/>
<u><b>It generates code::</b></u>
DATA: _t1 TYPE REF TO CL_TAG_ELEMENT.
CREATE OBJECT _t1.
_t1-><b>_</b>a1 = '//model/m1'.
...code to execute tag...

So already from the beginning, the compiler must know whether it must set a1 or _a1. Model binding is pure compile time construct, and does not work at runtime. It is not possible to set this parameter dynamically.

The only possible way to achieve this, if you really insist, is to dynamically process the tag directly on the page. Then you must set the attributes yourself correctly.

For background reading information, I would recommend this new weblog:

<b>BSP Programming: Writing Composite Elements</b>

/people/brian.mckellar/blog/2004/07/28/bsp-programming-writing-composite-elements

The expected code will be about (if you really insist):


<%
    DATA: myTag TYPE REF TO CL_TAG_ELEMENT.
    myTag = CL_TAG_ELEMENT=>FACTORY( _a1 = vh_value ).
    WHILE _m_page_context->element_process( myTag )
             = if_bsp_element=>co_element_continue.
    ENDWHILE.
%>

++bcm

Former Member
0 Kudos

Thanks Brian,

that solved my problem.

Stefan

Former Member
0 Kudos

Hi Stefan,

if data binding does not work I would have a look in the controller method do_handle_data and set a breakpoint to check the values of "form_fields".

Here you can see how the form-fields are passed from the request and dispatched to the appropriate model-attrbs (fill_model_data( ) ).

If this does not bring any solution you can even have a look at dispatch_input() of your (main-)controller to check the correct dispatching to your component (comp_id) and its values.

Regards , Bernd

Regards, Bernd