How to make a checkbox field which contains java objects, using thymeleaf? - spring

I am trying to make a project where you can add a new professor into the management system. Here you have to input the courses the professor offers. The courses is a separate POJO too. I have created a page where the teacher can select the courses he will be taking. How do i achieve this using checkboxes. The ticked checkboxes should mean that the course object has been added in the List of the professor class

Related

Magento save many to many models

I have created a custom module with 3 models (student, room, studentroom).
The studentroom is used to store the relation between student & room (manytomany).
I have maked the form + grid to the students and rooms and i can create both of them. i want now to add a multiselect in the student form to select the rooms (until now its ok). When i save or edit my student how can i save or display also the association in studentroom.
Anyone has an idea ? A module with the same functionalities ?
Thx for advance
Magento's ORM has no built-in methods for the sort of one to many and many to many relationships you're describing above. As such, it's up to each individual developer to implement their own save methods that (before or after calling parent::save()) handle any extra relationships an object might have.

CRM 2013 online Subgrid implementation best practice

I'm new to CRM, and am having difficulties implementing a subgrid onto an account form. I am not a programmer.
I will not bore you with the methods that I have tried to so far; that could take a while. Suffice it to say, I am having no luck.
i have created and imported two sets of records from my SQL database. One set was imported into the standard Accounts entity and the other was imported into a custom entity; let's just call that it Problems.
The relationship between Accounts to Problems is one-to-many. Each Account has a "problemID" and each related Problem has a "problemID" as well.
I need to be able to place a subgrid containing all related Problems onto the Accounts forms. I need to be able to see the old ones and create new ones.
How would YOU handle this?
Many thanks!
For a 1:N relationship between Accounts and Problems you only need a lookup to the Account Entity on the Problem entity. Then you can:
Edit the Account Form
Insert a Sub-grid
Set the sub-grid to look to "Only Related Records" for "Problems"

Binding posted values to view model using default binder - MVC3

Can the Model Binder in MVC bind posted values to a view-model object containing hierarchy?
I have a Customer, Order and OrderItem tables. OrderItem.OrderID points to Order.ID; and Order.CustomerID points to Customer.ID i.e. the common Customer -> Order -> OrderItem setup.
And I have a view model – Customer which contains Order objects and then OrderItem objects as well.
I have created the EF model objects using the designer tools in VS. (created database tables first in SQL, then created the classes automatically using the EF tools)
On a single page (view), let's say, I will allow the user to create a new Customer record, an Order, and some OrderItem(s).
When the user fills the form (creates a new Customer, Order and OrderItems on this one view), clicks on the submit button; will the default binder move all the values from the posted values to my view model? (the view model class carries properties for Customer, Order, OrderItem in a hierarchy i.e. Order is a property within Customer and OrderItem is a property within Order). Is EF smart enough to map posted values to such an object?
Yes, MVC is smart enough to handle this binding. It is fairly common in MVC to build up a 'complex' View Model made of several properties which are themselves Models. Binding to collections and dictionaries is harder, but entirely possible.
In EF, you can easily define relationships between objects (e.g. there is a 1 to many relationship between Customer and Order), and EF will handle this just fine. The code for the 'Create customer with order and order items' will (I imagine) be fairly straightforward but I'm not an EF expert, though - so I will have to leave detailed answers to someone else.
However, the EF code for an 'Edit Customer and/or Order and/or Items' screen would actually be quite complicated - and so you'd probably be better splitting these off into separate actions, as this would simplify the code quite a lot.

CodeIgniter MVC Model Logic

I have programmed in Rails, Django, Zend, and CakePHP. Also, Wordpress and Drupal.
Now, I am "catching up to speed" in as fairly large application in CodeIgniter.
Typically, my experience with MVC frameworks, has led me to believe that Models represent business logic in reference to actual database tables. In the CodeIgniter docs and in the code base I'm dissecting I see models created that represent something as vague as a page. A lot of the business logic is written directly into those models and they incorporate other actual data models. I'm not sure this is ideal and following MVC.
Should models be created beyond data models?
Also, lets say I have a data model representing a user (user table in DB). In that user table there is a column called gender of the type enum('male', 'female'). Now I want to populate a dropdown with the gender options from the enum column.
Where is it most appropriate to put this logic?
The user model is an object used to represent a single user or row in the db... right? So it doesn't seem fitting to include a function in the user model/class called "get_gender_options", because, while the function is related to the user table, it is NOT relevant to a single user object. In Zend this kind of logic could be built into the form object itself.
There is not "right" answer, just one we can consider the most appropriate...
I would probably just put the "get_gender_options" in the model, rather than sticking it in the view for the form. To keep it DRY but not put it in the model, I would create a helper to hold this.

Model Data Type versus View Control

I have having a little trouble wrapping my head around the design pattern for MVC when the data type of the model property is very different than what I wish to display in a form. I am unsure of where the logic should go.
Realizing that I am not really sure how to ask the question I think I will explain it as a concrete example.
I have a table of Invoices with a second table containing the InvoiceDetails. Each of the InvoiceDetail items has an owner who is responsible for approving the charge. A given invoice has one or more people that will eventually sign off on all the detail rows so the invoice can be approved. The website is being built to provide the approval functionality.
In the database I am storing the employee id of the person who approved the line item. This schema provides me a model with a String property for the Approved column.
However, on the website I wish to provide a CheckBox for the employee to click to indicate they approve the line item.
I guess my question is this -- how do I handle this? The Model being passed to the View has a String property but the form value being passed back to the Controller will be of the CheckBox type. I see two possible ways...
1) Create a new Model object to represent the form fields...say something like FormInvoiceDetails...and have the business logic query the database and then convert the results to the other type. Then after being submitted, the form values need to be converted back so the original Model objects can be updated.
2) Pass the original InvoiceDetails collection to the View and have code there create render the CheckBox based on the value of the String property. I am still not sure how to handle the submission since I still need to map back the form values to the underlying database object.
Maybe there is a third way if not one of these two approaches?
To make the situation a bit more complicated (or maybe it doesn't), I am rendering the form to allow for the editing of multiple rows (i.e. collection).
Thanks for any insight anybody can provide.
You need a ViewModel, like #Justn Niessner suggests.
Your controller loads the complete model from the database, copies just the fields it needs into a ViewModel, and then hands the ViewModel off to the view for rendering.
I'd use Automapper to do the conversion from Model to ViewModel. It automates all the tedious thingA.x = thingY.x; code.
Here is an additional blog post going over in detail the use of ViewModels in the Nerd Dinner sample.
I believe what you are looking for is the ViewModel.
In cases where you are using a ViewModel, you design the ViewModel to match the exact data you need to show on your page.
You then use your Controller to populate and map your data from your Model in to your ViewModel and back again.
The Nerd Dinner ASP.NET MVC Example has some very good examples of using ViewModels.

Resources