Search code examples
javajspjstlstrutsstruts-1

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?


Solution

  • 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}" />