I am trying to bind a label 2 (or more!) fields in a dataset in Silverlight 4. I get a localized string out of a resource file and do a String.Format on it like so:
<TextBlock Name="lblTotals" Text="{Binding TotalItems, StringFormat='You need \{0\} items and \{1\} products.'}" />
This works fine with 1 item but there's no way of doing multiple binds in SL4 it seems.
I found some blog posts on how to bind a single element to multiple fields but it does not seem to support the String.Format part which is critical.
The last caveat is that it is bound to an ObservableCollection, so when these fields change in the data the UI must update too.
Any suggestions? Thanks!
I found a solution here using a converter and binding to the whole object and passing in the string as a converter param.
Then the totals did not update when the grid values updated (despite being linked to OnPropertyChanged) - this was the solution hack here.
Related
I think the answer is no, but the question has been put to me so I'd like to confirm. My understanding is that any custom XBL control that I create for use in Form Builder can have one and only one value. Is this correct?
I have always assumed this because the control name is then used in the data instance as the name of the node which contains the the value.
This question comes from the desire to have reusable components with multiple values, for example, an Address control so that addresses can be recorded consistently and the same set of fields does not need to be added many times. Orbeon does have some support for this in the form of Section Templates but because the control names stay the same in each instance of a Section Template this does not work well with our design.
The best idea I've had is that a custom control which records multiple values could encode all the values into a single text string for example in JSON. Of course, this is not ideal.
Are there any other options?
It is possible for controls to have multiple values. When that happens the values are typically stored in nested elements. I.e. a control could bound to an element <address>, and could create nested elements <street>, <city>,<country>, etc to store the different parts of the address.
In practice, you can look at how this is done in the Image Annotation annotation control (see wpaint.xbl), which creates nested elements <image> and <annotation>, leveraging the xxbl:mirror="true" functionality.
I have 6 columns in my dataTable and I am particularly interested in two InputText: I must prevent the possibility of writing in both inputText on the same row. Either is written into one or the other, but not both.
The solution I found is to implement a Validator and browse the dataTable or specifically visiting the tree of components with UIComponent#visitTree() on UIData as advocated by BalusC here. My question is: how do I know on which row I am? How can I retrieve the value of a InputText specifying the row ?
My goal is to validate two InputText relative to another. When one has a value, the other must be null. And reciprocally.
If you have another solution, I'm interested.
Thanks for your help.
Is it possible to use OmniFaces <o:validateAllOrNone> (which is pretty cool ;)) within an <ui:repeat> or <h:dataTable>?
I need a table with each row having an input field column. You could either fill in none of these values or all of them.
If I put the <o:validateAllOrNone> within the <ui:repeat> or <h:dataTable> and use the id of the input field in components attribute, then the validator also gets triggered, if all fields are empty.
No, that's not possible. The components attribute must refer physically multiple components, not a single component which is rendered multiple times. It can however be used on physically multiple components which are rendered during same iteration round. The <o:validateXxx> multi field validator is not designed to reference a single component which is rendered multiple times. The only OmniFaces validator which does that is <o:validateUniqueColumn>.
If you want to use the <o:validateXxx> multi field validator on dynamic inputs based on a collection, then your best bet is to use JSTL <c:forEach>. It will build physically multiple components.
E.g.
<c:forEach items="#{bean.items}" var="item" varStatus="loop">
<h:inputText id="input_#{loop.index}" value="#{item.value}" />
</c:forEach>
Assuming that there are 3 items, this will dynamically create JSF components with IDs of input_0, input_1 and input_2. Then you can just use <o:validateXxx> as follows (put it outside the loop!)
<o:validateAllOrNone components="input_0 input_1 input_2" />
You can replace the hardcoded string in the above example by an EL expression which returns the desired space separated string of component IDs from a backing bean.
<o:validateAllOrNone components="#{bean.inputIds}" />
An alternative would be to create a <x:validateAllOrNoneColumn> yourself or to post an enhancement request at OmniFaces issue tracker. It would be not exactly trivial to alter the existing <o:validateAllOrNone> that a completely separate component is desired.
I'm trying to understand native knockoutjs template binding, especially foreach binding.
Just wondering how to access current item using native bidning? With jQuery.tmpl it is possible using something like $item / $data. How to do the same using native template binding when data source is the arrays of primitives so each item has no named fields? Here is the JSFiddle with two examples, the first - using native binding where data source is array of custom objects, second one - binding to an array of strings. I'm unable get it working, looks like I'm missing something obvious?
Basically I'm trying to understand native bindings and be able refactor following example using native binding: JSFiddle: Comma separated list of checked items so I would be able keep an observable variable which represnts a comma separated list of checked items.
You can use $data to access the raw value like: http://jsfiddle.net/rniemeyer/M73S8/3/.
Here is the other fiddle updated: http://jsfiddle.net/rniemeyer/EGAH9/8/. Not sure the exact functionality that you want to support in it.
I am not sure if this is already answered from the amazing Niemeyer (thanks for all of your help in the Knockout Community!), but I made a jsFiddle to show storing the actual Person objects Selected in an observable array.
I am not sure if that is what you are trying to do, but maybe someone else is researching this looking on how to do this exact thing: bind the actual objects into an observable array, not just the ids (although, i added that too to remind me).
Example of a Checkbox List Selected Object Binding: http://jsfiddle.net/cjgaudin/Dp7Br/
Ok, I'll explain. I need to create a datagrid in MVC on the fly (potentially multiple datagrids on a view) depending on a XML file being read in. The file gets looped through and may contain multiple grids of data, the headers and rows are set in the file. The problem being that my application won't know the content of the XML file before reading it so I can't apply it to an IEnumerable model. The idea being to make it generic so that it can read in any XML file I pass to it set up as below and put the data in a sortable datagrid. Is this at all possible with current controls out there? I have tried Teleriks MVC grid and while I can read the data into the grid, I cannot sort the data as this feature will only work when passed a DTO. I have a feeling what I'm looking for can't be done (unless I write a custom HTMLHelper or something) but no harm in asking I guess
My xml will be as such
<xml>
<REPORT>
<HEADERS>
<HEAD>Col1</HEAD>
<HEAD>Col2</HEAD>
</HEADERS>
<ROWS>
<ROW>Data1</ROW>
<ROW>Data2</ROW>
</ROWS>
</REPORT>
</xml>
Thanks
I would advise using the jquery grid. Then write a class to parse the xml and generate the grid javascript in the view, and a second action to parse the xml (again) and generate the json result. MVCCrud may help with the idea there is a generic jquery grid in there but it works off an IQueryable list so would need to be adapted.
I haven't seen a helper extension out there that does what you need.
There are some good ones that work with generic collections (such as Telerik's or MVCContrib's). The sample you provide cannot be translated in to a collection that would be handled by these however: the row needs to have cells that can be matched to the header elements.
<xml>
<REPORT>
<HEADERS>
<HEAD>Col1</HEAD>
<HEAD>Col2</HEAD>
</HEADERS>
<ROWS>
<ROW><CELL>Data1</CELL><CELL>Data2</CELL></ROW>
<ROW><CELL>Data2</CELL><CELL>Data4</CELL></ROW>
</ROWS>
</REPORT>
</xml>
If the XML can be deserialized into a generic collection, it is easy to populate the grid.
Hope this helps.
I'd look into the JQuery Grid. You have to munge the data into the format that it wants, but it gives you a lot of flexibility and nice UI for free. You will still need to write sort code, though.