NARENDRA
NARENDRA

Reputation: 395

I want to set the jsp text field values in struts2 Action class automatically when i declare the field variables in 2 other POJO classes

I don't want to declare those variables in Action class again

Employee POJO:

package com.pojo;

import java.io.Serializable;

public class Employee{

    String name;
    Address address;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

}

AddressPOJO:

package com.pojo;

import java.io.Serializable;

public class Address{


    String email;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }               
}

JSP:

<body>
<s:form action="beanEx">

<s:textfield label="name" name="name"/>
<s:textfield label="email" name="email"/>

<s:submit value="Submit"/>

</s:form>

</body>

I want to populate the values automatically set the values in Action class

Can anybody help me out........

Upvotes: 0

Views: 7251

Answers (1)

mprabhat
mprabhat

Reputation: 20323

Have two objects in your action class with getter/setter

private Address address = new Address();
private Employee employee = new Employee();;

then in your jsp do like this:

<body>
    <s:form action="beanEx">    
        <s:textfield name="employee.name" label="name"/>
        <s:textfield name="address.email" label="email"/>    
        <s:submit value="Submit"/>    
    </s:form>    
</body>

Basically earlier you were pointing to the field now you are pointing to the field inside an object.

Upvotes: 1

Related Questions