sliders_alpha
sliders_alpha

Reputation: 2454

DIsplay attribute of an object in jsp with Struts

So I have those classes :

public class DeviceDto {
  private long number;
  private long blob;

  //getters setters

}

public class PageDto {
  private DeviceDto pda;
  private DeviceDto tab;
  private String message;

  //getters setters
}

In my action I make a pageDto and then set it :

request.setAttribute("dto", pageDto);

Then in the jsp I have :

<bean:write name="dto" property="message" />
<bean:write name="dto" property="pda.id" />
<bean:write name="dto" property="tab.id" />

however the pda.id and tab.id do not display anything. I also tried ${tab.id} bit this raise an exception saying that there is no getter.

Any ideas?

Upvotes: 1

Views: 2462

Answers (2)

sliders_alpha
sliders_alpha

Reputation: 2454

Well @Roman C awnser is good, but I found a way to do it with bean:write so I'm posting it too.

Use bean define to define a proberty of dto as a bean and then bean:write can be used.

<bean:define name="dto" property="pda" id="pdadto" />
<bean:write name="pdadto" property="id" />

This will write dto.pda.id

Upvotes: 1

Roman C
Roman C

Reputation: 1

You can't use <bean:write> tag in that way. Instead of <bean:write> you can use equivalent JSTL tag <c:out>.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:out value="${dto.message}" />
<c:out value="${dto.pda.id}" />
<c:out value="${dto.tab.id}" />

Upvotes: 1

Related Questions