Skip to Content
avatar image
Former Member

Data binding doesn't work with dynamic indices

Hi all,

I have got a problem with data binding and can't think of a way to fix it. My code looks like the following:

...

Although the string for databinding looks good, it doesn't work! The string (e.g. //model/MT_MTRRA[1].readingresult) is simply shown as input in the input field.

When hard-coding the index:

...

value="//model/MT_MTRRA[1].readingresult"

...

data binding works, but a hard-coded index is of course not what I want. Using a table view instead is not an option, because the structure to be edited is too complex for that.

Any suggestions?

Thanks!

Stephan

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Oct 24, 2003 at 04:57 PM

    Hallo Stephan,

    It is always the simple questions that have the most complex answers.

    The reason for this "problem" is that you are using the model binding outside the scope of its design. For each attribute of a tag, there is usually a corresponding attribute on that class. So the code "<htmlb:inputfield id=abc>" will result that somewhere in the generated code there will be a statement "obj_inputfield->id = 'abc'.".

    However, for all attributes that are defined as model binding capable, there are **two** attributes. The one attribute is the actual value (which does NOT have to be of type STRING), and the second attribute for the model string (which MUST be of type STRING). This second attribute will always have the name _value.

    So now, during the compiler run, correct coding must be generated to fill either value or _value. And this is the reason why dynamic expressions (strings that are only known at runtime), can not be used for model binding. Already at compile time we require these values. (OK, you can argue that this first part of the string is already constant, but this compiler sees the complete string as expression and can not work with it.)

    I will offer you here a workaround. This is coding that we do officially support, and is the technique how you can dynamically program tags. (I am actually writing a weblog about this at the moment.) I give you the answer, and think that the some code will speak for itself :). For the rest, I would appreciate it if you could wait for my next weblog.

    <%--

    <htmlb:inputField id="READINGRESULT<%= l_cstr %>"

    value="//model/MT_MTRRA[<%= l_cstr %>].readingresult" />

    --%>

    <%

    data: inputfield TYPE REF TO CL_HTMLB_INPUTFIELD.

    inputfield = CL_HTMLB_INPUTFIELD=>FACTORY( id = 'READINGRESULT'

    id_postfix = l_cstr

    disabled = 'TRUE' ).

    CONCATENATE '//model/MT_MTRRA[' l_cstr '].readingresult' INTO inputfield->_value.

    %>

    <bsp:bee bee = "<%=inputfield%>" />

    regards, brian

    Add comment
    10|10000 characters needed characters exceeded