Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Oranger8
Copy link

@Oranger8 Oranger8 commented Mar 6, 2019

Предоставляет ли WildFly реализацию валидации?
Если поменять @ManagedBean на @Named (если я правильно понял, это и есть сделать CDI),
то бины перестают работать, на форме пусто, ошибок нет.

import java.util.Collection;

@Named("categories")
@SessionScoped
Copy link
Owner

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() {
Copy link
Owner

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;
Copy link
Owner

@usharik usharik Mar 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А переопределен ли hashCode у продукта?

Copy link
Author

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants