Skip to main content
deleted 2 characters in body
Source Link
marc_s
  • 759.9k
  • 186
  • 1.4k
  • 1.5k

I suggest to apply MVVC pattern to separate your bussinessbusiness object from your view object.

You expect to receive only strings from the view in your model attribute object.

Your entity object contains a list of tags and a list of answers => they are modeled differently and the usage of the same class is difficult, with many potential bugs.

In your case it is better to create.a separate view class only with strings and convert them to your entity object. Example

Example :

public class QuestionModelAttribute { private String tags; private String answers; ..... } 

and your method will receive:

@PostMapping("/questions/new") public String processQuestion(@Valid @ModelAttribute("question") QuestionModelAttribute questionModelAttribute, BindingResult result) { Questions question = questionsService.convertQuestion(questionModelAttribute); questionService.save(question); .. } 

Your view will receive in the model a QuestionModelAttribute

<form:form action="/questions/new" method="post" modelAttribute="questionModelAttribute"> 

This pattern offers a healthy decoupling between the view and model.

I suggest to apply MVVC pattern to separate your bussiness object from your view object.

You expect to receive only strings from the view in your model attribute object.

Your entity object contains a list of tags and a list of answers => they are modeled differently and the usage of the same class is difficult, with many potential bugs.

In your case it is better to create.a separate view class only with strings and convert them to your entity object. Example :

public class QuestionModelAttribute{ private String tags; private String answers; ..... } 

and your method will receive:

@PostMapping("/questions/new") public String processQuestion(@Valid @ModelAttribute("question") QuestionModelAttribute questionModelAttribute, BindingResult result) { Questions question = questionsService.convertQuestion(questionModelAttribute); questionService.save(question); .. } 

Your view will receive in the model a QuestionModelAttribute

<form:form action="/questions/new" method="post" modelAttribute="questionModelAttribute"> 

This pattern offers a healthy decoupling between the view and model.

I suggest to apply MVVC pattern to separate your business object from your view object.

You expect to receive only strings from the view in your model attribute object.

Your entity object contains a list of tags and a list of answers => they are modeled differently and the usage of the same class is difficult, with many potential bugs.

In your case it is better to create.a separate view class only with strings and convert them to your entity object.

Example :

public class QuestionModelAttribute { private String tags; private String answers; ..... } 

and your method will receive:

@PostMapping("/questions/new") public String processQuestion(@Valid @ModelAttribute("question") QuestionModelAttribute questionModelAttribute, BindingResult result) { Questions question = questionsService.convertQuestion(questionModelAttribute); questionService.save(question); .. } 

Your view will receive in the model a QuestionModelAttribute

<form:form action="/questions/new" method="post" modelAttribute="questionModelAttribute"> 

This pattern offers a healthy decoupling between the view and model.

added 609 characters in body
Source Link
Adina Rolea
  • 2.1k
  • 1
  • 10
  • 18

I suggest to apply MVVC pattern to separate your bussiness object from your view object.

You expect to receive only strings from the view in your model attribute object.

Your entity object contains a list of tags and a list of answers => they are modeled differently and the usage of the same class is difficult, with many potential bugs.

In your case it is better to create.a separate view class only with strings and convert them to your entity object. Example :

public class QuestionModelAttribute{ private String tags; private String answers; ..... } 

and your method will receive:

@PostMapping("/questions/new") public String processQuestion(@Valid @ModelAttribute("question") QuestionModelAttribute questionModelAttribute, BindingResult result) { Questions question = questionsService.convertQuestion(questionModelAttribute); questionService.save(question); .. } 

Your view will receive in the model a QuestionModelAttribute

<form:form action="/questions/new" method="post" modelAttribute="questionModelAttribute"> 

This pattern offers a healthy decoupling between the view and model.

I suggest to apply MVVC pattern to separate your bussiness object from your view object.

You expect to receive only strings from the view in your model attribute object.

Your entity object contains a list of tags and a list of answers => they are modeled differently and the usage of the same class is difficult, with many potential bugs.

In your case it is better to create.a separate view class only with strings and convert them to your entity object. Example :

public class QuestionModelAttribute{ private String tags; private String answers; ..... } 

I suggest to apply MVVC pattern to separate your bussiness object from your view object.

You expect to receive only strings from the view in your model attribute object.

Your entity object contains a list of tags and a list of answers => they are modeled differently and the usage of the same class is difficult, with many potential bugs.

In your case it is better to create.a separate view class only with strings and convert them to your entity object. Example :

public class QuestionModelAttribute{ private String tags; private String answers; ..... } 

and your method will receive:

@PostMapping("/questions/new") public String processQuestion(@Valid @ModelAttribute("question") QuestionModelAttribute questionModelAttribute, BindingResult result) { Questions question = questionsService.convertQuestion(questionModelAttribute); questionService.save(question); .. } 

Your view will receive in the model a QuestionModelAttribute

<form:form action="/questions/new" method="post" modelAttribute="questionModelAttribute"> 

This pattern offers a healthy decoupling between the view and model.

Source Link
Adina Rolea
  • 2.1k
  • 1
  • 10
  • 18

I suggest to apply MVVC pattern to separate your bussiness object from your view object.

You expect to receive only strings from the view in your model attribute object.

Your entity object contains a list of tags and a list of answers => they are modeled differently and the usage of the same class is difficult, with many potential bugs.

In your case it is better to create.a separate view class only with strings and convert them to your entity object. Example :

public class QuestionModelAttribute{ private String tags; private String answers; ..... }