I have a repeat control that is gathering its data from a view. Displaying in a table is one column from the view. These entries can be variable. For each entry in the repeat control I would like to have a couple of user editable fields (comments and checkboxes). Since the amount and names of entries are dynamic I think dynamic field binding is the way to go. The problem is I have been struggling with it for a few days and have gotten no where.
So in the repeat I have a computedfield displying the value of the column. I was thinking of making the field name for the comments field the value of the computedfield. The datasource would be the same, just the fieldnames would change and be based on the entries in the row.
The previous entries stackoverflow entries about dynamic field binding all list passing custom properties, I still haven't gotten my head around those.
If the value of the computedfield1 = "One" then the datasource/field name for the inputText1 = "document1.One", and if the computedField1 = "Two" then the datasource inputText1 = "document1.Two"
Is this even possible?
I'm a little confused by if you want these to be things you're setting to render at page load or if you want them to dynamically change based on user entered data, but I'll assume it's the former and give you an example.
If I'm iterating through a view in a repeat control, I probably have something like:
<xp:repeat rows="50" var="currRow" value="#{ViewName}" IndexVar="rowNum">
</xp:repeat>
Inside my repeat, I will put a reference to a custom class
<xp:repeat rows="50" var="currRow" value="#{ViewName}" IndexVar="rowNum">
<xc:dynamicRowBinding dataSource="#{currentDocument}">
<xc:this.binding1>
<![CDATA[#{javascript: currRow.getColumnValue("binding1");}]]>
</xc:this.binding1>
</xc:dynamicRowBinding>
</xp:repeat>
What this is assuming is that the document you're binding things to on the XPage is declared as currentDocument, and that there is a column in your underlying view that is calculating the desired field binding for the current row based on the properties and values of that document.
In the custom control, the following exists:
By defining dataSource and binding1 as properties within the custom control, they will be available as compositeData.
Thus, to bind a field using these components, we simply put the following definition in our custom control:
<xp:inputText value="#{compositeData.dataSource[compositeData.binding1]}">
</xp:inputText>
I hope this helps!
Related
I'm trying to add the following value to a computed field:
var b = #Subset(#Unique(#DbColumn (#DbName(),"vwNrRegistru",1)),-1);
if (#Elements(b)<1){return 10001; }
else { return (b+1);}
But, I want the computed field to be binded to a datasource field:
<xp:text escape="true" id="computedField1" value="#{Contr.txt_nrcontractcv}">
I would use an inputText, but everytime I open the doc. for editing, the value increments, that's the reason I would like to go for a computed field. How can I achieve this?
You want to take the value from an existing Notes field, then do some calculation on that, then display the result, right?
You might want to bind your comp. field to a scoped var. Then do the basic calculation beforePageLoad and put the result into the scoped var. You can easily control when the calculation takes place, e.g. only for new docs, or on specific times of day or whatever
Create a inputText with style="display:none;", so that it is always rendered*, but never shown on the screen and a 'computed field' (text) that simply is equal to the value of the non-displayed field.
when they chose to label the value in properties as "Visible" they made a mistake. They really ought to have called it "Rendered" in the properties. It might also have been useful for them to have a "Displayed" property to allow you to control the display style, but that would have been mixing too many things.
I would like to create a custom control which shows 3 columns,
column 1, value selected from checkbox (this is ok)
column 2, editable box , this is showing but not working 100%
column 3, a button to remove the row (still to be done)
So far:
After selecting the options, click "Create Rows" button and 1 row appears for each selected option.
Problem:
Only last value in editable box, is used, how can I get the value from each box ?
getComponent("inputText1").getValue() only shows the last value.
Example code is on this URL:
http://snipt.org/AAgd3
You bind the column values to array variables. Exercise 23 has a complete working example: http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Tutorial-Introduction-to-XPages-Exercise-23
You just need to adjust it to the source/destination of your data. Let us know how it goes
If you want to bind them dynamically, you can also do this with expression language. It takes a bit of getting around in order to get the fields editable, but the way I've resolved it is to pass a calculated ID into a custom control, then using that for the binding.
For example: If I'm Working with a list of Unique Part Names, I may pass into my custom control a variable for a Comment. If I pass this in as fieldNameComment to my custom control, I can dynamically bind it to an inputText element through the following code.
I'm using a DominoDocument passed in as the dataSource.
Calling the Custom Control:
<xp:repeat var="CurrVal" value="#{DataSource}">
<xc:DynamicTableRow dataSource="#{EmissionsDocument}">
<xc:this.fieldNameComment><![CDATA[#{javascript:CurrVal+"Comment"}]]></xc:this.fieldNameComment>
</xc:DynamicTableRow>
</xp:repeat>
Inside the Custom Control:
<xp:inputText id="inputText5"
value="#{compositeData.dataSource[compositeData.fieldNameComment]}">
</xp:inputText>
As long as (for some reason) none of the string calculations are performed within the expression language syntax, this will yield an editable field. In my testing, if I tried to calculate a value by concatenating any strings, the field would be bound, but not appear as editable under any circumstances. If you want to bind directly to fields, this may be a good approach, but if you want to save your array and parse it through java, then Stephan's solution also works great Hope this helps!
Appended: Added repeat control to show iteration through the data source. Each iteration of the Data Source yeilds a value, CurrVal, to which the string "Comment" is appended. This creates a series of FieldNames based on the Values in the DataSource that are bound to inputs within the custom control called DynamicTableRow
I have a list box where I am trying to get the datafrom the people view in names.nsf.
The first column of the people view is computed and shows Last Name , First Name.
The code below works fine for my list box values but it does not take into consideration the value in the Filter By Column Value. Basiclly the code below acts like the Filter By Column value property does not exist. I know the Filter by Column value property is working because I replaced a repeat control on the page with a computed field and the repeat control is displaying the value excepected but the list box is displaying values from the first document in the view.
Thoughts I had to fix this are:
Use getAllDocumentsByKey to just search the people view but when I do that I lose the column values and I would need to recompute the value, something that I would like to avoid if possible incase the column formula changes.
Use FTSearch but what I really need to do is search that first column only and I am not aware of search operator that searchs a column only. Is there such a thing?
Another thought would be to somehow use the values of a repeat control, as the values for my list box, but I am guessing that this is not possible. I sort of thinking something with a scope varibale but I have not worked that out yet.
A repeat control works. How can I get my code to loop through the doeuments the same way a repeat control does?
And as a side question, is there anyway to tie a pager to a datasource as oppsed to a repeat control.
BTW What I currently do is to build a list box using a few computed fields and a repeat control but what I really want to do is to use a regular xpages list box control.
Here is the code:
var doc:NotesDocument = view1.getFirstDocument();
while (doc != null && count<10)
{
var tmpDoc:NotesDocument = view1.getNextDocument(doc)
ret.push(doc.getColumnValues()[1]);
doc.recycle();
count++;
doc = tmpDoc;
}
Try to use getAllEntriesByKey. This will give You access to column values (through ColumnValue property of view entry).
Is it possible to add a rowStyleClass to a view dependent upon values in row columns?
At the moment I need to have my code on each column and I'd like to be able to set it on "globally"...
I have tried using viewEntry or assigning the "var" to rowData but without luck. The error's saying that viewEntry or rowData is missing.
This works fine for me (and adds the UNID of the document as styleClass):
<xp:viewPanel rows="5" id="viewPanel1" var="rowEntry"
rowClasses="#{javascript:rowEntry.getDocument().getUniversalID()}">
I'm having this categorized view displayed in a view panel where the category column itself is not shown. Instead I'm displaying a combobox above the viewPanel where users can select from all the categories available (see screenshot below). The combo is bound to a scopeVariable and is refreshing the viewPanel onChange. The viewPanel has a computed categoryFilter reading from the same scopeVar. That all works nicely.
Now I also have implemented an additional wildcard (*) value in the selection list which (if selected) programmatically sets the cat filter to NULL. This way I'm forcing the viewPanel to show all entries. Again, this works fine, but with the drawback that now the view is showing empty rows where the category entries would be shown normally (in the screenshot you see empty rows above each entry, with 2 entries for the category "edcom GmbH" obviously belonging to the same category; those aren't separated by an empty row):
One way to at least hide those empty rows would be through means of css coding. But I would prefer those rows not being rendered at all.
Can this be done at all using a viewPanel, and how? Or do I have to use other controls like a repeat or a dataTable maybe?
Thanks in advance,
Lothar
One "hack" (an ugly one I admit) would be to change your categorization column from Firma to Firma:"--All--" or Firma:"*" and then instead of setting the category filter to NULL you set it to "--All--" (or "*").
The double category hits the indexer, but should do what you need.
Obviously there's no easy way. So meanwhile I'll stick to this css-style solution:
In the view panel und All Properties - data I set var = "entry". Then, under All Properties - styling I set a programatic value for the rowClasses property:
if(entry.isCategory()){
return "rowStyleHidden";
}
return "";
The style class "rowStyleHidden" hides those rows using
display: none;
Don't know yet how this turns out performance-wise, I'll have to observe this once I implement it in a copy of the real database.
You can also switch to a none categorized view, by having the viewname calculated based on the value in combobox.