I'm new to Core Data and databases in general. Now I need to parse a XML and store the contents in Core Data. The XML looks something like this:
<books>
<book id="123A" name="My Book">
<page id="95D" name="Introduction">
<text id="69F" type="header" value="author text"/>
<text id="67F" type="footer" value="author text"/>
</page>
<page id="76F" name="Chapter 1">
<text id="118" type="selection">
<value data="1">value1</value>
<value data="2">value2</value>
<value data="3">value3</value>
</text>
</page>
</book>
<book id="124A"...
From my understanding I would need four Entities, like "Books", "Book", "Pages" and "Text". I wonder how to set the relationships correctly and how to add for example a Page object to a Book object and how to retrieve a Text object attribute's value? The tutorials I have found mostly deal with one Entity so I didn't really get the idea.. Gtrateful for any help!
No, you'd need three entities. You can think of "Books" as the CoreData database you're using. The CoreData database then includes a number of entities called book.
I think the data model you have is a bit weird, but I guess it makes sense for your application. To map it to CoreData I would:
Add the entities Book, Page, Text
Add a bookId, pageId, textId to them, respectively.
Then add a relation from Page to Book, and from Text to Page.
By then you should be able to print out a whole book by asking for all Pages that have
Book = the book you're interested in
and then order all those Pages by their pageId
and in order, ask for all texts that have
Page = the current page
then order those Texts by their textId.
What might be a problem is that a Text can have multiple Values, as seen in your XML above. You could use this by adding another entity called Value, but I would probably solve it by adding the attributes "value" and "type" to the Text entity directly. (You could then use "value" as a second sort key when printing out a page.
Check out these links:
http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/
http://developer.apple.com/cocoa/coredatatutorial/index.html (for regular Cocoa, but the same principles hold so this should help)
Related
I previously implemented aggregation with VBox. This get all the 'questions' and creates a Text box for each....
<VBox items="{path: 'view>questions', templateShareable: true}">
<items>
<VBox class="sapUiTinyMargin" templateShareable="true">
<Text text="Question {view>OrderSequence}"/>
</VBox>
</items>
</VBox>
I need to do the same, but for formElements. Can this be done?
<f:formElements>
<f:FormElement label="{i18n>radioLabel}">
<f:fields>
<Input value="{viewmodel>radioLabel}" id="__redioLabel"/>
</f:fields>
</f:FormElement>
</f:formElements>
It doesn't seem to work with 'items'
In UI5 elements have several characteristics:
Properties: generally scalar attributes, like "title" or "width".
Events: which are fired when something happens, like "press" or "close".
Aggregations: collections of child entities, like the "items" of a list.
Associations: related controls, like the "label" of a input field.
You can find how these relate to the concept of data binding in the official documentation here.
In your case, the "formElements" is an aggregation of the FormContainer element. Based on the documentation:
Aggregation binding can be used to automatically create child controls according to model data. This can be done either by cloning a template control, or by using a factory function. Aggregations can only be bound to lists defined in the model, that is, to arrays in a JSON model or a collection in the OData model.
This implies that ANY aggregation can be used, no matter how it is named. Now, to go back to you example, the reason why "items" does not work, is because the FormContainer parent element has no aggregation with that name. Instead, you must use the "formElements" aggregation.
<f:FormContainer formElements="{viewmodel>/my/path/to/list}">
<f:formElements>
<f:FormElement label="{i18n>radioLabel}">
<f:fields>
<Input value="{viewmodel>radioLabel}"/>
</f:fields>
</f:FormElement>
</f:formElements>
</f:FormContainer>
Also, note that usually, you do not need to give an ID to the template or any of its children (the Input in your example has an ID), that is because that element specifically will not be part of the resulting control tree. It is just used to be cloned to create the "real" elements based on the model list.
Lastly, you have a "templateShareable" property on the VBox in your first example. VBox has no such property, so it does nothing (you actually use it correctly inside the binding specification for the "items" of the parent VBox).
Solution was...
An aggregation on the form...
<f:Form id="formCustomRadio" editable="true" visible="true" formContainers="{viewmodel>answers}">
Thanks a lot
You can use the VBox and then put the f:formElements inside the items.
Or else use Standard List.
FormElements or containers don't have aggregation items.
I need some help designing a React app singe page app.
I want to show and let the user edit (via form inputs) a complex JSON structure (with known shape), but I'm having trouble picturing how to bind the values in my generated form to the data structure. The JSON structure is static, I just want to let the user edit values, not the structure itself.
Some of the values depend on other values in the structure (e.g. the max value of a field is specified in other field). The data has nested structures but they do not map 1:1 to my components (I don't control the input) which makes handling more complex (deep components can change surface values).
For example purposes:
data.json
{
"age": 12,
"maxAge": 100,
"name": {
"first": "John",
"last": "Doe"
},
"dogName": "Foo"
}
main.jsx
ReactDOM.render(<Editor data={data} />, mount);
Editor.jsx
<form>
<Person data={props.data} />
<Text defaultValue={props.data.dogName} />
<h2>Settings:</h2>
<Number defaultValue={props.data.maxAge} />
</form>
Person.jsx
<fieldset>
<Text defaultValue={props.data.name.first} />
<Text defaultValue={props.data.name.last} />
<Number max={props.data.maxAge} defaultValue={props.data.age} />
</fieldset>
Handling each and every field manually with change events seems too complex, tiresome (I have tens of fields per component), and error-prone... and I'm not even sure how to propagate the changes to the top-level component from the inner ones.
What are the alternatives?
For an official guide: Thinking in React
I believe the above guide can help walk you through some of the challenges that you are facing.
For your first point: I would use state to hold the information. You can do "two way" data binding to have the form represent your data and the data represent your form. You can also use some form of onChange function calls to update the data that relies on other inputs.
Section 5 of the linked guide goes over propagating data up the chain (ie person -> editor) using callbacks.
If this is going to potentially evolve into a larger project, I would suggest looking into Flux for a MVC type front end with React as the View.
I have an ODK form that is configured to get a list of data from the database and use that list of data for the select.
Problem is that I am not able to display an error for when the query from the database returns an empty string, instead, ODK form crashes while loading. I have tried this,
<instance id="books">
<list>
<g:if test="${Book.list()}">
<g:each in="${Book.list()}" var="book">
<book>
<id>${book.id}</id>
<name>${book.name?.encodeAsHTML()}</name>
</book>
</g:each>
</g:if>
<g:else>
<book>
<id></id>
<name></name>
</book>
</g:else>
</list>
</instance>
which creates an xml with an empty id and empty name. This makes sure that the ODK doesn't crash when it loads.
But since I don't want the user the select an empty book option, I added a constraint in the bind nodeset section,
<bind nodeset="/form/book" type="string" required="true()" constraint=". != ''" jr:constraintMsg="Book must be not be empty"/>
So now when the user tries to get past the book selection section the ODK form doesn't allow it, but instead of throwing the constraint message that I supplied it throws this error
don't know xml value! perhaps selection was stored as index only and has not yet been linked up to a formdef?
I've successfully created a new Data List type in Alfresco, but was struggling to figure out what the tag is called to achieve a description under a field. I consulted the Data Dictionary, but was unable to find it.
It may not exist, but the this screenshot makes me hopeful. As you can see, the Modified Date field has the DD/MM/YYYY help text under it. This is exactly what I want to put under the Program Name field, but with my own string.
<property name="orpdl:programName">
<title>Program Name</title>
<type>d:text</type>
<helptext>What's this tag called?</helptext>
<mandatory>true</mandatory>
</property>
Eeuh that's just a div in the control field for all the date fields.
Take a look at alfresco/site-webscripts/org/alfresco/components/form/controls/date.ftl
The message you see is in this div:
<div class="format-info">
<span class="date-format">${msg("form.control.date-picker.display.date.format")}</span>
<#if showTime><span class="time-format<#if disabled>-disabled</#if>">${msg("form.control.date-picker.display.time.format")}</span></#if>
</div>
So you want a string, just create your own custom controller based on textfield.ftl and put whatever string you like. Probably best to do that by passing it through the control-params.
Umbraco newbie here. I've researched a tonne but can't seem to find what I' looking for.
I have a site with a slider on the homepage, the slider is sitting in a macro which is using a for-each (of a nodes children) with a final goal to display the 'heroImage' image from that doctype. I cant post images as a newbie to this site, but heres my content structure:
HOME
PORTFOLIO
- First Item
- Another Item
ABOUT
CONTACT US
Home, Portfolio, ABOUT and CONTACT US are "Landing Pages" document types, and the children under Portfolio (First Item and Another Item) are "Portfolio Entries" document types. Below is the code on "Landing Page" calling the Slideshow macro.
Portfolio Entry has fields:
heroImage
images
body
Slideshow macro obviously being the highlight there. Easy enough. Heres my macro code where you'll see I'm trying to display the heroImage of the node in question for each 'for-each'.
<xsl:template match="/">
<!-- slider -->
<div id="slideshow">
<div id="slider" class="nivoSlider">
<xsl:for-each select="umbraco.library:GetXmlNodeById(1081)/*[#isDoc and position() < 4]">
<xsl:variable name="mediaId" select="umbraco.library:GetMedia(#id, 'false')/data [#alias = 'umbracoFile']" />
<xsl:if test="$mediaId > 0">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia($mediaId, 0)" />
<xsl:if test="count($mediaNode/data) > 0 and string($mediaNode/data[#alias='umbracoFile']) != ''">
<img src="{$mediaNode/data[#alias='umbracoFile']}" alt="[image]" />
</xsl:if>
</xsl:if>
</xsl:for-each>
</div>
</div>
<!-- data-transition="slideInLeft" -->
<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>
</xsl:template>
I feel like im so close, and ran out of search queries as most of the solutions I found were dependant on the imageId being passed onto the macro from the other side of the macro which wouldn't work.
Hope Ive explained this enough and thanks in advance for your help!
First of all, it looks like you're hardcoding the parent node id. In the code you just provided, it seems to only be getting the children of the node with id 1081. From reading what you just posted, it would seem that on all landing pages, you want to display their individual portfolio entries.
Either way, I would stay away from hardcoding IDs. If the node id changes in any way(user deletes the node, it gets exported as a package to the live environment, etc), your code will stop working. I'd just use $currentPage instead.
Judging by your filter, I imagine you only want the first 3 items to show in the slider. The code seems correct, but you seem to be using the old schema and its associated xpath. If you're using a newer version of Umbraco, the way you reference node data in xslt would have changed. I would guess that you've found many code examples and tried merging them together, without realising they wouldn't call the same schema.
This wiki link will provide more information, and hopefully fix your problem if you're using the wrong xpath.