Skip to Content
author's profile photo Former Member
Former Member

MVC data binding dynamically

Hi Friends,

I have a requirement in one of my MVC views. I have an <htmlb:inputField> and i want to associate it to my Model class attribute dynamically i.e. i have the fully typed model attribute in a string and i wish to assign it to the inputField's value. But, my efforts are in vain.

Here's my code:

<% concatenate '//model/structure.' tmp into substr. %>

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

value = "<%= substr %>" />

The 'tmp' has the name of the structure component in it. The code gets compiled but when i run it the inputField has the whole model string (substr) as text inside the input box and is not actually getting binded with the model. How can we dynamically do this ?

Please help.

Regards,

Ram.

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Nov 20, 2007 at 03:40 PM

    System will consider '//model/structure.' as the value. no way it can recogize this as the model binding. If you want to display the dynamically then you achieve as follows:

    <% substr = model->structure-field1. %>
    
    <htmlb:inputField id = "<%= tmp %>"
    value = "<%= substr %>" />

    This way, the substr will display the value of model attribute.

    Raja T

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Thilo Klopfer

      Thanks Thilo. Though not exactly the solution i needed, it surely guided me to find the right one.

      Raja/Patrick and Everyone,

      Luckily i found a relatively easy way to dynamically bind an htmlb element to a model attribute. Below code snippet says it all:

      <% data: input type ref to cl_htmlb_inputField,

      input_string type string.

      create object input.

      input->id = tmp.

      input->_value = '//model/structure.field'.

      input_string = input->if_bsp_bee~render_to_string( page_context ).

      %>

      <%= input_string %>

      By putting this code on the page layout, the htmlb:inputField is dynamically created and during this process the 'value' is binded to the string provided. Please go through the PDF file for more details: https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/72d7ac11-0501-0010-63a2-cc6960569926

      Thanks everyone,

      Ram.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.