on 11-20-2007 2:51 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raja,
Thanks for the reply. But, my requirement is that i am iterating through a loop and creating a htmlb:inputField for each iteration dynamically. During this creation process, i want to attach this inputField to a component in a model attribute (structure).
Is there any way i can do this when i have the name of in a string variable (model-attribute-component) ??
Ram,
You can display the values as well get the modified values.
<% substr = model->structure-field1. %>
<% concatenate tmp 'model_structure_field1' into tmp.% >
<htmlb:inputField id = "<%= tmp %>"
value = "<%= substr %>" />
As long as u can display & get the modified value back you shd be fine. let me know if you are looking for more..
<b>*Reward each useful answer</b>
Raja T
Hi Raja,
Your solution was useful. I used Field-Symbols to construct the necessary model attribute's component in the below way:
assign modelRef->(substr) to <fs>. "substr has the attributeName-componentName
<htmlb:inputField id="id1"
value="<%= <fs> %>" />
I am able to bind the inputField to the model's attribute i want to and i am able to display the model attribute's value in the inputField. But, the other way is not happening. The modified values in the inputField is not getting updated in the model's attribute.
Any idea why this is not happening ??
Hi Ram,
If you want your values to be updated you would need to code this in the DO_HANDLE_DATA method using Raja's code.
You cannot dynamically call the data binding in the BSP layout page; the "//model/attribute" must be declared at design time. However, you could try experimenting with a model attribute of type ANY.
Regards,
Patrick.
Hi Raja/Patrick,
Could you please brief me in detail abt the solutions you proposed ? Since, i am out of office, i would be able to implement the solution and check only in the morning (Time zone diff. screws up and i can't take the liberty of disturbing your sleep ).
I am able to understand that on the page layout, i cannot attain the dynamic binding. So, how can i go about in the DO_HANDLE_DATA. Please guide. A code snippet might surely help me. Also, i didn't quite get trying a model attribute of TYPE ANY.
Thanks,
Ram.
Ram,
What I meant is, if you name the inputfield with ID as simply ID1, it will not get the modified value simply. It shd have the following naming convention <i>MODEL_STRUCURE_FIELDNAME</i>.
Say you want to display model->struc-carrid then your inputfield id shd be <i>model_struc_carrid</i>.
you can dynamically populate this into tmp and show as below:
<htmlb:inputField id = "<%= tmp %>"
Hope this will give you clear idea.
<i>*Reward each useful answer</i>
Raja T
Hi Raja,
I could understand your point. So, if i have the id of the inputField follow that naming convention and i already have the value = model->struc-field, i can achieve two way data binding. So, there will not be any need to dwell into DO_HANDLE_DATA. I guess i got it right. Please correct me if i am worng.
Yes you are correct.
follow the naming convention for ID.
If that doesnt work
Have below code in DO_HANDLE_DATA:
CALL METHOD SUPER->DO_HANDLE_DATA
EXPORTING
FORM_FIELDS = FORM_FIELDS
GLOBAL_MESSAGES = GLOBAL_MESSAGES
Automatically the modified data will be available in model->struc.
This way it always worked for me.
<b>*Reward each useful answer</b>
Raja T
Hi Raja,
In giving the inputField ID as 'model_structure_field', what has to be the value for model? I mean when i concatenate, do i need to use name of model ref or name of model class ??
Also, if i already have '_' in the names of model or structure or field name, will it affect the data binding ??
Message was edited by:
Ram Mohan Venkatraman
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-cc696056...
Thanks everyone,
Ram.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.