Tridion 2011 with DD4T - no MetaData fields available on Component entity - tridion

I'm using Tridion 2011 (with DD4T, feeding an MVC webapp).
It seems that MetaData fields for Multimedia Components (specified on the Metadata tab of my Images Schema in Tridion) are not populating the corresponding property on the DD4T "Component" object. e.g. LinkedComponentFields[0].MetadataFields is empty and Multimedia.AltText is null.
Specifically the field I'm after is the AltText. But as the entire MetadataFields collection is empty on the Component, it's obviously not pulling through any metadata properties. i have tried using TemplateBuilder to set parameters in the Component Template (I set "resolve width and height" to yes, and the MergeAction to Merge) - this did not help.
Any ideas?

It is possibly caused by the linklevel. By default, links are followed for one level from the page or component that you are publishing.
You can increase this by adding a parameter to the template invocation, called linklevel. Try it with a value of 2 first, then increase until it works.

Related

Duplicity restriction for component availability

Within an area in Magnolia template, we could create 2 components. We should restrict the user in a way that they don't create duplicate components. Can we achieve this through configurations or this requires a custom property created? Any pointers would be of great help!
areas:
myArea:
availableComponents:
maxComponents: 2
renderType: freemarker
type: list
Component1:
id:
Component2:
id:
When we have created content with component1 then it shouldn't be available for selection later.
You have already limited number of components to 2. What you can do extra is to autogenerate each of the components at area creation time and mark them as not delete-able so that editors can't remove them and can't add more of the same (due to maxComponents restriction either). This effectively limits everyone to use of max 1 component of given type, but also forces exactly 1 component of given type.
If you want anything more sophisticated, you need to code it yourself.

Using [Bind(Exclude='ID')] in DNX 5 with no System.Web

I've read that you can use:
[Bind(Exclude="id")]
to stop an ID field from invalidating a ModelState when creating a record from a 'Create' action.
With DNX Core 5 System.Web is no longer available. Is there an equivalent way to ignore an auto-generated ID or am I in the same boat as this answer:
https://stackoverflow.com/a/34847744/2591770
UPDATE
It seems as though items can be removed from the ModelState directly as described here:
https://stackoverflow.com/a/13169910/2591770
I'm still interested in any other alternatives.
Use a view model and then map the posted values to an instance of your entity. That way, only the properties you place on the view model may be modified. Bind is an anti-pattern anyways.

Clone object in another language and modify fields

Using LinguaPlone we can translate a single object in another language. Usually we obtain a new instance of the same object-type with all the fields blank. We have to fill the (blank) fields and then save all. The catalog for the translations is committed and upgraded.
I wrote two new AT content-type. Almost of all fields of the object must be untranslated in the various language (we've also two image fields and file field).
So, is there a method (or addon) to clone an object as it is changing on the fly only the language-field and the translation catalog?
(Plone 4.2, last version of linguaplone)
That's what the languageIndependent=True flag is for in your schema. Use it to flag any field that does not need to be translated and it'll be copied over for you.
By setting the flag, you mark a field as only editable in the canonical copy, all translations are automatically updated whenever you modify such a field.

Creating blank dummy Components which contain mandatory Fields with the SDL Tridion 2011 Core Service

I wanted to create a blank Component in SDL Tridion 2011 using the Core Service. The only information I have at the start of the process is the Schema URI. The Schema may contain any kind of field (text, rtf, number date, embedded etc), some of which may be mandatory.
I understand that for the mandatory fields, I will need to save some dummy value in them, and this is acceptable as they will be changed manually later.
How can i achieve this?
First - you make sure all fields are set to optional in the schema, otherwise this will never work.
Second - You save.
When an optional field has no value, it will have no XML representation. If you have a schema that defines a component like this:
Field1
Field2
Field3
When all fields are optional and you save a value in Field 2, Tridion will store the following:
<Content xmlns="yourNamespace"><Field2>SomeValue</Field2></Content>
If one of your fields is not mandatory, then you'll have to provide a value. If you're using the CoreService then you can use ReadSchemaFields class to get the fields and some information about them - what type, mandatory/optional, etc.
Looking at your question/requirement to understand what you're exactly looking for, so we can answer the best possible and relevant.
Are you asking for "How can you write a generic code for component creation using core service?" instead of creating a component with a specific schema knowing all the fields upfront.
If that is what you are looking for, here is what you need to do:
You need to read the schema fields with CoreService (since you know the schema URI)
Now you know what type of fields (embedded/component link etc) you need to create content for
use the links pointed by "Puf" in his answer.
Please note that, if the field is marked as required in Tridion Schema you must have to fill a value and it has to match the field type defined in schema.
Reading schema fields via Core Service sample code can be found here
Updating a Component's field through the Core Service is already answered here: Updating Components using the Core Service in SDL Tridion 2011
That post points to a helper class you can find here: Updating Components using the Core Service in SDL Tridion 2011
If those don't help you in creating a Component, I suggest you post your code instead of asking us to write it for you.
We ask about use case, because code to fill in specific fields for a specific schema only works in one environment. Code that can automatically determine fields is re-usable.
If the use case is for an Tridion setup that has Inline Editing (Experience Manager or SiteEdit), then the correct approach is content/component types. These define a reference component with "junk defaults," instructions to the author, and even save location context.
If the use case is to allow authors the ability to create dummy components, this is out-of-the box with:
CTRL+C
CTRL+V
One-time setup required to create a "reference component." Of course we can mimic this behavior (in case "Copy of Untitled" isn't an appropriate name) by copying items with the core service.
In that case, I'll also do a copy--see a general solution for creating Tridion items using the Core Service.
Fields that require a default can have an actual default in the schema.
"Junk values" don't help authors much, always consider good defaults such as an appropriate selection or instructions in the case of fields (maybe). A 10 second change costs development practically nothing, but impacts all future components and the authors that create them.

Getting FaceletContext from FacesContext in JSF 1.2

How to get FaceletContext from FaceletContext in JSF 1.2?
The problem is that I am creating a Tab dynamically and I want to include a view inside the newly created Tab. Including a view is supported only by FaceletContext.
Maybe with
FacesContext.getCurrentInstance().
getELContext().getContext(FacelectContext.class)
See ELContext#getContext(java.lang.Class)
Returns the context object associated with the given key.

Resources