How to create new JSString (or other type) from createObject? - jxbrowser

The last version of jxBrowser brings the createObject() method in JSContext. I´d like to create a String (or other types) directly from java. How can I use the createObject method to do that?
I´m able to create an empty object without problem and even set it´s property, but I don´t know how to create a String or Array or any other type.
Thanks for any help!

Right now JSContext allows creating only JavaScript objects from Java. If you need to create a String or Array then you can use the following approach:
JSValue value = browser.executeJavaScriptAndReturnValue("'this is my string'");
JSString jsString = value.asString();

I´ve just tried to hack a bit into it...
Doing:
obj = jscontext.createObject()
obj.setProperty("constructor", Array)
obj.setProperty("__proto__", Array)
Will create an object that acts like an Array in javascript (if calling eval on this object), although it is not a JSArray.
This approach does not work for String. I guess String is a special type of constructor.

Related

ASP.Net QueryString Sort Parameter with Dojo JsonRest Memory Store

I have made a gridx grid that uses a JsonRest Memory store from the dojo framework
http://dojotoolkit.org/reference-guide/1.10/dojo/store/JsonRest.html
the issue is I do not know how to pull out the sort parameter from the query string.
The url being formatted from the JsonRest call is
/admin/sales?sort(+DealershipName)
using the following statement gives me a null error
String sort = Request.QueryString["sort"].ToString();
Looking at the debugger I see the following (I need more rep to post images :( )
ok I can see that the following variables hold this value.
Request.QueryString = {sort(+DealershipName)}
type : System.Collections.Specialized.NameValueCollection
{System.Web.HttpValueCollection}
but the array is null.
I'm thinking I can do two thing. Parse the string myself or overload the dojo JsonRest Memory store. Parsing the string seems easier but if anyone has any idea or knows any libraries that can help me out. I would greatly appreciate it.
dojo/store/JsonRest has a sortParam property that you can set to the name of a standard query parameter to use instead of sort(...) (which it uses by default to avoid colliding with any standard query parameters).
For example, adding sortParam: 'sort' to the properties passed to the JsonRest constructor will result in the query string including sort=+DealershipName instead.
http://dojotoolkit.org/reference-guide/1.10/dojo/store/JsonRest.html#sorting
If the + also presents a problem, you can also override ascendingPrefix to be an empty string (''). Note that descending sort will still be indicated by a leading - (controllable via descendingPrefix).

Which is better to use for adding IEnumerable object?

I have found two ways to implement add operation on IEnumerable objects in repository pattern.
First is to use .AddRange() & pass the list in here. Or
Second is to convert my list to Array & use .AddOrUpdate(ArrayObject).
Which is better to use if my intension is to remove foreach loop on IEnumerable items? Please help.
_context.DbSet<MyEntity>().AddOrUpdate(entities.ToArray());
Or
_context.DbSet<MyEntity>().ToList().AddRange(entities);
AddOrUpdate can be called with an array of new objects, so you can just create an array of type City[] and call context.CitySet.AddOrUpdate(cc => cc.Id, cityArray); once. In generated SQL, there should be Where condition.
In case of performance, you would like to read following
https://stackoverflow.com/a/21839455/194345
and look following:
context.BulkInsert(hugeAmountOfEntities);

How to store object types and create objects using that information only

I would like to store MetaObjects in a list like this:
myList = QList<QMetaObject>();
myList->append(MyClass::staticMetaObject);
myList->append(MyOtherClass::staticMetaObject);
I want to keep track of these object through out the application but I don't wish to allocate them just yet. By adding some information in my classes I will be able to use the MetaObject function "classInfo(int).value()". I use this when I store them in a QListWidget. When a row in the QListWidget is pressed I would like to be able to create an object of that specific kind that is stored in the list.
(Also have to add that all the classes dervies from the same baseclass)
This sample code describes a bit of what I want to do, except in his example, you add the classes as you go along.
http://lists.qt.nokia.com/pipermail/qt-interest/2012-January/037204.html
I read through the manual and when I try things like:
MyBaseClass *test = qobject_cast<MyBaseClass*>myList->at(i).newInstance();
The project compiles but when I try to print the "test" object its null. What am I doing wrong? And is this the best way of doing this?
Was also looking at MetaType, but where would i be able to store, for example a string for the menus if I'm not allowed to create the object? Would this be a nicer solution if I have a static function that returns a string?
Edit:
I now changed so the constructors are Q_INVOKABLE which solved the problem where "test == null".
But what are the downside of this solution? Should I just use a object factory (the old fashion way with a switch case)?

VTL evaluate or define an object reference

I would like to create a macro that takes a string as a parameter and evaluates that to an object. Something like:
#macro( valueTest $objRef)
#define( $obj )#evaluate("$${objRef}")#end
$obj.foo ## This would have to be translated to $obj.getFoo()
#end
Unfortunately the $obj variable does not point to object reference that could be used to call methods. $obj is a String and $obj.foo does not try to execute getFoo.
Somewhy I have a feeling that this is the nature of evaluate and it is not possible to do what I want to.
the reason why I want to do smth like this is because we have quite few macros that take both command bind path and command itself as a parameter and I am hoping the latter could be derived from first.
Unfortunately, Velocity does not have a mechanism to define functions which return object references. Macros are really intended to be a shortcut to display text.
In cases like this, the way to proceed is generally to create a "tool" in Java and put an instance in the context. A tool is just an ordinary class with a method that returns what you are looking for
e.g.
create an object with an "eval" method, then put it in the context as "referenceEvaluator".
#set($obj = $referenceEvaluator.eval($objRef))
You might find that your code is clearer if you avoid the double evaluation and just insert an object into the context named $obj that does what you want. (better performance, too).

How to use FormView in order to insert complex entity framework objects

I'm trying to use formview in order to do insert of a new entity object (called Customer)
Customer has a reference to another entity called Address.
How can I fill both of them in the same formview?
Thanks.
After looking more into it, it seems like the problem is in the ConvertProperties method of EntityDataSourceView.
Using reflector I've found out that the problem was in the line:
PropertyDescriptor pd = propertyDescriptors.Find(str, false);
(this codeline takes the inserted property name, and convert it to a descriptor)
when str = "Address.Address1" the function returns null.
I've took a look at propertyDescriptors.properties and it seems like Address.Address1 doesn't exist. Only Address.ID and Address exist.
I took a look at the population of propertyDescriptors and it seems like there is no way to change that. Or in other words, it seems like there is no solution to the problem.
bummer.
Actually there is a solution. Flatten the two objects into one. Create a CustomerViewModel object that includes all of the fields of the two objects. Then at databinding bind to the CustomerViewModel.

Resources