How to reference custom fields in a collection template - plone

I am trying to create a custom collection template, which includes some of my custom fields.
This is what I have at the moment: https://gist.github.com/adrigen/06bdc88bda6e9cf20a44
But the error is: NameError: name 'resource_type' is not defined.
I know I need to define that variable, but I cant find the right place to do it.
I tried
<metal:block use-macro="context/standard_view/macros/entries"
tal:define="
resource_type context/resource_type; >
And a few other places, but it doesn't seem to make a difference. What am I understanding incorrectly?

I moved the definition to <div class="icon" tal:define="..."> as per Mathias' suggestion.
Then got the error
Expression: <PathExpr standard:u'context/resource_type'>
Names:
{'container': <PloneSite at /hccrems>,
'context': <Collection at /hccrems/our-products/our-products/hccrems-purchasable-products/products>,
'default': <object object at 0xb72c66a8>,
'here': <Collection at /hccrems/our-products/our-products/hccrems-purchasable-products/products>,
'loop': {u'item': <Products.PageTemplates.Expressions.PathIterator object at 0xb3dacf6c>},
And noticed that 'context' refers to the collection while item is an object, so I changed it to tal:define=" resource_type item/resource_type;
And now it's good.

Related

EF Core Value Converter Usage: Type vs Instance

I have a simple value converter (ValueConverter<List<string>, string>) for a property. The code is not important, but it turns a semicolon delimited list of strings into a string array. I want to apply it to a List<string> property so that my colon-delimited database-stored column can be turned into an array of strings in .NET.
If I apply it like this, it works:
builder.Property(x => x.Pictures)
.HasColumnName("Pictures")
.HasColumnType("nvarchar(max)")
.HasConversion(new SemicolonValuesConverter());
But if I apply it like this, it doesn't:
builder.Property(x => x.Pictures)
.HasColumnName("Pictures")
.HasColumnType("nvarchar(max)")
.HasConversion<SemicolonValuesConverter>();
Class SemicolonValuesConverter is public, has a public parameterless constructor and inherits from ValueConverter<List<string>, string>. As I said, it works just fine if I pass an instance, but not if I pass the type.
The error I get is:
System.InvalidOperationException: The property 'Venue.Pictures' is of type 'List< string >' which is not supported by the current database provider. Either change the property CLR type, or ignore the property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

Kotlin reflection: findAnnotation<Type>() returns null

I have the following data class:
data class Foo(#field:Password val password: String)
Why does Foo::password.annotations return an empty list?
Also, Foo::password.findAnnotation<Password>() returns null.
The same happens when I use an instance of Foo:
Foo("")::password.annotations
Foo("")::password.findAnnotation<Password>()
However, this java variant works: Foo::password.javaField.getAnnotation(Password::class.java).
This is on kotlin version 1.3.10.
The docs don't give much information on the inner workings of findAnnotation.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-property/index.html
fun <T : Annotation> KAnnotatedElement.findAnnotation(): T?
Returns an annotation of the given type on this element.
What am I missing here?
Thanks in advance!
Foo::password.annotations is the list of annotations on the property. In your code, you've used the #field: use site target, which means that the annotation is applied to the backing field, not the property. Therefore, the list of annotations on the property is empty.
The Java variant works because it loads the list of annotations on the field.

spring validator without using properties file for show error messages

I want configuration for show error messages on jsp using spring validator,but without using this configuration for message.properties.
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>message</value>
</list>
</property>
</bean>
error.rejectValue(String field,
String errorCode,
Object[] errorArgs,
String defaultMessage)
Register a field error for the specified field of the current object (respecting the current nested path, if any), using the given error description.
The field name may be null or empty String to indicate the current object itself rather than a field of it. This may result in a corresponding field error within the nested object graph or a global error if the current object is the top object.
Parameters:
field - the field name (may be null or empty String)
errorCode - error code, interpretable as a message key
errorArgs - error arguments, for argument binding via MessageFormat (can be null)
defaultMessage - fallback default message
reference link
Use
error.rejectvalue with three parameters("name of path variable" , "any name" , "message you want to show");
just like
error.rejectvalue("Name", "msg.name", "please enter name");

function return type issue

According to the w3c
An ElementTest is used to match an element node by its name and/or type annotation. An ElementTest may take any of the following forms. In these forms, ElementName need not be present in the in-scope element declarations, but TypeName must be present in the in-scope schema types [err:XPST0008]. Note that substitution groups do not affect the semantics of ElementTest.
...
element(*, TypeName) matches an element node regardless of its name, if derives-from(AT, TypeName ) is true, where AT is the type annotation of the element node, and the nilled property of the node is false.
I have this function
import schema namespace cdm-base="http://cdm.basic.upc.com" at "file:///Workspace/peal/peal40/trunk/common/schema/cdm-basic.xsd";
declare function local:matchType(
$input as element()
) as element(*,cdm-base:ProductComponent..) {
<cdm-base:product xsi:type="cdm-base:ProductComponent" />
};
which while I am typing returns the error:
F [Saxon-EE XQuery 9.3.0.5] Required item type of result of function local:matchType() is element(*, ProductComponent); supplied value has item type element({http://cdm.basic.upc.com}product, {http://www.w3.org/2001/XMLSchema}untyped)
I may mistaken, but the type is actually cdm-base:ProductComponent and not untyped.
I don't get where the issue is...
I am Using Oxygen 13.0 with Saxon EE 9.3.0.5
Saxon is indeed correct here, all directly constructed ("inline") elements have the type xs:untyped (or xs:anyType if the construction mode is set to preserve).
The xsi:type element is meaningless until the element has been validated against your schemas. The easiest way to do this is to wrap the element in a validate expression:
import schema namespace cdm-base="http://cdm.basic.upc.com" at "file:///Workspace/peal/peal40/trunk/common/schema/cdm-basic.xsd";
declare function local:matchType(
$input as element())
as element(*,cdm-base:ProductComponent)
{
validate { <cdm-base:product xsi:type="cdm-base:ProductComponent" /> }
};
Note that in XQuery 3.0, if you do not actually need the xsi:type attribute then you can validate the element as a particular type:
import schema namespace cdm-base="http://cdm.basic.upc.com" at "file:///Workspace/peal/peal40/trunk/common/schema/cdm-basic.xsd";
declare function local:matchType(
$input as element())
as element(*,cdm-base:ProductComponent)
{
validate type cdm-base:ProductComponent { <cdm-base:product /> }
};

Populate ArrayCollection with HTTPService

Yes there is a question like this one, but there is no activity and no answer.
I want to load data from a external XML file, using a HTTPService, and on the ResultEvent of the same HTTPService i want him to populate a ArrayCollection with the data from the XML.
I think a ArrayCollection is the ideal for this XML. but I'm open to suggestions.
XML
<?xml version="1.0" encoding="utf-8"?>
<PhotoGalleryData>
<Photo>
<id>1</id>
<name>Summer Vacation</name>
<description>In vacation</description>
<source>vacation.JPG</source>
</Photo>
<Photo>
<id>2</id>
<name>Winter Vacation</name>
<description>coold</description>
<source>vacation2.JPG</source>
</Photo>
</PhotoGalleryData>
I thought that this simple line in getDataResultHandler(), would be enough to populate the ArrayCollection.
<mx:HTTPService id="getData"
url="{XMLDataFileLocation}"
fault="getDataFaultHandler()"
result="getDataResultHandler()"/>
[Bindable]
private var PhotoData:ArrayCollection;
private function getDataResultHandler():void
{
PhotoData = new ArrayCollection(getData.lastResult.PhotoGalleryData.photo)
}
But i guess it isn't, because just to be sure i have placed a List binded to the ArrayCollection to actually see if it really was populated.
<mx:List dataProvider="{PhotoData}" labelField="name"/>
And the list didn't showed any data, so isn't working as supposed to be.
Thanks for any help.
EDIT
NOTE
The <mx:List/> used is just to be
sure that the ArrayCollection is
indeed populated, it won't be used in
the App.
Results taking Bozho advice.
With Bozho changes Flex doesn't report the var type error any more, but once i run it. Adobe flash does report this.
TypeError: Error #1034: Type Coercion
failed: cannot convert
mx.utils::ObjectProxy#22cd311 to
mx.collections.ArrayCollection. at
PhotoGallery/getDataResultHandler()[C:\Users\Fábio
Antunes\Documents\Flex Builder 3\Photo
Gallery\src\ActionScripts\PhotoGallery.as:56]
at
PhotoGallery/__getData_result()[C:\Users\Fábio
Antunes\Documents\Flex Builder 3\Photo
Gallery\src\PhotoGallery.mxml:23] at
flash.events::EventDispatcher/dispatchEventFunction()
at
flash.events::EventDispatcher/dispatchEvent()
at
mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\http\mxml\HTTPService.as:290]
at
mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:193]
at
mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43]
at
mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
at
DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:403]
at
flash.events::EventDispatcher/dispatchEventFunction()
Well and the line 23 that Flash reports the error its:
PhotoData = ArrayCollection(event.result);
Line 23 is:
result="getDataResultHandler(event)"
If you can use an XMLListCollection in place of an ArrayCollection the process of converting the result object is more straightforward. Here is a good tutorial explaining how to go about this.
EDIT:
The key things to get from this tutorial are this:
you need to set the result format of the service to e4x.
you need to cast the result object as XML object, extract the repeating nodes as an XMLList, and construct an XMLListCollection from the list like so:
private function httpService_result(evt:ResultEvent):void
{
var xmlList:XMLList = XML(evt.result).path.to.repeating.element;
xmlListColl = new XMLListCollection(xmlList);
}
You can simplify your script like this:
<mx:HTTPService id="getData" url="{XMLDataFileLocation}"/>
<mx:List dataProvider="{getData.lastResult.Photo}" labelField="name"/>
The lastResult of your getData will be the root of your XML. By retrieving lastResult.Photo you'll get an XMLList of the photos.

Resources