JSF, several bean update properties in the form

I edited my question to be more precise, as I have more time to write it.

I have a JSF form that should change the meaning of various properties of a dog:

<h:form id="submit">
     <h:outputLabel value="Dog name:"/>
     <h:inputText value="#{User.dog.name}" id="dogName"/>
     <h:outputLabel value="Name :"/>
     <h:inputSecret value="#{User.name}" id="name" />
     <h:commandButton type="submit" value="Submit" />
</h:form>

This is my managed bean User.java: (All getters and setters are good and valid, as this bean constructor is empty). (Initially, the Dog property is initialized in the verification method, so it matters and not null)

public class User {
    public User() {}
    String  name;
    Dog dog;

    (...get, set, ect...)

This is another bean that I have not installed, since it is used only by the User class Dog.java:

public class Dog{
    public User() {}
    String  dog_name;

(...)

This means that this is a simple example for understanding things.

When I submit the form, the property User.namewill be updated, but not the property User.dog.name.

How to update both values ​​of Java classes?

, User.name:

System.out.println(User.name);// System.out.println(User.dog.name);//

, , Dog JSF althouth. Dog bean , User.Dog...

, faces-config :

: bean. , ...

<managed-property>
    <property-name>dog</property-name>
    <property-class>package.Dog</property-class>
    <value>#{Dog}</value>
</managed-property>
+3
2

beans beans. JSF .

, :

public class User {
    Dog dog;
}

:

public class User {
    Dog dog = new Dog();
}

:

public class User {
    Dog dog;
    public User() {
        this.dog = new Dog();
    }
}

Dog bean, User faces-config.xml:

<managed-bean>
    <managed-bean-name>dog</managed-bean-name>
    <managed-bean-class>mypackage.Dog</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>user</managed-bean-name>
    <managed-bean-class>mypackage.User</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
        <property-name>dog</property-name>
        <value>#{dog}</value>
    </managed-property>
</managed-bean>

, , Javabean.

+2

. , , User.dog null. , bean name User. User ( User, ​​ JSF).

0

Source: https://habr.com/ru/post/1724034/


All Articles