model-view-controller

MVC - where to implement form validation (server-side)?

雨燕双飞 提交于 2019-12-22 04:18:10
问题 In coding a traditional MVC application, what is the best practice for coding server-side form validations? Does the code belong in the controller, or the model layer? And why? 回答1: From Wikipedia: Model-view-controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying

Does SessionStatus object.setComplete() clears all the session attributes or just work for the controller in which it is used?

拟墨画扇 提交于 2019-12-22 04:06:45
问题 I am not clear about this if I use SessionStatus object.setComplete() in a Controller, does it clears all the session data of the Webapp or just clears the session data saved by a particular controller in which @SessionAttributes is used? 回答1: SessionStatus#setComplete() JavaDoc is pretty clear about the method's purpose: /** * Mark the current handler's session processing as complete, allowing for * cleanup of session attributes. */ This clears the current handler's session attributes

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions

大憨熊 提交于 2019-12-22 01:40:53
问题 This part of code is not working @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem=>item.Registrations.Count()) </td> and throws an error [InvalidOperationException: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.] But this part of code below is working as a charm. @foreach (var item in Model) { <tr> <td> @item.Registrations.Count() </td> Is there anybody who can explain why is so?

Spring 3 MVC Multiple view resolvers(Jsp and Velocity)

拜拜、爱过 提交于 2019-12-22 01:34:55
问题 Because of some business/technical constraints we should use spring3 MVC multiple view resolvers( JSP and Velocity ). I tried to search on net on this but i couldn't find perfect solution. May be someone else had experienced the same scenario. So Could you please let me know is it possible to use both JSP and Velocity as vew resolvers in the SPring3 MVC application All help is appreciated. 回答1: Spring support multiple view resolvers. You chain view resolvers by adding more than one resolver

Where to validate in Express.js project – Validation at the database layer (re. Mongoose)?

流过昼夜 提交于 2019-12-22 01:29:05
问题 I am writing an application with a form in Express.js, and to begin with, I was doing all of my validation in the route (or controller, if you like): app.post('/register', function (req, res, next) { // Generic validation req.assert('name', 'Name is empty').notEmpty(); req.assert('username', 'Username is empty').notEmpty(); var errors = req.validationErrors(true); if (errors) { // If there are errors, show them } else { // If there are no errors, use the model to save to the database } });

Rails lib directory

风格不统一 提交于 2019-12-22 01:13:03
问题 Question about lib directory. What are good practices in using the lib directory? When should it be used over app/models or app/helpers? And somewhat related how do you get Rails 3 to include files from the lib directory? Thanks 回答1: One use of the lib directory (how I use it most often) is to share code between models to stay DRY. For example, if you are defining a tag_tokens attribute on many different models for use with a tokenizer input, you could put that in "tag_accessor.rb" or

MVC with JavaFX and FXML

别说谁变了你拦得住时间么 提交于 2019-12-22 00:40:09
问题 If I have a JavaFX project that uses FXML, how would I structure it to adhere to the Model-View-Controller pattern? This is what I would assume the general structure to be like: Model - Underlying program (what the GUI is representing). View - FXML file. Controller - FXML controller. The issue with this representation is that the view cannot be notified of the model's changes, as it is simply an FXML file. Should the view be the FXML controller class, and then should I have a main controller

Programming with a Java MVC approach using NetBeans GUI builder

人盡茶涼 提交于 2019-12-22 00:36:03
问题 I've been tasked with making a GUI that essentially takes a bit of user input and does some folder/file manipulation on various drives accessible by the machine the program is being run on. While designing this GUI, I'm starting to realize that MVC will make my life much easier and anyone else who decides to modify code, but I can't really see how this can be done via NetBeans. I've done a bit of reading up on this topic, and I can't really see any clear cut answers as to whether or not this

Enum with mvc rendering in checkbox on my view, reaction of my controller?

戏子无情 提交于 2019-12-22 00:07:02
问题 If i got a list of checkbox in a View, and this list came from Enum (flags). If my checkbox as all the same name, did my controller will update automaticly my Enum (flags) values in my ViewModel with multiple selection ? Suppose i get in my View <% foreach (var t in Enum.GetValues(typeof(FoodType))) { Response.Write(t.ToString() + " "); %> <input type="checkbox" name="TypeOfFood" value="<%:(int)t %>" /> <% }%> My Controller working like this public ActionResult Manage(FoodEntity food) { } If

What are your best practices when using an MVC-based web framework?

淺唱寂寞╮ 提交于 2019-12-21 22:56:01
问题 A few general questions to those who are well-versed in developing web-based applications. Question 1: How do you avoid the problem of "dependency carrying"? From what I understand, the first point of object retrieval should happen in your controller's action method. From there, you can use a variety of models, classes, services, and components that can require certain objects. How do you avoid the need to pass an object to another just because an object it uses requires it? I'd like to avoid