Unable to bind 'foo' on class 'Foo' - flex4

I know the 'unable to bind msg' has been asked before but I think in my case is different...
When my application is running on debug mode I get some warnigs I'm not sure how I can solve...
[trace] warning: unable to bind to property 'nonCreditRelevantLabel' on class 'com.company.model::Counterparty'
[Bindable]
[RemoteClass(alias="com.company.model.Counterparty")]
public class Counterparty extends CounterpartyBase {
public function get nonCreditRelevantLabel():String {
return nonCreditRelevant == '1' ? 'Yes' : 'No';
}
}
I understand that this is a getter, but there is no field as such. It contains some logic for the nonCreditRelevant field which is in CounterpartyBase and also exists in com.company.model.Counterparty on the java side.
I have this in a couple of places, is there a workaround for this?
Thanks

Binding read-only accessors in Flex
http://www.rubenswieringa.com/blog/binding-read-only-accessors-in-flex

Related

Hot Chocolate - Is it possible to implement my own object type with generics?

I wrote the following object type class.
public class ResponseType<T> : ObjectType<ResponseEntry<T>>
{
protected override void Configure(IObjectTypeDescriptor<ResponseEntry<T>> descriptor)
{
descriptor.Name("Response");
}
}
I want to use it like this as the outermost type in the resolver definition.
descriptor.Field<SharedResolvers>(r => r.GetObject1(default, default, default, default))
.Type<ResponseType<ListType<Object1>>>()
.Name("object1");
descriptor.Field<SharedResolvers>(r => r.GetObject2(default, default, default, default))
.Type<ResponseType<ListType<Object2>>>()
.Name("object2");
This code works if I only implement object1 however as soon as I add object2 I get the following error.
System.Collections.Generic.KeyNotFoundException: 'The given key 'HotChocolate.Configuration.RegisteredType' was not present in the dictionary.'
It seems as though there may be some issue with declaring two resolvers of the same class type. Is that the case? And if so, what are my options?
I was able to resolve the issue by setting the descriptor.Name to a unique value based on T.
descriptor.Name($"Response_{typeof(T).GetHashCode()}");
Then I realized my real issue was that I was defining the name at all. If you don't override the name it automatically comes up with a unique name/key based on the type definition.

Grails Domain Class with Inheritance fails to set errors after validate

I am experiencing a very strange behaviour in some of our domain classes after upgrading vom grails 2.1.4 to 2.3.11.
The Domain Objects i am talking about use inheritance and also has embedded properties.
Here is a simple outline of the structure we are using
abstract class A {
String normalProperty
ComplexType embeddedProperty
static embedded = [ 'embeddedProperty' ]
}
class B extends A {
String someMoreProperties
static hasMany = [ cs: C ]
}
class C extends A {
String evenMoreProperties
static belongsTo = [ b: B ]
}
I can save a instance of B without errors.
When i try to create a C object and add it to the list in B and save B i will get the following error:
Caused by: java.lang.NullPointerException
at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod.setupErrorsProperty(AbstractDynamicPersistentMethod.java:100)
at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractSavePersistentMethod.doInvokeInternal(AbstractSavePersistentMethod.java:156)
at org.codehaus.groovy.grails.orm.hibernate.metaclass.AbstractDynamicPersistentMethod.invoke(AbstractDynamicPersistentMethod.java:63)
at org.codehaus.groovy.grails.orm.hibernate.HibernateGormInstanceApi.save(HibernateGormInstanceApi.groovy:196)
I investigated the issue and found out that validation is no longer working.
If I call b.validate() or c.validate() b.errors and c.errors will still be null.
This is causing the null pointer exception on save.
The odd thing is that there will be an errors Object when there is an actual validation error in the object, its only null when validation is passed.
Usually when you validate an entity the errors field will have the value of a grails.validation.ValidationError Object. However for my B and C objects the error field will be either null if there was no error or org.springframework.validation.BeanPropertyBindingResult if there was an validation error.
Any help or pointers are greatly appreciated .

Pivot items with caliburn.micro

I am trying to use the caliburn.micro Conductor. According to the docs, a Conductor doesn't necessarily need to be of type Screen, it can actually be any POCO.
So I create my class like this:
public class StoreContentsViewModel : Conductor<MyItem>.Collection.OneActive
{
protected override void OnInitialize()
{
...
foreach (MyItem item in Collection)
{
Items.Add(item);
}
ActivateItem(Items[0]);
}
}
but I get a binding error
System.Windows.Data Error: BindingExpression path error: 'Items' property not
found on 'MyItem' (HashCode=107597610). BindingExpression: Path='Items'
DataItem='MyItem' HashCode=107597610); target element is
Microsoft.Phone.Controls.Pivot' (Name='Items'); target property is
ItemsSource' (type 'System.Collections.IEnumerable')..
I thought that it was Conductor the class that implements Items list, but caliburn is trying to bind MyItem. Why is that?
I want to have a Pivot, which receives a list of MyItem in the bindable property Items, and displays them according to an ItemTemplate I defined. Do I need a ViewModel for this??
I've read the documentation several times but I am still lost, could you please explain me what's happening?
Found the problem!
I was setting a DataContext in the Grid that contains the Pivot, overwriting the convention DataContext which is the ViewModel. I deleted that and worked perfect.
So, it is true that you can use any POCO in a Conductor.

MVC ExecuteQuery not a valid method on Context object

I am trying to execute a sql command directly against the database. However, intellisense does not see ExecuteQuery as a valid method against my context variable. I am sure I am missing something obvious.
My context class:
public class CatastropheContext : DbContext
{
public DbSet<CLIENT> CLIENTs { get; set; }
...
}
My attempt to establish the query:
CatastropheContext db = new CatastropheContext();
IEnumerable<ClientClaim> = db.ExecuteQuery
In the code above, ExecuteQuery is flagged as invalid an intellisense suggests creating a stub method.
Can you use Database.ExecuteSqlCommand where Database comes from the DbContext class.
This seems to me like you are missing some references. Make sure you are:
using System.Data.Linq;
Here is the MSDN reference on ExecuteQuery. Notice the namespace.

Filter select drop down using Grails security ACL

I am implementing ACL security using the spring-security-acl plugin. I have the following domain classes:
package test
class Subitem {
String name
static belongsTo = [employer: Employer]
static constraints = {
name blank: false
}
}
package test
class Employer {
String name
static hasMany = [users: User, items: Subitem]
static belongsTo = User
static constraints = {
name blank: false, unique: true
}
String toString() {
name
}
}
In the create.gsp file which is used to create a Subitem, there is the following statement:
<g:select id="employer" name="employer.id" from="${test.Employer.list()}" optionKey="id" required="" value="${subitemInstance?.employer?.id}" class="many-to-one"/>
From the EmployerController:
def list = {
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[employerInstanceList: employerService.list(params),
employerInstanceTotal: employerService.count()]
}
Following the tutorial given here, I have moved some of the functionality with dealing with Employer to a service called EmployerService:
#PreAuthorize("hasRole('ROLE_USER')")
#PostFilter("hasPermission(filterObject, read)")
List<Employer> list(Map params) {
Employer.list params
}
int count() {
Employer.count()
}
Access to information in any given Employer class instance is restricted using ACL. At present, I can see ALL instances of Employer in the database in the drop down, and I assume that is because I am using the controller list(), not the service list() - however, I only want to see the filtered list of Employer domain classes. However, if I replace the g:select with:
<g:select id="employer" name="employer.id" from="${test.EmployerService.list()}" optionKey="id" required="" value="${subitemInstance?.employer?.id}" class="many-to-one"/>
then I get an internal server error because I haven't passed a Map parameter to the service list() function (and I don't know how to do this within the tag):
URI /security/subitem/create
Class groovy.lang.MissingMethodException
Message No signature of method: static test.EmployerService.list() is applicable for argument types: () values: [] Possible solutions: list(java.util.Map), is(java.lang.Object), wait(), find(), wait(long), get(long)
I only want to see the information that comes from the EmployerService list() function - how do I do this please? How do I reference the correct function from within the gap?
Edit 16 Mar 0835: Thanks #OverZealous, that's really helpful, I hadn't realised that. However, I've tried that and still get the same problem. I've put a println() statement in both the Employer and EmployerService list() functions, and can see that neither actually seems to get called when the g:select tag is parsed (even if I leave the g:select to refer to Employer). Is there another version of the list() function that is being called perhaps? Or how else to get the g:select to take account of the ACL?
Just change your method signature in the Service to look like this:
List<Employer> list(Map params = [:]) {
Employer.list params
}
The change is adding this: = [:]. This provides a default value for params, in this case, an empty map.
(This is a Groovy feature, BTW. You can use it on any method or closure where the arguments are optional, and you want to provide a default.)
OK, I worked it out, and here is the solution to anyone else who comes up against the same problem.
The create Subitem page is rendered by means of the Subitem's create.gsp file and the SubitemController. The trick is to amend the SubitemController create() closure:
class SubitemController {
def employerService
def create() {
// this line was the default supplied method:
// [subitemInstance: new Subitem(params)]
// so replace with the following:
params.max = Math.min(params.max ? params.int('max') : 10, 100)
[subitemInstance: new Subitem(params), employerInstanceList: employerService.list(params),
employerInstanceTotal: employerService.count()]
}
}
So now when the SubitemController is asked by the g:select within the Subitem view for the list of Employers, it calls the EmployerService, which supplies the correct answer. We have simply added 2 further variables that are returned to the view, and which can be referenced anywhere within the view (such as by the g:select tag).
The lesson for me is that the View interacts with the Controller, which can refer to a Service: the Service doesn't play nicely with a View, it seems.

Resources