Struts2 - Strange behavior of ModelDriven Interface

181 Views Asked by At

My objective is to get an object of TestBean class in Struts2 Action and show its values at jsp page (view layer)

I am implementing ModelDriven interface into my action class as follows

public class TestAction extends ActionSupport implements ModelDriven<TestBean>{

    private TestBean testBeanObject;

    @Override
    public TestBean getModel() {
        return testBeanObject;
    }

    @Override
    public String execute(){

        testBeanObject = getting object of TestBean Class from business layer (It is having all the value whatever I want)

        return ActionSupport.SUCCESS;
    }
}

My TestBean class code

@Entity

@Table(name="test_bean") 
public class TestBean implements Serializable { 
private static final long serialVersionUID = 1L; 

@Id 
@Column(name="test_bean_id") 
private int testBeanId; 

private String firstProperty; 

private String secondProperty; 


@OneToMany(mappedBy="testBeanPaper", fetch = FetchType.LAZY) 
private List<PapersText> papersTexts; 

public TestBean() { 
} 

public String getFirstProperty() { 
   return this.firstProperty; 
} 

public void setFirstProperty(String firstProperty) { 
   this.firstProperty = firstProperty; 
} 

public String getSecondProperty() { 
   return this.secondProperty; 
} 

public void setSecondProperty(String secondProperty) { 
   this.secondProperty = secondProperty; 
} 

public List<PapersText> getPapersTexts() { 
   return this.papersTexts; 
} 

public void setPapersTexts(List<PapersText> papersTexts) { 
   this.papersTexts = papersTexts; 
}  

}

My jsp page code is

<s:textarea id="textarea1" class="longinput" name="firstProperty" value="%{firstProperty}"></s:textarea> 

<s:textarea id="textarea2" class="longinput" name="secondProperty" value="%{secondProperty}"></s:textarea> 

At View Layer (Jsp page) I am having text fields with same name as properties of TestBean Class.

Now the problem is

case 1.

If I am getting TestBean class object form another class (as shown above), Values are not reflecting at jsp page. Even TestBean object is initialized perfectly

case 2.

In action class, If I manually set value of properties of TestBean class like

testBeanObject.setFirstProperty("FirstProperty");
testBeanObject.setSecondProperty("SecondProperty");

It is reflecting perfectly at view layer.

I have debugged my code. It is showing that object is initialized and have correct values in both case.Then Why is it not reflecting in case 1.

Plz help

0

There are 0 best solutions below