How to set default value for double type field in JavascriptObject? - gwt

I have a JavaScriptObject like this:
#SingleJsoImpl(Test1Impl.class)
public interface Test1
{
double getValue();
void setValue(String Value);
}
public class Test1Impl extends JavaScriptObject implements Test1
{
protected Test1Impl()
{
}
#Override
public final native double getValue()/*-{
return this.Value||(this.Value=0);
}-*/;
#Override
public final native void setValue(String Value)/*-{
this.Value = Value;
}-*/;
}
And I want to use this:
return this.Value||(this.Value=0);
to set default value,but when I test it
public class GWT_Test implements EntryPoint{
public static native void log(Object message)/*-{
console.log(message);
}-*/;
#Override
public void onModuleLoad()
{
Test1 t1=(Test1) Test1Impl.createObject();
log(t1.getValue());
}
}
I got these erros:
com.google.gwt.core.client.JavaScriptException: (null) #com.gwt.test.client.GWT_Test::log(Ljava/lang/Object;)([Java object: java.lang.Double#239824989]): null
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:304)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.dsc.gwt.test.client.GWT_Test.log(GWT_Test.java)
at com.dsc.gwt.test.client.GWT_Test.onModuleLoad(GWT_Test.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:411)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Thread.java:744)
So what is the problem here? Or
How to set default value for double type field?
Update:
#Override
public void onModuleLoad()
{
Test1 t1=(Test1) Test1Impl.createObject();
printDouble(t1.getValue());
}
private void printDouble(Double num){
log(num.toString());
}
and this
#Override
public void onModuleLoad()
{
Test1 t1=(Test1) Test1Impl.createObject();
log(Double.toString(t1.getValue()));
}
Worked as I expected,and can anybody explain first line of error messages?
com.google.gwt.core.client.JavaScriptException: (null)#com.gwt.test.client.GWT_Test::log(Ljava/lang/Object;)([Java object: java.lang.Double#239824989]): null

The error you're seeing is the JS equivalent to a NullPointerException.
GWT runs in an iframe, an depending on browsers iframes don't always have a console object. Use $wnd.console to reference the console of the top window, where your widgets et al. live.

Related

Gwtp Autobean and rest

I have InfraNameModel (Rest-type) to work with JSON
public interface IInfraNameBeanFactory extends AutoBeanFactory {
IInfraNameBeanFactory INSTANCE = GWT.create(IInfraNameBeanFactory.class);
AutoBean<InfraNameModel> infraName();
AutoBean<InfraNameListModel> results();
}
public interface InfraNameListModel {
List<InfraNameModel> getResults();
void setResults(List<InfraNameModel> results);
}
public class InfraNameListModelImpl implements InfraNameListModel {
private List<InfraNameModel> results;
#Override
public List<InfraNameModel> getResults() {
return results;
}
#Override
public void setResults(List<InfraNameModel> results) {
this.results = results;
}
}
public interface InfraNameModel {
String getInfraName();
void setInfraName(String infraName);
}
public class InfraNameModelImpl implements InfraNameModel {
private String infraName;
#Override
public String getInfraName() {
return infraName;
}
#Override
public void setInfraName(String infraName) {
this.infraName = infraName;
}
}
I wanted to make them into a separate JAR
To make it common for the client and the server
But now I have errors
[WARN] Class by.models.infraNameModel.InfraNameModel is used in Gin, but not available in GWT client code.
Is it real to pull such beans into a separate library?

Bulk operations in CassandraRepository for spring-data-cassandra 2.0M1

I have a simple spring-data-cassandra project that tries to insert multiple entities using
<S extends T> Iterable<S> save(Iterable<S> entities)
of the CassandraRepository class.
However when I use version 2.0.0.M1 (works in previous versions), I get the following error,
Exception in thread "main" org.springframework.data.cassandra.mapping.VerifierMappingExceptions: java.util.ArrayList:
- Cassandra entities must be annotated with either #Persistent, #Table, #UserDefinedType or #PrimaryKeyClass
at org.springframework.data.cassandra.mapping.CompositeCassandraPersistentEntityMetadataVerifier$PersistentAnnotationVerifier.verify(CompositeCassandraPersistentEntityMetadataVerifier.java:92)
at org.springframework.data.cassandra.mapping.CompositeCassandraPersistentEntityMetadataVerifier.verify(CompositeCassandraPersistentEntityMetadataVerifier.java:70)
at org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntity.verify(BasicCassandraPersistentEntity.java:160)
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:332)
at org.springframework.data.cassandra.mapping.BasicCassandraMappingContext.addPersistentEntity(BasicCassandraMappingContext.java:381)
at org.springframework.data.cassandra.mapping.BasicCassandraMappingContext.addPersistentEntity(BasicCassandraMappingContext.java:65)
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:185)
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:145)
at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:70)
at org.springframework.data.cassandra.core.CassandraTemplate.getPersistentEntity(CassandraTemplate.java:427)
at org.springframework.data.cassandra.core.CassandraTemplate.getTableName(CassandraTemplate.java:443)
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:314)
at org.springframework.data.cassandra.core.CassandraTemplate.insert(CassandraTemplate.java:302)
at org.springframework.data.cassandra.repository.support.SimpleCassandraRepository.save(SimpleCassandraRepository.java:66)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.executeMethodOn(RepositoryFactorySupport.java:553)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:538)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:479)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy34.save(Unknown Source)
My main class, App.java
public class App
{
public static void main(String[] args) {
ApplicationContext context =new AnnotationConfigApplicationContext(CassandraConfig.class);
CustomerRepo repo=context.getBean(CustomerRepo.class);
List<Customer> customers=new ArrayList<Customer>();
Customer cust=new Customer();
cust.SetId("142");
cust.setName("Mayor");
cust.setAcc_type("new");
cust.setAcc_name("savings");
cust.setSegment("Normal");
customers.add(cust);
Customer cust1 = new Customer();
cust1.SetId("143");
cust1.setName("Final");
cust1.setAcc_type("new");
cust1.setAcc_name("savings");
cust1.setSegment("Normal");
customers.add(cust1);
repo.save(customers);
}
}
The entity class, Customer.java
#Table(value="Customer")
public class Customer {
#PrimaryKeyColumn(name = "id",ordinal = 1,type = PrimaryKeyType.PARTITIONED)
private String id;
#Column(value ="name")
private String name;
#Column(value = "acc_name")
private String acc_name;
#Column(value = "acc_type")
private String acc_type;
#Column(value = "segment")
private String segment;
public Customer(String id, String name, String acc_name, String acc_type,
String segment) {
this.id=id;
this.name=name;
this.acc_name=acc_name;
this.acc_type=acc_type;
this.segment=segment;
}
public Customer() {
}
public void SetId(String id)
{
this.id=id;
}
public void setName(String name)
{
this.name=name;
}
public void setAcc_name(String acc_name)
{
this.acc_name=acc_name;
}
public void setAcc_type(String acc_type)
{
this.acc_type=acc_type;
}
public void setSegment(String segment)
{
this.segment=segment;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getAcc_name() {
return acc_name;
}
public String getAcc_type() {
return acc_type;
}
public String getSegment() {
return segment;
}
}
And finally, the repository, CustomerRepo.java
import com.Entity.Customer;
public interface CustomerRepo extends CassandraRepository<Customer> {
}
Is this an issue (I haven't been able to find via Goolge or the site), or am I missing some annotations ?
For batch queries, use CassandraTemplate helps to insert batch of operations with multiple entities. This is available with Spring Data Cassandra.
example code:
CassandraBatchOperations batchOps = cassandraTemplate.batchOps();
batchOps(movieByGenre);
batchOps(movieByActor);
batchOps.insert(movie);
batchOps.execute();
This will use Cassandra native Batch operation internally.

How to create an instance of A class that extends Application

I just designed a simple javaFx app. While running it solo works, but when I try to separated and create an instance of it all I get :
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
... 1 more
my code
import javafx.application.Application;
import javafx.stage.Stage;
public class Demo
{
public static void main(String[] args)
{
Demos dm = new Demos();
}
}
class Demos extends Application {
private String args;
private Stage stage;
public Demos()
{
main(args);
start(stage);
}
public void main(String args)
{
this.args=args;
launch(this.args);
}
#Override
public void start(Stage stage)
{
this.stage=stage;
this.stage.setTitle("Simple JavaFX Application");
this.stage.setResizable(false);
this.stage.show();
}
}
Application.launch requires the Application class to be lauched to be public. This is not the case for your Demos class.
Additional Notes
private String args;
private Stage stage;
public Demos()
{
main(args);
...
}
public void main(String args)
{
this.args=args;
...
}
Just assigns the initial value of args to itself, which will always result in args remaining null.
Application.launch is a static method creating the Application instance itself. Calling this form from a instance makes little sense.
If you want to launch a specific Application, pass the Application class to Application.launch:
public static void main(String[] args) {
Application.launch(Demos.class);
}
public Demos extends Application {
private Stage stage;
public Demos(){
}
#Override
public void start(Stage stage) {
this.stage=stage;
this.stage.setTitle("Simple JavaFX Application");
this.stage.setResizable(false);
this.stage.show();
}
}

UiEditor/RequestFactory generate null delegate on ValueProxy

I have a Service.class ValueProxy in a service oriented architecture (i have a server method like "storeService(service)".
I would use an Editor with RequestFactoryEditorDriver.
I expect all work, but when i call driver.edit(service) i get a null delegate exception.
Why? It's a bug?
At http://crazygui.wordpress.com/tag/editor/ i find a sample of implementation...only differece with mine is SimpleBeanRequestEditorDriver.class (i have RequestFactoryEditorDriver.class)
ServiceEditor.class
public class ServiceEditor extends Composite implements Editor<ServiceProxy>{
private static final Logger logger = Logger.getLogger(ServiceEditor.class.getName());
private static ServiceEditorUiBinder uiBinder = GWT
.create(ServiceEditorUiBinder.class);
interface ServiceEditorUiBinder extends
UiBinder<Widget, ServiceEditor> {
}
//~Driver ==========================================================================================================================
interface Driver extends RequestFactoryEditorDriver<ServiceProxy, ServiceEditor> {
}
Driver driver;
//====================================================================================================================================
#UiField
Decorator<String> name;
#UiField
Decorator<String> description;
#UiField
Decorator<String> notes;
#UiField
Decorator<String> citiesString;
// #UiField(provided=true)
// Decorator<String> category;
// MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
// #UiField(provided=true)
// #Ignore
// SuggestBox suggestBox = new SuggestBox(oracle);
private BigInteger organizationId;
private EditorDelegate<ServiceProxy> delegate;
public ServiceEditor() {
initWidget(uiBinder.createAndBindUi(this));
driver = GWT.create(Driver.class);
}
#Override
protected void onLoad() {
driver.initialize(ClientFactory.AppInjector.getRequestFactory(),this);
}
public void edit() {
ServiceRequestContext requestContext = ClientFactory.AppInjector.getRequestFactory().getNewServiceContext();
edit(requestContext.create(ServiceProxy.class),requestContext);
}
public void display(ServiceProxy p){
driver.display(p);
}
public void edit(ServiceProxy p) {
ServiceRequestContext requestContext = ClientFactory.AppInjector.getRequestFactory().getNewServiceContext();
edit(p,requestContext);
}
public void edit(ServiceProxy service,ServiceRequestContext requestContext) {
if(service.getToken()==null) {
requestContext.addServiceToOrganization(organizationId, service);
//TODO: attenzione a tempistiche chiamate;
SessionRPC.Util.getInstance().getOrganizationId(new AsyncCallback<BigInteger>() {
#Override
public void onSuccess(BigInteger result) {
organizationId = result;
}
#Override
public void onFailure(Throwable caught) {
}
});
}
else
requestContext.updateService(service);
driver.edit(service,requestContext);
}
public RequestContext flush2(){
return driver.flush();
}
public void submit(Receiver<Void> receiver){
RequestContext context = driver.flush();
if (driver.hasErrors()) {
Window.alert("Driver errors!");
return;
}
context.fire(receiver);
}
public void notifyErrors(Set<ConstraintViolation<?>> violations) {
driver.setConstraintViolations(violations);
//driver.getErrors().get(0).
logger.info("Validation Errors: /n "+driver.getErrors().toString());
}
// #Override
// public void setDelegate(EditorDelegate<ServiceProxy> delegate) {
// this.delegate = delegate;
// }
}
ActivitySnippet...
ServiceEditor serviceEditor = GWT.create(ServiceEditor.class);
serviceEditor.display(response);
Stack trace...
Caused by: com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot set property 'request' of undefined
at Unknown.$collect(JsArrayString.java:42)
at Unknown.fillInStackTrace_2(StackTraceCreator.java:180)
at Unknown.fillInStackTrace_0(StackTraceCreator.java:518)
at Unknown.fillInStackTrace(Throwable.java:115)
at Unknown.Throwable_0(Throwable.java:51)
at Unknown.Exception_0(Exception.java:25)
at Unknown.RuntimeException_0(RuntimeException.java:25)
at Unknown.JavaScriptException_1(JavaScriptException.java:117)
at Unknown.JavaScriptException_0(JavaScriptException.java:109)
at Unknown.getCachableJavaScriptException(Exceptions.java:45)
at Unknown.wrap(Exceptions.java:29)
at Unknown.$setRequestContext(RequestFactoryEditorDelegate.java:80)
at Unknown.$edit(AbstractRequestFactoryEditorDriver.java:168)
at Unknown.display_0(AbstractRequestFactoryEditorDriver.java:159)
at Unknown.$show_2(ServiceEditor.java:91)
This means that getDelegate() method (line 168 of AbstractRequestFactoryEditorDriver.class) return null.
If you call RequestFactoryEditorDriver.show, it essentially just calls RequestFactoryEditorDriver.edit, but without a requestcontext. This otherwise should follow the same basic path in terms of how the driver needs to be wired up.
In this case, if the delegate is null, then the driver hasn't been initialized. From your code:
public ServiceEditor() {
initWidget(uiBinder.createAndBindUi(this));
driver = GWT.create(Driver.class);
}
#Override
protected void onLoad() {
driver.initialize(ClientFactory.AppInjector.getRequestFactory(),this);
}
public void edit() {
ServiceRequestContext requestContext = ClientFactory.AppInjector.getRequestFactory().getNewServiceContext();
edit(requestContext.create(ServiceProxy.class),requestContext);
}
public void display(ServiceProxy p){
driver.display(p);
}
You never listed the code that shows when edit or display are being called, so I'm mostly guessing here, but it looks like your other code looks roughly like this:
ServiceEditor editor = new ServiceEditor();//create ui, create driver.
editor.display(data);//driver.display, which calls driver.edit
parentWidget.add(editor);// causes onLoad to be called if actually
//attached to the dom, which causes driver.initialize
This is wrong. The driver must be initialized before you attempt to edit or display, since otherwise it doesn't know which editor objects it should be working with.
Instead, move driver.initialize to earlier than onLoad, like in the ServiceEditor constructor itself, or in some init method which allows you to call it earlier deliberately. Another option is to just call parent.add(editor) before editor.display(), though this may not work - make sure you understand what causes onLoad to be called.
(Please note that ServiceEditor.show is in your stack trace but not in your code listing, so I can't tell if the chance would be more obvious in seeing this.)

smartgwt + gin Code Splitting

I am looking for example to use code splitting with gin and smartgwt ...
In my simple application I have 2 modules AutoLoadModule and WindowModule. In my simple app I just need to load a window when some button is clicked.
My window module contains:
#Override
protected void configure() {
bind(MainWindow.class).in(Singleton.class);
}
and my MainWindow:
#Singleton
public class MainWindow extends Window implements SessionStatusChangedEvent.Handler {
private final XmppSession session;
#Inject
private MainWindow(XmppSession session) {
Log.debug("Constructor ImMainWindow... !");
this.session = session;
initComponent();
}
....................
In my AutoLoadModule I have bind AutoLoad asEagerSingleton();
#Override
protected void configure() {
bind(StartButton.class).toProvider(StartChatButtonProvider.class);
bind(AutoLoader.class).asEagerSingleton();
}
My AutoLoader class:
#Singleton
public class AutoLoader implements Scheduler.ScheduledCommand {
private final XmppConnection connection;
#Nullable
private final ImStartButton startButton;
#Inject
protected AutoLoader(final XmppConnection connection, final XmppSession session,
final StartButton startButton) {
this.startButton = startButton;
Scheduler.get().scheduleDeferred(this);
}
#Override
public final void execute() {
startButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
Log.debug("StartButton click handler...");
//load window in this point but how ? ....
}
});
}
}
Its possible to load a window instance using Code Splitting, when window is in WindowModule? In my example app I need load the window only on demand using code splitting and that window must be in a gin module.
Not sure where you want to split your code, but using gin you can take advantage of AsyncProviders and let git to split your code.
#Inject
protected AutoLoader(
final XmppConnection connection,
final XmppSession session,
final StartButton startButton,
final AsyncProvider<MainWindow> mainProvider) {
...
#Override
public final void execute() {
startButton.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
// Here Gin would split the code
mainProvider.get(new AsyncCallback<MainWindow>() {
public void onSuccess(MainWindow main) {
...
}
}
}
});
}