-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Homework 4 #2
base: master
Are you sure you want to change the base?
Homework 4 #2
Conversation
import java.util.Collection; | ||
|
||
@Named("categories") | ||
@SessionScoped |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Насколько я зная возможность полностью отказаться от managed бинов появилась только в версии JSF 2.3. Но этот момент нужно уточнить. Речь идет о довольно новых вещах.
@Inject | ||
private CategoryRepository categoryRepository; | ||
|
||
public String getId() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
На всякий случай хочу сказать, что есть еще один подход к построению managed бинов. Можно не создавать геттеры для всех полей сущности, а создать только один геттер для поля с текущей сущностью. Тогда можно будет обращаться к полям из представлений #{categories.category.id}
public class Order { | ||
|
||
private String id; | ||
private Map<Product, Integer> orderMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А переопределен ли hashCode у продукта?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мапа хранит для заказа пары продукт - количество. Хеш-функцию забыл. Сделаю по id.
|
||
private String id; | ||
|
||
@NotNull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Валидация будет работать только в бинах, а этот файл бином не является. На следующем уроке мы преобразуем его в сущность и все заработатет. Пока же предлагаю использовать валидацию в xhtml. Компоненту inputText можно добавить свойство required. Кроме того есть еще семейство вот таких тегов для валидации https://www.tutorialspoint.com/jsf/jsf_validation_tags.htm
Предоставляет ли WildFly реализацию валидации?
Если поменять
@ManagedBean
на@Named
(если я правильно понял, это и есть сделать CDI),то бины перестают работать, на форме пусто, ошибок нет.