Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am pretty new to grails. In the past I have created web applications with jsf 2.0. Usually I created every class by "hand". Therefore scaffolding of grails comes extremely handy to me.
So my question is:
Do you just create the domain layer and then just modify the scafolded views?
Whats your typical development process in grails 2.3.4?
I appreciate your answer!
The development process depends on your type of project and experience.
I personally create lots of crud applications with the same corporate identity. So I use the scaffolding as you described: create views and controllers, then modify them. In order to apply the corporate identity, I've modified the default stylesheet and apply it through a self made plugin.
If you create crud like applications, but the scaffolding doesn't fit, you can do a install-templates and modify the resulting scaffolding templates. This way, you can easily modify the structure of your scaffolded pages (for instance add an Excel-Export for all list pages as default)
In other projects, my main pages are not crud like, so I manually create them. But I still need a lot of admin pages which are crud like - these I still scaffold and even don't have to modify. That spares a lot of effort
If scaffolded pages do not fit and you are experienced enough in Grails, #moeTi is right that manually coding your controllers and views might be faster.
For now until your more familiar its a great starting point to generate contollers and views. I think you will need to get more specific as to what it is you want to do with your controller views outside of scaffolding.
Email Validation in a controller Grails
Take look here for an example of a validation class that you could makeup and add at a bottom of a controller. This then gives you the power to custom verify. Hand made forms
Take a look at spring security plugin and if needed restrict delete edit to certain group of users.
In a lot of my earlier controllers I did a basic generation and then ended adding extra functionality.
Personally I don't really like the scaffolded views, although you can modify the templates. It's a good way to get started quickly, but you will soon realize that it's a lot of work to modify them to your needs.
You can scaffold and modify until you understand the GSP underpinnings, but at some point you will realize that you could write the whole thing faster than create and modify everything. And you can outsource code into templates and/or taglibs.
On the other hand, if you really just need default layout CRUD operation UI for your database, scaffolded views are probably good enough
Here is a start and brief info about scaffolding
Scaffolding lets you generate some basic CRUD interfaces for a domain class, including:
The necessary views and Controller actions for create/read/update/delete (CRUD) operations.
static scaffold = true // by setting scaffold to true
With this configured, when you start your application the actions and views will be auto-generated at runtime. The following actions are dynamically implemented by default by the runtime scaffolding mechanism:
a)index b)show c)edit d)delete e)create f)save g)update
then you could customize the generated views of your need.
I am sure the default views never fit to your need, so i would always go with my own view from the beginning.
But Yes!, if you are a beginner and want grails to help you how the controller and view looks like you can always start with it and feel the ease of grails framework
Thanks
Motilal
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I will try to explain my issue as much as I can.
I hope you guys can understand and give me an idea / help me.
So I am working on a practice app. There are two separate bootstrap html/css design for both of my dashboard and main site.
Here's the dashboard design:
Here's the main site design:
Both of these used bootstrap but separate set of custom design css as well js files.
So far I created a CRUD feature for both of my pages and posts (controller, migration, model, views)
Now I am confused on whether I'll create another controller for the dashboard and create a different folder on the views for that and how I can actually link the dashboard to my created pages, controller views so far as well as controller. Wondering also if I can create separate layout file for my dashboard and main site.
I hope it make sense.
Should I'll create another controller for the dashboard and create a different folder on the views for that?
Wondering also if I can create separate layout file for my dashboard and main site.
Yes, because they are literally two separate layouts.
There is no hard rule for controller separation, but in this case it's a nice way to separate one group of business logic (site front) from another (dashboard). So I would make a DashboardController and put layout for it in app/views/layouts/dashboard.html.erb
This is how Rails decided which layout to use
how I can actually link the dashboard to my created pages, controller views so far as well as controller
Using UrlHelper, like usually.
There are many ways to solve this problem.
But I think you are on the right way by creating seperate controller and views. A controller for the main site and one for the dashboard.
This has the great effect that you can handle the request more specific for both sides.
I think you want to add authorization for the dashboard. So you would implement this in the dashboard_controller.rb.
For specific css for a rails page: Adding a specific stylesheet to a single Rails page
I hope this was helpfully.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I will start a new .Net MVC project with a small team. It have five members, two back-end devs and three front-end devs.
The front-end members will work separately, building a html version of this project using tools like gulp/grunt, less/saas, jade and others frameworks. They prefer to use editors like Sublime and will run interface tests in many differents devices in real time.
They not able to work with MVC specifically Razor view engine, so we need two repositories, one to front and another to back.The back-end developer in the process ever need to catch the built html and suit it in Razor MVC.
Any ideas how to improve this process? How can i reduce the technical gap between back devs and front devs?
IMO you are trying too hard to accommodate the skills/desires of your team members. You will not get good cohesion from the client side with the server side if you completely ignore Razor/CSHTML. Your overall architecture/design should come first, and dictate these decisions. Of course you would take your team's skills into consideration, such that you wouldn't make a team of Java developers adopt C++. But you are taking this to an extreme by basically throwing consideration for design/architecture out of the window, and saying you will divide the application based on what your devs are willing to work with.
My opinions aside, you can make this work, but somewhat painfully.
For one, developing HTML apges first in a vacuum without consideration for interactions with the server is either going to result in very crippled interface that is more like static website from the 90s. There are a few cases where you can build a single-page-application that's pure javascript with no AJAX requests, but these scenarios are very rare.
Therefore, you need to either build the server-side first, or have a design step that mocks up the page and talk through how it will work.
1) Design a page and it's features, and how it interacts with the server. Identify what interactions are navigation actions, such as clicking a link to navigate to another page, versus those which are AJAX operations. Do NOT implement HTML, that comes later. As a team review what each dev mocks up and make sure they've thought through all of the interactions thoroughly.
From this, list what server side operations are needed in the controller for that page:
agree upon URLs
is it GET/POST
is it AJAX
whether it returns a page, partial HTML fragment, or JSON.
what parameter names for each are and data types
2) Your backend developers create controllers, exposing actions based on agreed upon design. CSHTML will for now be stubs and return nothing.
3) Your frontend developers create HTML/javascript to consume these.
They will be able to point ajax operations to the controllers, but they will need to mock what is returned since the Controllers don't know what HTML they should be returning yet.
4) Front end devs provide HTML to back end devs to incorporate into the project so that actions/partial views return the HTML or HTML fragments.
The problem is you are going to constantly be iterating through frontend devs giving HTML to backend devs to incorporate into the MVC project so that the actions that return HTML and or AJAX actions that return partial HTML fragments (PartialView) can be tested.
It makes for a very non-agile process.
You won't be able to take advantage of many frameworks for MVC which assume you are using Razor views/HTML helpers. Many frameworks for compressing/bundling javascript/less/css which integrate well with MVC are not going to be viable. You can still do this stuff, but you'll have a workflow that is not as smooth and will involve more hacking it together yourself.
I would like to point out that almost all javascript frameworks work great within CSHTML. From the client side perspective, MVC/CSHTML doesn't introduce any strangeness that prevents you from building very interactive pages. You can build a CSHTML page that is pure HTML and javascript, and makes AJAX calls to controllers, but trying to take that outside of the MVC project is going to cripple the development workflow. Designing and implementing an interactive page requires alot of consideration for how the actions on the server side are implemented.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have experience in writing code... but new to developing web applications.
I am in process of choosing a framework for my project. Based on my initial research almost everything is very VIEW centric where after all business logic has been executed a model is populated with data and passed on to the VIEW.
So the lowest level of granularity is the VIEW.
But I wonder what is the right technology to use if I wanted to develop re-usable widgets or controls. and then reuse them across multiple VIEWS.
i would prefer if the controls are in JavaScript and then they can easily be reused across pages.
So if I were to select Ruby on Rails ... does it have anything to help me write code in reusable widgets... or will it simply ask me to write the VIEWS which work with the data provided by the model?
Sorry if this is newbie question.
What do you use to write reusable Widgets in ROR?
to eloborate on what I mean by a widget.
Suppose I am writing a discussion forum web application. I want to write a widget called post which has 3 views. View 1 is edit mode. View 2 is summary mode. view 3 is Detail mode.
I throw in this widget in a page called QuestionStream and in this page the widget appears in summary view. I perform data binding so that i get a list of questions.
I throw in this widget in a page called ThreadView and in this page the widget appear in detailed view. I perform data binding and I get all the details of the question.
I throw in this widget in a page called NewQuestion and in this page the widget appears in edit view.
So its a self contained control... but is reused in multiple places in different modes (so to speak).
OK, well I hope I understood your question correctly.
Firstly I want to start by saying that web apps tend to be very "view-centric" since that's kind of (in a very abstract way) the basis of the REST architecture (i.e. the Internet). It's about stateless resources. You can imagine a resource being a form printed on a document. I've generated all the fields I require and I've printed it out and handed you the piece of paper. At this point I really don't know or care how you will fill out the form or with what data. I will only care about the data's validity once you hand me back the form and I can begin checking (for simplicity I've ignored AJAX concepts, that give you real-time validations/interactions). I think it's this 'statelessness' that makes it appear very 'view-centric', but don't be fooled, there's a lot going on under the hood.
With that said, there are three common ways of sharing code across your application.
PARTIALS - reusable view code - These are reusable snippets that can be used in your views - example: each item listed on Amazon has the same format (thumbnail, title, author/manufacturer, rating & price). It would make sense to write this View snippet once and just pass an array of objects where each object's attributes are then passed individually into the same partial and placed side by side
HELPERS - reusable methods - Helpers are again used in the views. Essentially it is common functionality that has been consolidated into a method so it can be reused multiple times, and by passing in different parameters you could make your method respond differently based on the situation (i.e. the current logged in user, or the current controller that has triggered this view). Example: I could create a helper method that could toggle my product listings from a detailed view, to a list view (not the best example, but I hope it gets the message across).
CONCERNS - reusable code across models - Concers are meant to "extract common and/or context specific chunks of code in order to clean up the models and avoid them getting too fat and messy". Please see this link for an example.
Your question was a bit tricky but I hope my answer helped clear a few things up for you.
As for your example, the 3 different views could be 3 different partials. You could then write a helper method that looks at the current controller, and determine which partial should be loaded. Digging a little deeper, you could then use concerns to keep your models' code DRY (Don't Repeat Yourself) - assuming you have multiple models with similar functionality.
Im really new to Grails and I try to understand how it works. I did some tutorials and wrote a sample application with a mysql database connection. Ive got three tables and therefor three domain-classes and three controller using def scaffold = true. So the views are generated automatically. Now I can add and remove and ... the data in my tables. Thats working.
But now I dont know how to go on. I mean, creating those tables and filling them is nice and its nice that this is possible so fast, but... Now I really want develope an application! Normally I work with Spring Framework, Spring Security, Spring MVC and so on to generate web applications. There, everything is logical. I have the requests comming in, the mapping to controllers, classes which work on the requests, answers given back, jsps rendered.... logical!
In Grails, I dont even know where to start for a real application! All tutorials I find show the same: Setting up those tables and being able to fill them, nice, nice - but after that?
Where do I save the "main.gsp". Do I need a controller for it? How does the application at start up redirect to "main.gsp".
Where can I define the "real logic" - I want to develope something like a "questions with multiple answers - try to select the correct answers"-application. Well, I must admit, I really dont know where to start. And I don't see the use of the Controllers and the possibility to add Data to my tables in my application. Thats for admins but not for users.
Could anyone give me an hint how to go on? Or maybe someone knows a good tutorial which is not about "setting up domain classes, controllers with scaffold, adding data to your database" - I dont see so much sense in it.
Thanks for your help! :-)
[EDIT] Thanks for the answers! Services, that was exactly what I was looking for. I guess I simply must get more familiar with it. The tutorials were just confusing me, but now I understand better!
If you are familiar with Spring and Spring MVC, the concepts in grails should be no surprise to you. Grails actually uses Spring MVC under the covers.
Grails can auto-generate Domain classes, controllers and views as you have tried in tutorials. This is to give you a starting point for your application. This is often enough for those textbook tutorials. For real applications though, you may not always have 1 domain class to 1 controller to 1 set of views. You might not always be doing CRUD operations on that domain. For this, you need to dig a bit deeper into Grails. You can do everything you previously have done in Spring MVC in Grails!
Here are some links to help you get going.
If you are trying to understand the 'flow' better. How requests get mapped to controllers/views, check out the UrlMappings.groovy in your config directory. Docs on that are located here: URLMappings
If you are trying to understand controllers better, check out this: Controllers. Keep in mind that your controller do not need to work on domain models. That is simply the default convention. They work similar to a Spring MVC controller.
Models are simple in Grails. Typically the controllers just return a map of the items you want to return. In Spring MVC, you often create a Model object, most times in Grails you will return something like [name: bean1, name2: bean2]. This allows you to easily get those two beans in the vies.
Start with 'Grails In Action'. The first chapter would give you details about the CRUD Sample app creation , but on reading further you would understand the grails flow better. Services are to be used for the logic, Controllers are used for delegation. You dont need explicit xml mapping as is done in Struts, Spring because everything here works on Convention.
Here is info on controllers: Controllers
Also you can use the same manual to find information on other stuff. For example about where to put business logic you should read in The Service Layer chapter.
Read Beginning Groovy, Grails and Griffon by Vishal Layka, Christopher M. Judd, Joseph Faisal Nusairat and Jim Shingler. They are building a real web application throughout the book with models, database access, authentication, css, templates and layouts, and many other things.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Does anyone know of a good/usable ASP.NET MVC code/solution generator. Ideally it would build from a domain model, but from a data model is also acceptable.
If you do, can you answer the following:
Does it produce "good" code?
Can it be extended?
What do you like and not like about it if you have used it?
What great fearures does it come with that stand out?
If there isn't one you know of then do you think this is something missing from the community or do you not think it is needed? What features would you like to see in one?
Can't wait to hear your answers...
Thanks
Scott
S#arp Architecture includes scaffolding generator using T4. It generates model, views, controllers, and tests from the template model definition. You get full CRUD. Since it uses T4 (Visual Studio template language I suppose) you can extend default templates as you want.
Here's an example of the template:
EntityScaffoldingDetails entityScaffoldingDetails =
new EntityScaffoldingDetails("Organization.Worker");
/*
* Property names should be PascalCase.
* Do not include a property for Id as it will be included automatically.
*/
entityScaffoldingDetails.EntityProperties.Add(
new EntityProperty("FirstName", "string", "Joe", "[NotNull, NotEmpty]", true)
);
entityScaffoldingDetails.EntityProperties.Add(
new EntityProperty("LastName", "string", "Smith", "[NotNull, NotEmpty]", true)
);
entityScaffoldingDetails.EntityProperties.Add(
new EntityProperty("BirthDate", "DateTime", DateTime.Parse("1/1/1975"))
);
entityScaffoldingDetails.EntityProperties.Add(
new EntityProperty("Manager", "Employee", null, "[NotNull]")
);
///////////////////////////////////////////////////
// The first parameter should reflect the root directory of your solution
//ScaffoldingGenerator generator = new ScaffoldingGenerator(
//#"D:\Work\Project\", "Orders", entityScaffoldingDetails);
// Uncomment this line when you're ready for the scaffolding generator to fire...be sure to recomment after it completes to avoid accidental generating!
//generator.Run();
One small addition: I would not recommend using it as is, because, for example, I'd prefer controllers to work with ViewModel, not entities. And I don't use scaffolding much. But it is pretty flexible, though you may need to learn T4.
You could try a Visual Studio 2010 extension called Radarc. It has a repository of extensions (called Formulas) which allows you to generate solutions for different architectures and technologies. Using Radarc with MVC Formula you can create ASP.Net MVC 3 applications with EF Code First either from a new domain model or importing an existing database.
I am working in this product team so I am not too objective to reply all your questions, but yes it can be extended.
Have you taken a look at Naked Objects MVC ? at least for academic reasons is very interesting.
The Naked Objects MVC framework will take a Domain model (written as POCOs) and render it as a complete HTML application without the need for writing any user interface code - by means of a small set of generic View and Controller classes. The framework uses reflection rather than code generation.
The developer may then choose to create customised Views and/or Controllers, using standard ASP.NET MVC patterns, for use where the generic user interface is not suitable.
Try www.datatreepages.com.
You connect the designer at your database and it generates data entry pages with sorting/searching/paging. You can also design layouts which allow you to link data pages together on the screen for master/detail relationships.
The controllers, data access, models, view models, csthml, javascript/jquery, html/css are all written for you. The code produced is simple and extendable.