Xpages more fields (unlimited) at the click of a button

前端 未结 3 503
粉色の甜心
粉色の甜心 2021-01-03 02:47

I would like to start with x no. of fields (in my app I have a pair of textual data field and numeric data field) on a xpage application (say 10 pairs) and then when the use

3条回答
  •  一向
    一向 (楼主)
    2021-01-03 03:21

    Usually, fields are bound to a document data source using dot notation:

    
    

    However, array notation is also supported:

    
    

    Because the field name in this latter syntax is being treated as a string, not as an implicit property of the bean, it can be dynamically computed. What I've found to be the easiest way to define these dynamic fields is to create a custom control for each of the basic types of fields, and define each as accepting the data source and the field name. So the field itself then ends up with a syntax similar to the following:

    
    

    By using that syntax, a calculation of any complexity can be used to determine what field name to pass to the custom control. In the scenario you're attempting to accomplish, specifying an indexVar on the repeat control that surrounds the field pair would allow you to designate a field suffix for each... perhaps something like the following:

    
     
      
      
     
    
    

    With this approach, you would end up with fields named "fullName_0", "fullName_1", etc., up to the limit specified in the viewScope. Typically, the only complication is ensuring that when an existing document is opened, the viewScope variable is set back to the correct limit. Another approach to that, of course, is actually saving the limit as another item on the document and binding the repeat value to it instead.

提交回复
热议问题