Grails GWT project , how to share dto classes from server to client - grails

I have created a grails+Gwt project with gwt plugin from grails.
I am able to run a hello world .
Next, I am trying to return some dto class from server to client.
But it always gets failed.
No source code is available for type domainclasses.UserEntity; did you forget to inherit a required module?
I have placed this entity/dto class in the domain package .
Also added in my Application.gwt.xml
<source path='domain.domainclasses'/>
I am unable to understand how to deal with/ where to place entity/dto classes in case of Grails/GWT Project
screenshot of my project structure:
http://screencast.com/t/JVRrTxto70
please guide.
thanks

Related

How do I create a grails 3 plugin which exposes a JSON view?

In my custom Grails plugin, how can I set up a JSON view for a non-domain class and get client apps to use it by default?
I have a view file in the plugin:
/views/com/mycompany/myplugin/myclass/_myClass.gson
When I do grails install, I can see that this .gson file is in the generated JAR. However, the client app is not using it.
What can I do to make it work?
Are there any settings or steps that can make troubleshooting easier?
I am using Grails 3.2.4.
Update:
When I copy the view into a client app, using the exact same path, the view is getting invoked. It's only when the view is defined in the plugin that the view cannot be found.
The framework seems to be trying to look up the plugin as a class from the classloader:
myclientproject_com_mycompany_myplugin_myclass__myClass_gson
How do I get my plugin to add this class to the classpath?
For my use case, what I actually needed was a custom converter.
See:
In JSON views, how do I flatten an object out as a single string?
This obviated the need for my plugin to publish a view.

WCF Service Library Configuration (App.config) And Webapplication Config(Web.config) Issue

I have a Service Client Library project which has its own
app.config
.
This project is referenced in my Web Application. The problem is My web application throws following exception
Could not find endpoint element with name 'HttpEndPoint' and contract 'ServiceLibReference1.IDalService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
There is nothing wrong with the service. If i directly refer my service in the web application it works fine as client configurations get added to the web.config. But my requirement is to keep it in a separate library project.
The reason for the exception is service configurations are not added to the web.config. Should i always add them manually? Should not VS add corresponding configurations into web.config whenever a service library is referenced? or am i missing something ?
thanks
Service libraries are, by design, intended to be used by (potentially) multiple different applications. Therefore, they don't use the app.config file included in the template - they will use the config file (web/app) of the application that is referencing them. This promotes code reuse - if you have certain methods that you are always using across multiple applications, it's easier to put them in a separate class library assembly. One benefit of that design is that you only need to change the code in one place to make the change effective for all using applications.
So yes, you will always need to add the service configuration to the specific application configuration file. Unfortunately, VS does not know to do this.

accessing internal Grails modules

My team suggests to modularize our current Grails project, so we experimented. We've started doing it through IntelliJ:
Projects > MyProject _right-click_ New > Module ..... create-app
Then we move each previously existing domain, controller, services, and view to their specific module.
When we run the project (through MyProject run-app -reloading), the pages that previously were accessible returns error 404. Now of course, we believe that is because the project directory is restructured. We attempt to access those pages from this old url:
http://localhost:8080/MyProject/someController
to this new url, assuming that it only needs to append the module name
http://localhost:8080/MyProject/the-new-module-name/someController
^ ^ ^ ^ ^ ^ ^ ^ ^ ^
But it still doesn't work. How do we suppose to run the project along with it's module and how can we access them? Do we need to configure some .config and .property files?
This is what the new project directory looks like:
MyProject
+.idea
+ grails-app
+ lib
.
.
.
- the-new-module
+.idea
+ grails-app
+ lib
.
.
.
+ web-app
+ wrapper
.
.
.
+ web-app
+ wrapper
edit: The reason the team wants to implement this "modular" approach is that our current Grails project can still be subdivided further into smaller, independent projects (for maintainability, etc.). Now, we have manage to create (and run) these smaller projects. The problem arises on consolidating these smaller pieces. So the task is to create a parent Grails project (is that even possible).
It would appear you're making the assumption that InteliJ "modules" are something that Grails understands. It does not.
The correct approach to making a modular Grails application is "plugins". Grails has great support for creating your own plugins. You can even create inline plugins which greatly speed up development. I highly recommend you read the official documentation regarding plugin creation and use in your Grails application.
Keep in mind that your plugin can have almost all the same artifacts as your application (services, domain classes, controllers, GSPs, etc.) but will appear under the same application as if the application using the plugin was providing the artifacts.
For example, if you have the BookController in your plugin it will have the same URL mapping as if the controller were a part of your base application. You indicate in your question that you wish to have different URLs for these controllers which are provided by your plugins. If that's the case then you need to namespace your controllers. You can read more about that in the official documentation too.
Update
In order to help visualize how plugins work with modular Grails applications:
/~/MyApp
/~/PluginA
/~/PluginB
MyApp is the main application (created using grails create-app). It has it's own functionality and includes both PluginA and PluginB (both created using grails create-plugin) to add their functionality to itself. You have the option of using inline plugins or even packaging the plugins and publishing them to your own internal repository for use by other applications (MyApp in this case). Notice that all three parts of this are separate. They can be modified independently of one another, versioned in your source control, managed, developed, etc.

Grails Plugin Development - override domain class

Plugins in Grails are great method to modularise an application.The documentation suggest to override the artifacts from the plugin in the application, which uses this plugin.
Is it realy the best approach?
Let's describe it by example: There is a domain class "org.User" defined in the plugin. The application overrides this domain class. If I use "grails run-app" then there are no warnings and it works. But Eclipse (GGTS) complains about "Invalid duplicate class definition of class org.User". For some developers it wouldn't matter, but I like the IDE helping on coding by stuf like "autocomplete".
At the end both classes are compiled an put on the java class loader. The application version of the class is loaded before the version of the plugin. The class resolver finds it first and that's why it works. Please correct me if I'm wrong at this point. Is it realy a good idea to have two versions of a class in one class loader?
What are the alternatives?
You can do like Spring Security Core plugin does, provide the User class as a template, so your application that use this plugin can choose between creating his own class or installing your default User class.
The plugin user template is here, and the script responsible to create this in the application is here.
You will need also a config value to know the class to use, and use it dynamic.
P.S: there are good security plugins like Shiro and Spring Security, maybe it's easier to check them instead of create your own.

What does WebActivator do?

This code was generated for me after added entity framework code-first for SQL Server CE using NuGet. They did no changes to any other file. The file SQLCEEntityFramework.cs was created and placed in App_Start folder.
Does this mean it automatically gets executed or something? The same thing happened when I added Ninject for MVC 3. No code was added to the global.ascx file so I have no idea if its plug and play or I have to configure something.
[assembly: WebActivator.PreApplicationStartMethod(typeof(StackTorrents.WebUI.App_Start.SQLCEEntityFramework), "Start")]
According to:
http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx
This new attribute allows you to have
code run way early in the ASP.NET
pipeline as an application starts up.
I mean way early, even before
Application_Start. This happens to
also be before code in your App_code
folder (assuming you have any code in
there) has been compiled. To use this
attribute, create a class library and
add this attribute as an assembly
level attribute. A common place to add
this would be in the AssemblyInfo.cs
class within the Properties folder.
To clarify, it gives you a way of hooking into several application start and application shutdown events WITHOUT having to change any existing code files (previously you had to edit Globals.asax.cs).
This is mostly a big deal when making packages as these events are really useful for bootstrapping Http modules and it is really difficult to write code into existing files.

Resources