I need to solve this business requirements but I'm experiencing some unwanted behaviour and I need the assistance of the experts. I'm using JSF 2.2.13, Prime Faces 5.3
I have a UserBean like this
@ManagedBean(name = "userBean")
@RequestScoped
public class UserBean implements Serializable {
private Long id;
private String firstName;
private String lastName;
@ManagedProperty(value = "#{countryBean}")
private CountryBean phoneCode1;
private String phoneNumber1;
@ManagedProperty(value = "#{countryBean}")
private CountryBean phoneCode2;
private String phoneNumber2;
...
...getter/setter
and a CountryBean like this
@ManagedBean(name = "countryBean")
@RequestScoped
public class CountryBean implements Serializable{
private Long id;
private String isoCode;
private String phoneCode;
...
...getter/setter
The problem(as you probably already know) is that inside the UserBean we have more than 1 field(phoneCode1, phoneCode2)of the same managed property(countryBean).
The strange behavior is that inside the database(MySQL), my application save the same value for all of those fields(phoneCode1, phoneCode2) even if, in the front-end we select different values.
In the front-end I've this piece of code
<h:selectOneMenu value="#{userController.userBean.phoneCode1.id}" class="form-control">
<f:selectItem itemLabel="#{msg['seleziona']}" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{applicationScopedBean.countries}" var="ac" itemValue="#{ac.id}" itemLabel="#{ac.phoneCode}"/>
</h:selectOneMenu>
<h:selectOneMenu value="#{userController.userBean.phoneCode2.id}" class="form-control">
<f:selectItem itemLabel="#{msg['seleziona']}" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{applicationScopedBean.countries}" var="ac" itemValue="#{ac.id}" itemLabel="#{ac.phoneCode}"/>
</h:selectOneMenu>
So, in which way we can solve this business requirement?
I've saw similar questions but I don't understand if I'm not using very well JSF, or if it's a JSF limitation. From the point of view of a database it's similar to ask "In which way I can create a table named "A" with some FK linked to the table "B"?
Thank you!