Item Descriptor Inheritance in ATG for "contactInfo" - atg

I am trying to inherit the "contactInfo" item and create a new item descriptor.. Something like this as given below..
<item-descriptor name="testContactInfo" super-type="contactInfo">
<table name="test_contact_info" type="auxiliary" id-column-name="contact_id" shared-table-sequence="1">
<property name="fixedlinenumber" column-name="fixed_line_num" data-type="string"/>
</table>
</item-descriptor>
I get the following error when i start the server.
14:19:52,856 ERROR [ProfileAdapterRepository] Error parsing template: atg.repository.RepositoryException: Your item-descriptor definition for testContactInfo has super-type contactInfo but no sub-type attribute.
what am i doing wrong here? I have kept the definition in userProfile.xml

First question: are you actually looking to create a subtype of the contactInfo item descriptor - that is to say, are you expecting there to be some items in your system of type contactInfo and some items of type testContactInfo - or are you just looking to add a custom property to the existing contactInfo item descriptor?
If you are actually trying to create a subtype of contactInfo, then you need to modify the descriptor of contactInfo to tell it how to differentiate between items of type contactInfo and items of type testContactInfo. You will need to add a property, say contactType, to contactInfo and set the sub-type-property attribute
<item-descriptor name="contactInfo" sub-type-property="contactType" ...>
...
<property name="contactType" data-type="enumerated">
<option value="standard"/>
<option value="test"/>
</property>
...
</item-descriptor>
and then you can subtype it
<item-descriptor name="testContactInfo" super-type="contactInfo" sub-type-value="test">
...
</item-descriptor>
If, however, you are just looking to add a custom property to it, you can very well add to the existing definition. You do not need to subtype to extend an out-of-the-box item. For example
<item-descriptor name="contactInfo">
<table name="test_contact_info" type="auxiliary" id-column-name="contact_id" shared-table-sequence="1">
<property name="fixedlinenumber" column-name="fixed_line_num" data-type="string"/>
</table>
</item-descriptor>
will result in a new property called fixedlinenumber added to the standard contactInfo item.

Item-descriptor inheritance can be done in two ways. You can:-
Add new properties for existing item-descriptor.
Here you can add many properties to an existing item-descriptor. This can be out of the box, or your custom repository.
For example, you can have a employeeId property to contactInfo item-descriptor, which would be available for all contactInfo items.
Create a sub-type of an item-descriptor.
This is generally used to have distinctive properties for a particular item-descriptor.
For example, in your contactInfo type, you can have a "employeeContactInfo" wherein you want to store an extra employee id, and you can have a "employeeId" only for this type.
So, it basically depends on your requirements. You can see some details on this website.. nice tutorials:-
http://learnoracleatg.blogspot.in/2014/11/art203-how-to-extend-out-of-box-non.html
and
http://learnoracleatg.blogspot.in/2014/12/art204-how-to-add-new-item-descriptor.html

Related

Correct Syntax of Element binding in XML view with JSON model

Trying to get right syntax for context binding in XML view. I have a JSON model and set the model to view with name "company" inside controller. When I use absolute path, it works but when I use relative path, it doesn't. It seems, view is unable to access the model in second case.
My Code
<Text text ="{company>/data/name}" width="200px"/>
<Input binding="{company>/data}" value ="{name}" width="200px"/>
When binding a property, you also have to provide the name of the model. Otherwise the "nameless" default model is assumed. But since all your data is in the company model you have to explicitly state that name for your value.
<Input binding="{company>/data}" value="{company>name}" width="200px"/>

Aggregation Binding to Child Collection

In an XML view I have a JSON model bound to the page with the name 'foo'. The model's object has a 'name' field and child collection 'bar' (that has a 'code' field) that I want to show in a list. This is modeled as such:
JS Code
var foo = { name:'My Name', bar:[{ code:'Code 1' }, { code:'Code 2' }] }
var fooModel = new sap.ui.model.JSONModel(foo);
page.setModel(fooModel, 'foo');
page.bindElement('foo>/');
XML Markup
<Label text='{foo>name}'/>
<List items='{foo>bar}'>
<StandardListItem title='{foo>code}'/>
</List>
Notice that the list item's values for the child 'bar' array are resolved via the name 'foo'. At least this works for me and I have found no other way to reference them in the list.
But the problem is how do I get the top-level 'foo' object data in my list-item also? Say I wanted to show the 'name' field also in the list items?
In other words, is there a way to do the equivalent of the following, where I can reference the child collection by a different name? Is there some way to achieve this?
<List items="{ path:'foo>bar', name='bar' }">
<StandardListItem title='{bar>code}' info='{foo>name}' />
</List>
You need to use an absolute path to bind the name property. Absolute means the complete path to the property within your model. The opposite is a relative binding path. Here you just use a property somewhere within your model and set a binding context to tell the runtime where your property is located within the model. You do this by using:
page.bindElement("foo>/");
Now the runtime will apply this information to all relative bindings against the model foo within this page. Therefore you can write foo>bar and the runtime automatically look up foo>/bar. However within the item aggregation this does not work, because the bar object does not have a property name. Therefore you need to use a absolute binding path to bind the property.
<List items="{foo>bar}">
<StandardListItem title='{foo>code}' info='{foo>/name}' />
</List>
You find an explanation of the binding syntax for JSONModel in the documenation.

Symfony2 Field Type Guessing: When is <textarea> chosen (over <input type="text">)?

Not declaring the field type brings the advantage that Symfony infers the required and maxlength attribute from validation rules, as explained here: http://symfony.com/doc/current/book/forms.html#field-type-options-guessing
However, I can't find a way to make Symfony 2.8.2 "guess" a <textarea> instead of an <input type="text"> :-(
My first idea was to increase the allowed length, but even with Length: max: 100000 in validation.yml, Symfony is unimpressed and just gives me <input type="text" maxlength="100000" />.
EDIT: #chalasr: I'm talking about an entity which is not mapped to the database. Sorry for not mentioning that earlier!
The FormBuilder guesses the field type by checking the type in the mapping of the corresponding property, in the entity.
Use text instead of string as type of your column mapping, and the FormBuilder will use a textarea instead of an input.
Example :
/**
* #ORM\Column(type="text")
*/
protected $field;
Output with $builder->add('field'); :
<textarea id="entity_field" name="entity[field]" required="required"></textarea>
For more info look at the Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser.
Update
So, you don't use a mapped class.
Look at the FormBuilder, as you can see, if there is no corresponding Guesser found, the form type will be a TextType (input text).
Otherwise, there is 3 different Guesser:
FormTypeGuesserChain
DoctrineORMTypeGuesser
ValidatorTypeGuesser
Because your class is not mapped, Symfony will use the ValidatorTypeGuesser to guess the type of your field.
This Guesser looks for constraints in your class.
For example, if your field has a Type constraint with type integer, the NumberType will be used and an input type number will be rendered.
My first idea was to use a Length constraint with a big min-length.
But, after many tries and looks in classes, it seems the TextareaType is never guessed, unless your class is mapped and your field has text as type (DoctrineTypeGuesser is used) .
So, without a mapped class, Symfony cannot create a textarea from type guessing.
For more informations look at the ValidatorTypeGuesser::guessTypeForConstraint.
See also the Form Type Guessing chapter of documentation, it shows how create your own TypeGuesser with a good example.

Action object Form Object Command Object

Can someone explain in the context of a Web application what do these mean? I am reading up on Spring MVC reference and see these terms thrown around.
These are referring to a bean that is the the target for the data in the form fields. I.e if you have a Person bean with username, address, email etc etc then you might have a registration.jsp with a form that your users enter all these various details, with an attribute path set in the form tag, e.g. path="username" etc. Once they post the form all the information that they have entered will be matched up from the path attributes and mapped to the corresponding appropriate fields in your Person class.
Example jsp:
<form:form ... commandName="person">
<input type="text" ... path="username">
Person class
Private String username;
Spring docs here: http://docs.spring.io/autorepo/docs/spring/3.2.x/spring-framework-reference/html/view.html

How to display different value in struts 2 select

I want to know how to display a different value in struts 2 select.
eg: i want to put Jan,Feb as month where the value should pass 1,2 respectively.
if anybody aware of this please let me know
thank you.
See the following example (from the Struts 2.1.8 API doc) :
<s:select label="Months"
name="months"
headerKey="-1" headerValue="Select Month"
list="#{'01':'Jan', '02':'Feb', [...]}"
value="selectedMonth"
required="true"
/>
The list attribute contains a map where the key is the value that will be sent and the value is the value that will be displayed.
Of course, months are static, but you could use a list of domain objects or whatever beans you need. In this case the list should be stored, typically as a field of your action class. Then you will refer to the list or map :
<s:select label="User"
name="users"
headerKey="-1" headerValue="Select User"
list="users"
value="selectedUser"
required="true"
/>
In this case your action will contain a map with the usernames and their ids and a getter for it : getUsers().
If the getUsers() method of your action returns a list of User objects, and the User class has at least (let's assume) the id and username fields, you will have to specify which field to use for value to be passed and which field to use for display in the select. This is done with the listKey and listValue attributes of the select tag :
<s:select label="User"
name="users"
headerKey="-1" headerValue="Select User"
list="users"
listKey="id"
listValue="username"
value="selectedUser"
required="true"
/>