Search code examples
javaweb-applicationsjstljavabeansstruts-1

Pass JavaBean to Struts 1 tiles


I just started developing a web application using struts 1.3.10 tiles framework. There is something I am not so clear.

Suppose I have a tiles definition in tiles-def.xml:

<definition name="body" path="/layouts/BodyLayout.jsp">
    <put name="displayUnit" value="/tiles/displayUnit.jsp"/>
</definition>

The "displayUnit.jsp" is a modularized jsp page that contains some basic tiles module:

<div>
    <!-- Some html here-->
</div>

This basic structure is operating on a single JavaBean:

public class DisplayUnitBean() {
private String color;
private String bgcolor;

public String getBgColor() {
    return bgcolor;
}

public String getColor() {
    return color;
}

public void setBgColor(String bgcolor) {
    this.bgcolor = bgcolor;
}

public void setColor(String color) {
    this.color = color;
}
}

In the layout jsp "BodyLayout.jsp", I would like to insert a few basic tiles modules "displayUnit.jsp":

<tiles:insert attribute="displayUnit"/>
<tiles:insert attribute="displayUnit"/>
<tiles:insert attribute="displayUnit"/>
<tiles:insert attribute="displayUnit"/>

And each of these tiles modules is using a different "DisplayUnitBean" instance to be displayed in different ways.

Obviously, I need some dynamic codes (JSTL based maybe) inside "displayUnit.jsp" to retrieve JavaBean parameters. And, I also need to pass different JavaBeans to different "displayUnit.jsp" pages while inserting them.

I wonder how I can accomplish this, and whether it's possible to do it at all. If not, I wish to know the correct paradigm to code this web application.

Thank you in advance!!


Solution

  • refer this struts1 tiles example

    Codes for mappings, definitions, etc are explained there with screen shots and codes..