Tridion DynamicContent.Query Searching By Component Template - tridion

I'm trying to render all component presentations from the broker database with a certain component template. Here's the query code so far:
using Tridion.ContentDelivery.DynamicContent;
using Tridion.ContentDelivery.DynamicContent.Query;
ItemTemplateCriteria CTCriteria = new ItemTemplateCriteria(1111);
PublicationCriteria pubCriteria = new PublicationCriteria(10);
AndCriteria finalCriteria = new AndCriteria(pubCriteria, CTCriteria);
Response.Write("<h1>START</h1>");
Query q = new Query();
q.Criteria = finalCriteria;
string[] result = q.ExecuteQuery();
if (result != null && result.Length > 0)
{
foreach (string r in result)
{
Response.Write("<h1>" + r + "</h1>");
}
}
else {
Response.Write("Result is null or 0-length.");
}
Response.Write("<h1>END</h1>");
I keep getting null results. I do have dynamic content publishing setup in cd_storage_conf.xml and a few component presentations published in the Broker database.
My understanding from this document is that, I should be able to retrieve related component URIs using this approach.
My Questions:
Is my understanding of the capabilities of the Query class correct?
Did I miss anything, config and code-wise?
Is there any other way of retrieving broker content by component template?
EDIT:
Additional info: Regarding ItemTemplateCriteria, I only assumed that this is used for searching records by Component Template. I assumed because there is another criteria class called PageTemplateCriteria. Please correct me if this assumption is invalid.
EDIT:
Additional info: I've inspected the COMPONENTS, SCHEMA and TEMPLATES tables in the broker database but didn't find the published components there. By default rule in the cd_storage_conf.xml, published content must go to the broker. For reference, here's my config:
<Publication Id="57" defaultStorageId="brokerdb" cached="false">
<Item typeMapping="ComponentPresentation" storageId="brokerdb" cached="false" />
<Item typeMapping="BinaryMeta" cached="true" storageId="brokerdb"/>
<Item typeMapping="BinaryVariant" cached="true" storageId="brokerdb"/>
<Item typeMapping="Binary" storageId="defaultFile" cached="true"/>
<Item typeMapping="ComponentMeta" cached="true" storageId="brokerdb"/>
<Item typeMapping="ComponentPresentationMeta" cached="true" storageId="brokerdb"/>
<Item typeMapping="ItemMeta" cached="true" storageId="brokerdb"/>
<Item typeMapping="LinkInfo" cached="true" storageId="defaultDataFile"/>
<Item typeMapping="DynamicLinkInfo" cached="true" storageId="defaultDataFile"/>
<Item typeMapping="Page" cached="true" storageId="defaultFile"/>
<Item typeMapping="PageMeta" cached="true" storageId="defaultDataFile"/>
<Item typeMapping="Reference" storageId="brokerdb"/>
<Item typeMapping="Schema" storageId="brokerdb"/>
</Publication>

Double check your cd_storage_conf.xml and database to check the items are stored there. If your data is going to the file system it will not be query-able.
Specifically I think the ComponentPresentationMeta must be going to the DB for this scenario to work.
Also check your cd_licenses.xml file, if it is expired, if it is (even if the cd_storage_conf.xml is correct), the items will end up on the file system.

Related

Spring Framework - How to change locale in controller

I am new to Spring, and currently confusing about localization.
I'm using the following code to get text from messages_jp.properties file.
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages" />
</bean>
And now I want to switch to text from messages_en.properties file, is there any ways to change locale in controller within if...else... block, not with using url params like "?lang=en", something like:
if (user.getLang() == 1) {
// set locale to en
} else {
// set locale to jp
}
Thanks in advance!
Try this one
<util:properties id="yourFileNameId" location="classpath:/yourFileName.properties"/>
In Controller
#Value("#{yourFileNameId['message_id']?:1}")
private int smalltext;

Read elements from XMLList in flex

is it possible to read elements what i have circled in image. I need this because XmlLists what i receive from the system is dynamic.Their elements are not static.I can't use methods like
for each(var item:XML in dp)
{
var element:String=item.#date.toString;
}
i cannot use #date always because XMLList content change always. date , open , close names are not getting always .
This is my sample XML
private var testXML:XML=<main>
<item name= "agent1" tag="cpu" value="39"/>
<item name= "agent2" tag="cpu" value="17"/>
<item name= "agent3" tag="cpu" value="27"/>
<item name= "agent4" tag="cpu" value="39"/>
<item name= "agent5" tag="cpu" value="17"/>
<item name= "agent6" tag="cpu" value="27"/>
</main>;
This sample code shows how i achieved
var List:XMLList=testXML.children();
var attr:XMLList=List.attributes();
for(var i:Number=0;i<List[0].attributes().length();i++)
{
Alert.show(attr[i].name());
}
You Can use this syntax
var str_attr:String = "#date"; // or any things you define
for each(var item:XML in dp)
{
var element:String=item[str_attr].toString();
}

Removing duplicates in Flex 4 XMLList with filterfunction

I have seen numerous examples on how to remove duplicates in ArrayCollection but I can't seem to transpose this to XMLList. In most ArrayCollection examples, the example compares the key of the array with hasOwnProperty method and return a bool. That's fine, but what would I compare to when using an XMLList? Let's say I have:
<fx:XML id="testXML" xmlns="">
<universe>
<category cname="cat 1">
<item iname = "All"/>
<item iname = "item 1"/>
<item iname = "item 2"/>
</category>
<category cname="cat 2">
<item iname = "All"/>
<item iname = "item 3"/>
<item iname = "item 4"/>
</category>
</universe>
</fx:XML>
[actionscript]
var myList:XMLList = testXML..#iname;
will give two occurences of the item "ALL".
I know I might have to convert the XMLList to an XMLListCollection to use the filterFunction (how would I go about doing that - or should I just define myList as an XMLListCollection right from the start). then on to the filterFunction:
private function remove Duplicate (item:Object): Boolean
{
here I don't know how to compare the item to tell me if the object already exist
or not. I guess I need to compare the item to a copy of the list and see if the
item has already been seen in the copy of the list. Or is there a clean way to
do this?
}
then all this is passed to a dropDownList:
<s:DropDownList id="myDDL" dataProvider="{myList}" />
Using E4x filter function you can for example put the key into an Object (if the key is a String, otherwise use a dictionary instead of an Object) and look if it is already present to build your XMLList :
var xml:XML=<universe>
<category cname="cat 1">
<item iname="All"/>
<item iname="item 1"/>
<item iname="item 2"/>
</category>
<category cname="cat 2">
<item iname="All"/>
<item iname="item 3"/>
<item iname="item 4"/>
</category>
</universe>
function filter(xml:XML):XMLList {
var seen:Object={}
return xml..#iname.(!seen[valueOf()]&&(seen[valueOf()]=true))
}
trace( filter(xml) )
Here a live example at wonderfl : http://wonderfl.net/c/10xr
The easiest way I know how to do this is to use ActionLinq. This code will take your e4x code and turn it into an Enumerable, cast the attributes as strings, make the items in the list distinct and dump it out as an ArrayCollection.
myList = Enumerable.from(testXML..#iname)
.cast(String)
.distinct()
.toArrayCollection();
If you don't want to use ActionLinq, you can implement this using a Dictionary:
[Bindable]
private var myList:ArrayList;
private function removeDuplicates(data:XMLList):ArrayList {
var result:ArrayList = new ArrayList();
var found:Dictionary = new Dictionary();
for each(var item:String in data) {
if(item in found) {
continue;
}
found[item] = true;
result.addItem(item);
}
return result;
}
And then when the XML is ready, you can call it:
myList = removeDuplicates(testXML..#iname);

Default formView for SimpleFormController?

Firstly I would like to say that I am quite new to Spring (in particular the MVC framework), and just trying to understand how everything works so please go easy on me.
I'm playing around with a dummy application that I've created, and I've created a simple login form that users can access via the /login.html bean. The bean definition is as follows:
<bean name="/login.html" class="test.controller.LoginController">
<property name="successView" value="list_messages.html" />
<property name="commandClass" value="test.domain.Login" />
<property name="commandName" value="login" />
</bean>
(the Login class is a simple object containing a username and password field with appropriate getters and setters).
The LoginController class does virtually nothing for now:
public class LoginController extends SimpleFormController
{
#Override
protected ModelAndView onSubmit(Object command, BindException errors) throws Exception
{
return new ModelAndView(new RedirectView(getSuccessView()));
}
}
Now I have one view resolver in my bean definition file, which goes as follows:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
To support my Login form I have a login.jsp file in my jsp directory.
My question is as follows: why does accessing /login.html redirect me to login.jsp? I have not specified a formView property for my form, so how does the view resolver know to redirect me to login.jsp?
Thanks in advance for any help!
Joseph.
When you do not specify The logical view name, Spring relies on DefaultRequestToViewNameTranslator, which is installed by default. So if your request is something like
http://127.0.0.1:8080/app/<LOGICAL_NAME_EXTRACTED_BY_VIEW_NAME_TRANSLATOR_GOES_HERE>.html
Have you seen <LOGICAL_NAME_EXTRACTED_BY_VIEW_NAME_TRANSLATOR> ??? So if your request is
http://127.0.0.1:8080/app/login.html
The logical name extracted by ViewNameTranslator is login which is supplied To viewResolver and Translated To
/jsp/login.jsp
Nothing else

How to map Items which its SubItems are in the same Table with Nhibernate?

I am trying to build a messaging system and for this i have the table definition below
Message
Id
From
To
Body
ParentId // Subcollection, i want to get Asnwers (Message.ParentId== Message.Id)
IsRead
and i have this in the Message.cs
IList<Message> Answers;
I have tried this but it gives me all the messages and all the answers in the main collection.
But i dont want answers to be seen like a message (like the main item).
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="RealEstate.Core" namespace="RealEstate.Core.Domain">
<class name="Message" table="Message" lazy="true">
<id column="id" type="Int64" name="Id">
<generator class="native" />
</id>
<property name="From" column="[From]" type="Int64" />
<property name="To" column="[To]" type="Int64" />
<property name="Body" column="Body" />
<property name="ParentId" column="ParentId" type="Int64" />
<property name="SenderType" column="SenderType" type="Byte" />
<property name="IsRead" column="IsRead" type="Boolean" />
<bag name="Answers" lazy="true" cascade="delete">
<key column="ParentId" />
<one-to-many class="Message"/>
</bag>
</class>
</hibernate-mapping>
How can this mapping be done, they are in the same table ?
Thank you very much
Before attempting an answer, I'd strongly recommend that you search the NHibernate Users Group as there are tons of helpful NHibernate folks that lurk there answering all kinds of questions.
But let me see if I can help here.
Hmmm, I'm not totally sure I understand the question. You say:
I have tried this but it gives me all
the messages and all the answers in
the main collection.
But i dont want answers to be seen
like a message (like the main item).
Do you mean that the Answers collection contains all answers in the database?
Can you post up more code, showing the query your running, and the class code?
One potential problem you have with your scenario is that ParentId can be NULL in the database. This gives NHibernate problems when mapping a one-to-many.
Try making the association bidirectional (documentation reference). That sometimes helps avoid a few traps.
To do that, add this to your class
public class Message {
///<summary>Reference to parent message</summary>
public Message Parent {get;set;}
//... rest of class
Add this to your mapping:
<bag name="Answers" lazy="true" cascade="delete" inverse="true">
<key column="ParentId" />
<one-to-many class="Message"/>
</bag>
<many-to-one name="Parent"/>
The inverse=true will make NHibernate manage the relationship from the Parent property, not the collection. This is necessary because ParentId can be null.
In your code, rather than using myMessage.Answers.Add( blah ); you can use answer.Parent = myMessage. Of course, you can write nice helper methods to make this more meaningful.
someMessage.AddAnswer( someAnswer );
Which looks like this:
public void AddAnswer(Message answer)
{
answer.Parent = this;
if( ! this.Answers.Contains(answer) )
this.Answers.Add(answer);
}
Hope this helps.
You want to map a tree ?
Maybe this could help:
how to map a tree in nhibernate

Resources