How to get the complete set of Embedded field values in a popup window in the Tridion Web GUI? - tridion

I implemented a ribbon tool bar button for Tridion 2011 SP1, which opens an aspx page and populates a drop down list based on a look-up component. The look-up component comprises of different embedded schemas. To filter out the values based on embedded schema name I need to get the Embedded schema field values of component creation page on button click in button JavaScript.
Because in my component creation page consists of multivalued Embedded schema field has the info, which helps look up value filtering process. I am unaware of the command need to be used for the requirement. I know about a command to get the complete component XML, that is: $display.getView().getItemFields().
To get the present RTF field content I am going for the command: target.editor.getHTML(). To get the complete set of Embedded schema field values only,
which command I need to use?
My sample component source:
<root>
<a>sample a</a>
<b>sample b</b>
<c>
<ca>ca 1</ca>
<cb>cb 1</cb>
<cc>cc 1</cc>
</c>
<c>
<ca>ca 2</ca>
<cb>cb 2</cb>
<cc>cc 2</cc>
</c>
<c>
<ca>ca 1</ca>
<cb>cb 1</cb>
<cc>cc 1</cc>
</c>
</root>

I don't think there are public API for that. But you could use component data xml and then parse it by yourself:
var item = $display.getItem();
var xml = item.getContent(); // OR $display.getView().getItemFields();
var xmlDoc = $xml.getNewXmlDocument(xml);
var schema = item.getSchema();
if(schema.isLoaded())
{
var xpath = "/custom:{0}/custom:embeddedFieldName".format(schema.getRootElementName());
var fields = $xml.selectNodes(xmlDoc, xpath, { custom: schema.getNamespaceUri() });
// loop fields and get values ...
}

Related

How to dynamically load image into picturebox in fast report?

I have a table in Sql that has 2 columns containing header and address of images that related to that header like below:
Header address
194003 ~/viewerImages/1903-01-1-5-0-6-00143.jpg
194003 ~/viewerImages/1903-01-1-5-0-6-00161.jpg
194003 ~/viewerImages/1903-01-1-5-0-6-00190.jpg
194012 ~/viewerImages/1903-01-1-5-0-6-00143.jpg
194012 ~/viewerImages/1903-01-1-5-0-7-00141.jpg
194012 ~/viewerImages/1903-01-1-5-0-7-00160.jpg
194015 ~/viewerImages/1903-01-1-5-0-7-00180.jpg
194015 ~/viewerImages/1903-01-1-5-0-8-00159.jpg
194015 ~/viewerImages/1903-01-1-5-0-8-00184.jpg
I want to load these images dynamically in fastreport for each header.
what should I do?
One solution is to create an objet with some properties that are the images to load (image1, image2, image3). You also add more properties with the data that you want to print in the report.
Then, you can load the information in the object dinamically and after send the object to the report, so Fast Reports will print the information you are loading in the object. In this way you can do wharever you want dinamically.
For image properties, you can use Image or byte[] type.
To create the report:
var report = new Report();
report.Load(Constants.Paths.ReportFolder + "Return.frx");
report.RegisterData(myObject, "Name");
report.Design(); // if you want to open the designer before to print
report.Show();
Note: The object to register must be a collection of objects. In this case myObject would be a List. If you want to register a single object, you can do it in this way:
report.RegisterData(new List{ myObject }), "Name");
In the designer you can access all the properties.

Custom AEM Form field not persisted

I attempt to create a custom field for AEM form (AEM6.0 SP3) following how text field does it: /libs/fd/af/components/guidetextbox
I created init.jsp and widget.jsp with same content.
On widget.jsp, I then add some jQuery to autopopulate text field on focus out.
<script>
var thisField = '${guideid}${'_widget'}';
$(thisField).focusout(function() {
$(this).val('date ' + new Date());
});
</script>
On focus in, I type text 'ABC' then when focus-out I get text 'date ' however when submitting the data, text 'ABC' gets submitted.
Is there any AEM API I need to invoke (instead of just jQuery .val() function) in order for the changes to be recorded ?
Not the best solution, but we managed to get it work by first calling focus(), eg.
$(this).focus().val('date ' + new Date());
Better solution:
create a custom function eg
function initDatePicker(thisObj) { $(this).focusout(function() {thisObj.value = $(this).val();});}
Update .content.xml to call this within initScript eg.
<cq:template guideNodeClass="guideTextBox" jcr:primaryType="nt:unstructured" jcr:title="Datepicker input field" initScript="initDatePicker(this)"/>
the function will be immediately included when the widget is added to canvas.
In AEM Forms a Javascript model is maintained that stores the value and that model is used to submit the data. Now to pass on the value from the ui to the model XFA_EXIT_EVENT[1] has to be triggered. So after setting the value you must add this line of code to persist the value
$(this).trigger(xfalib.ut.XfaUtil.prototype.XFA_EXIT_EVENT)
Also a better way would be to create your own widget for this specific scenario. See [2] for more details. The article is for AEM Form 6.1 but it will work for AEM 6.0 as well.
[1] https://helpx.adobe.com/aem-forms/6/html5-forms/introduction-widgets.html
[2] https://helpx.adobe.com/aem-forms/6-1/custom-appearance-widget-adaptive-form.html

how to retrieve java map in javascript?

I'm using JSF1.2 apache trinidad tag. I have a requirement like based on the drop down list the associated list of array values should get rendered into the UI.My Bean will have a map (drop down value as key which is unique, the associated list of values retrieved from DB) will be readily available when the page loads. In java script, how to retrieve the associated list value from this map and how to return back the array value into UI? Is there any other options available to achieve this requirement?
Your help on this is really much appreciated.
If I understand this right, you have the entire map available when the page is rendered.
You could prebuild the selectItems in the dropdown beforehand like this:
Map<String, List<String>> map;
//read the map content here
List<SelectItem> items = new ArrayList<SelectItem>();
for(String key: map.keySet()){
items.add(new SelectItem(key, map.get(key)));
}
These items will have the key as the label and the corresponding array as the value.
When you use this in your interface you can do this:
<tr:selectOneChoice value="#{bean.selectedArray}" required="true" autoSubmit="true">
<f:selectItems value="#{bean.items}"
</tr:selectOneChoice>
<tr:outputText value="#{bean.selectedArray}" />
The code isn't complete, but it should get you started.

SDL Tridion GetListKeywords using Anquilla Framework

I'm writing a GUI extension and using the Anquilla framework to get a list of Keywords within a Category. I'm obtaining an XML document for the list of keywords then working with that document within my extension.
My problem is that the returned XML doesn't contain the Keyword's 'Description' value. I have the Title and Key etc.
My original code looks like this:
var category = $models.getItem("CATEGORYTCMID:);
var list = category.getListKeywords();
list.getXml();
A typical node returned is this:
<tcm:Item ID="tcm:4-1749-1024"
Type="1024" Title="rate_one" Lock="0" IsRoot="true"
Modified="2012-12-17T23:01:59" FromPub="010 Schema"
Key="rate_one_value" IsAbstract="false"
CategoryTitle="TagSelector"
CategoryID="tcm:4-469-512" Icon="T1024L0P0"
Allow="268560384" Deny="96" IsNew="false"
Managed="1024"/></tcm:ListKeywords>
So I've tried using a Filter to give me additional column information:
var filter = new Tridion.ContentManager.ListFilter();
filter.columns = Tridion.Constants.ColumnFilter.EXTENDED;
var list = category.getListKeywords(filter);
Unfortunately this only gives the additional XML attributes:
IsShared="true" IsLocalized="false"
I'd really like the description value to be part of this XML without having to create a Keyword object from the XML. Is such a thing possible?
cough any ideas? cough
I'm afraid you'll have to load the Keyword itself to get the Description.
It's not used in any lists, so it's not returned in the XML.
You could always create a List Extender to add this information to the list, but try to be smart about it since this extender will execute everytime a GetList is called.
Won't save you from having to open every keyword in the list, but you'll be doing it server-side (with Core Service/NetTcp for instance) which will probably be easier and faster than opening each keyword with Anguilla.
In this instance I only need the one keyword, so I simply get it from the CMS. Getting an object in Anguilla is a bit weird, here's the code:
In your main code area:
var selectedKy = $models.getItem("TcmUriOfKeywordHere");
if (selectedKy.isLoaded()) {
p.selectedKy = selectedKy;
this.onselectedKyLoaded();
} else {
$evt.addEventHandler(selectedKy, "load", this.onselectedKyLoaded);
selectedKy.load();
}
It's worth noting how I store the keyword in the properties of the item, so I can obtain it in the onselectedKyLoaded function
The function called once the item is loaded
ContentBloom.ExampleGuiExtension.prototype.onselectedKyLoaded = function (event) {
var p = this.properties;
var selectedDescription = p.selectedKy.getDescription();
// do what you need to do with the description :)
};
I resolved this, thanks to the answer here: https://stackoverflow.com/a/12805939/1221032 - Cheers Nuno :)

Getting the values from a repeated Embedded Schema using TOM.NET API in an event handler in SDL Tridion 2011 SP1

I am working on the Event Handler for saving a component.
My objective is to perform some validations when the user creates and component based on a schema.
I have a schema with the name "Employee".
Employee has an embedded schema with the name "Experience" and it is multivalued.
Experience has 3 fields.
Role : Drop down with the values Manager, Lead.
Company: Text field
Years: Text field
When the user enters some data in these fields, I want to do some validations before save.
The high level design would look like this.
Load the instance of the Component
Navigate to embedded field "Experience"
For every "Experience". I need to get the value of the "Role", and check that appropriate value is entered in other two fields(By writing Component Save event)
For( all the repeated "Experience")
{
If (Role=="Manager")
check the values in the other two fields and do some validation
If (Role=="Lead")
check the values in the other two fields and do some validation
}
I am stuck at extracting the value and Names of subfields at the embeddded field.
I have tried:
Tridion.ContentManager.Session mySession = sourcecomp.Session;
Schema schema= sourcecomp.Schema;
if(schema.Title.Equals("Employee"))
{
var compFields = new ItemFields(sourcecomp.Content, sourcecomp.Schema);
var embeddefield = (EmbeddedSchemaField)compFields["Experience"];
var embeddedfields = (IList<EmbeddedSchemaField>)embeddefield.Values;
foreach(var a in embeddedfields)
{
if(a.Name.Equals("Role"))
{
string value=a.Value.ToString();
}
}
}
Actually I am stuck how to retrieve the values in the other fields at the same time.
Can any one explain how it can be done?
What you need to understand on a EmbeddedSchemaField class is that it represents both a schema and a field (as the name implies...)
I always find it helpful to look at the source XML of the component when writing code that targets its fields, you get a good visual representation of what your classes must do. If you look at a component XML like this:
<Content>
<Title>Some Title</Title>
<Body>
<ParagraphTitle>Title 1</ParagraphTitle>
<ParagraphContent>Some Content</ParagraphContent>
</Body>
<Body>
<ParagraphTitle>Title 2</ParagraphTitle>
<ParagraphContent>Some more Content</ParagraphContent>
</Body>
</Content>
Body is your embedded Schema field, which is multivalued, and contains 2 single-valued fields within it.
Addressing these fields in TOM.NET then:
// The Component
Component c = (Component)engine.GetObject(package.GetByName(Package.ComponentName));
// The collection of fields in this component
ItemFields content = new ItemFields(c.Content, c.Schema);
// The Title field:
TextField contentTitle = (TextField)content["Title"];
// contentTitle.Value = "Some Title"
// Get the Embedded Schema Field "Body"
EmbeddedSchemaField body = (EmbeddedSchemaField)content["Body"];
// body.Value is NOT a field, it's a collection of fields.
// Since this happens to be a multi-valued field, we'll use body.Values
foreach(ItemFields bodyFields in body.Values)
{
SingleLineTextField bodyParagraphTitle = (SingleLineTextField)bodyFields["ParagraphTitle"];
XhtmlField bodyParagraphContent = (XhtmlField) bodyFields["ParagraphContent"];
}
Hope this gets you started.

Resources