Grails using a package to hold domain classes - grails

Grails question: Confused about using a package to hold domain classes.
I'm using Netbeans on Mac to check out Grails.
When I create domain classes without using a package holding it, I can just go to localhost:8080/gTunes and the expected .gsp page is rendered properly.
However when I use a package (com.g2one.gtunes) to hold a domain class (Song), I don't see the .gsp page when I go to localhost:8080/gTunes. Instead I see a Directory view of folders/files such as META-INF, WEB-INF, etc. In order to see the expected .gsp page, I have to type in the specific URL localhost:8080/gTunes/index.gsp
In my research I've seen people talk about adding the following line but I can't figure out where to add it.
<%#page import="path.to.domains.*"%>
Any help is appreciated.
Thank you.

You need to add that import to the top of your GSP pages that use the domain class that you put in a package. Don't forget you'll also need an import in your controllers unless that are in the same package.

Add the specified line as the very first line in the GSP you are trying to render (show).

Figured out why I way I was having this issue. I'm going through Definitive Guide to Grails 2nd Edt on mac with NetBeans. I ran into this problem when I
created 'gtunes' project at /Users/name/NetBeans/gtunes
deleted 'gtunes' project and /Users/name/NetBeans/gtunes
created another project with same name at /Users/name/NetBeans/gtunes. I type in some code and run it and I run into the error I posted.
To get around this error,
I create 'gtunes' project located at /Users/name/NetBeans/gtunes
I right click on 'gtunes' project in NetBeans, issue 'Clean' command. Than I see some files are removed from ~/.grails/... in Output window
I right click on Album.groovy (possibly Song.groovy also) and issue 'Generate Views', NOT 'Generate All'
Run the project and it works!
Thanks all for comments and hopefully my mistake will help others avoid same mistake.

Related

zend framework 2 projects conflict

I have a home server with 2 sites zf2 plus doctrine in a structure like this: var/www/site1 and var/www/site2 i think i have a conflict with namespaces. On one of two projects(site1) i receive:
Fatal error: Cannot redeclare class Doctrine\Common\Annotations\Annotation\Target in /var/www/site2/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php on line 31
what should i do to not try to load classes from other project?
Tank u.
So after a while i figure out what goes to this, is opcache from php, once i disable all zf2 project goes well. i don't know how to adjust to work with opcache enable
This error means you included the class Doctrine\Common\Annotations\Annotation\Target two times. It is difficult to say how you could achieve that.
Zend Framework 2 uses autoloading, so this type of error is typically impossible there. To install Doctrine, you use Composer dependency manager, and it creates all the autoloading configuration for you. But, if you then copy and paste the Composer-generated code in another project, you might have problem like yours.
The problem was from hosts file one site were to 127.0.0.1 and other to 192.168.10.20 i change and everything work normal

redmine-my-widgets-plugin not working on redmine 2.3.0

The following is the repository for redmine.
https://github.com/redmine/redmine
And the following is the repository for redmine-my-widgets-plugin
if we look at the file structure app/views/my
https://github.com/redmine/redmine/tree/master/app/views/my
there is a folder blocks which contains the partial which are widgets and displayed when added from select list.
similarly for redmine-my-widgets-plugin there is similar file directory structure
https://github.com/bradbeattie/redmine-my-widgets-plugin/tree/master/app/views/my
when i install this plugin the partials mentioned in this /my/block gets added in the my page -> select list so as to be added
When we add one of the plugins select list value then it displays 404 error
By looking at the structure the plugin, it looks like the plugin is overrided.
Also there are no others config files, or lib files present in the plugin(except en.yml)
So, what can be done that the plugin will be able to atleast find those partials.
Basically, redmine is able to find the partial files as the names are displayed in the my page -> select list but when added it throws 404 error
I know, I'm rather late to the party, but maybe this answer helps somebody else in the future.
The underlying problem was already covered at this question on SO. The plugin directory needs to have the exact same name as the symbol that is passed to Redmine::Plugin.register. In the case of this plugin: redmine_my_widgets. Changing the directory name will fix the 404.
On the other hand, the plugin was not updated for a long time and it is very likely, that most, if not all of the widgets, will no longer work because of changes to Redmine's internals.

grails-doc creates copies of my classes in default package

In my grails 1.3.7 project, I have put all of my classes in com.mycompany.myapp, as you do. So this goes for services, controllers, domain classes. I have a filter that goes in its own package. My app works fine.
However, when I run grails doc, grails decides to create two pages for every class:
one in its right comp.mycompany.myapp package that has all the right Groovy Doc
the other takes all the above classes and pretends as if those also live in the default package.
So, target/docs contains two directories: 'DefaultPackage' and 'com', with DefaultPackage holding a copy of everything that lives under com/
Consequently, my groovy doc looks messy because there is two copies for each class.
How can I solve this?
It has been documented as a bug at GRAILS-6605. There is no workaround listed there for the bug.
I too faced the same issue and so created a plugin "Grails Runtime Docs" ( http://grails.org/plugin/grails-runtime-docs ) that solves this issue and generates both Java and groovy docs properly only 1 copy per class. It's grails aware and categorizes the classes into Controllers, Commands, Domains, Services and Tag Libraries. The groovy documentation is actually generated from runtime so as to include the dynamic methods also, adding "Dynamic Method Summary" & "Dynamic Method Detail" in the generated html docs, that provide their source information. Hope you find it useful.

I cannot find the searchableController or the view for the Searchable plugin in Grails

I installed the searchable plugin on Grails and when I run my application I can browse to it and the searchable function works fine.
The only problem is that I cannot find the searchableController or even the view of it in my project. So I'm not able to edit anything or rewire the code to fit in another controller or view.
Any help would be much appreciated.
Kind regards.
The SearchableController and its views are located inside the searchable plugin, see $HOME/.grails/<version>/projects/<projectname>/plugins/searchable.
Be warned: it's a really bad idea to modify anything in $HOME/.grails manually unless you're sure what you're doing.
Instead you could either:
download the plugin from svn/git and reference it as 'inplace' plugin. If you don't know about inplace plugins, just google for it.
copy the SearchableController from $HOME/.grails to your project and modify it.

How to rename an existing Grails application

Does anybody know how to (easily) "rename" an existing grails application? I'm running into this because my PaaS provider does not allow me to delete a subscription... So I want to deploy my application under a different name.
Of course, I can do this manually, but I think it might be a useful 'top-level' script (i.e. "grails rename-app newappname")
Manual hints:
When I do a "grails create-app myappname" I can see the myappname exists in the following files (and filenames)... Of course this is done by the create-app script, which replaces #...# tokens in the template. I guess once they are replaced, it's not trivial to do a rename.
./.project: <name>myappname</name>
./application.properties:app.name=myappname
./build.xml:<project xmlns:ivy="antlib:org.apache.ivy.ant" name="myappname" default="test">
./ivy.xml: <info organisation="org.example" module="myappname"/>
./myappname-test.launch:<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="myappname"/>
./myappname.launch:<listEntry value="/myappname"/>
./myappname.launch:<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="myappname" path="1" type="4"/> "/>
./myappname.launch:<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="myappname"/>
./myappname.launch:<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dbase.dir="${project_loc:myappname}" -Dserver.port=8080 -Dgrails.env=development"/>
./myappname.tmproj: <string>myappname.launch</string>
And of course... the top-level directory name is "myappname"
Any hints, or information about ongoing initiatives in this area are welcome
Greetz,
Johan
I had to do this, I renamed my project top level directory to the new name and
edited the application.properties file. There is a line app.name=youroldappname which should be changed.
Actually, you do not even have to rename the directory. You could have a different web-app name.
Hmm, I know it doesn't look fun, but it shouldn't be difficult (just boring) to rename the project directory, then all the files with your project name in them (you can ignore .tmproj unless you use TextMate). Finally, a quick search through all the files for your old project name to replace and you should have it.
Oh! First, if you're using an IDE, you'll want to remove the project from the IDE, then re-import it once you've completed your renaming procedure.
As far as I know, nothing project-specific is stored anywhere except the project directory and below, so it's a very finite set to search, and you only have to do this once (I hope).
Not very elegant, I know, but brute force does have its uses.
I used the brute force Method and it worked for me. Took 5-10 minutes to find all files with the name in it and replace it with the new one. Also Netbeans was ok afterwards. The only thing that changed was the port number which I had to change again.
Just renaming works except when you are using plugins. They will be stored in the $USER_HOME/.grails/$GRAILS_VERSION/projects/OLDNAME folder.
So after renaming your project you "lost" your plugins. I haven't tried renaming the plugin's folder however just installing all your plugin works as well (at least with Google App Engine and gorm-jpa).
If only changing the web app name isn't enough you can try the rough way - make a backup before.
(In workspace folder)
zip -r oldname.zip oldname/
Then, in eclipse/ggts, use
Disable project, Build automatically
Search, File, Containing text : "oldname", Search
Right click on search results, Replace all, ... "newname"
Exit eclipse and rename all folders to the new project name. On Unix/Mac run
find . -name "oldname"
and mv the handful of results to properly reflect the new names.
For me it worked like a charm, but make sure your project name is not a keyword and reasonably unique.

Resources