问题
I have a little problem with printing field in a jsp page. I've managed persistency with hibernate.
When I go to jsp page, it displays nothing. How can I modify jsp in order to print fields of prodotti
of a scontrino?
Action Class
public class ScontrinoStruts extends ActionSupport implements UserAware{
private static java.lang.Float iva = 22.00f;
private String valori;
private int idScontrino;
private Date data;
private java.lang.Float importoTotale;
private int totalePezzi;
private int ID_Anagrafica;//idanagrafica
private Anagrafica anagrafica;
private AnagraficaDAO anagraficaDAO = AnagraficaDAOFactory.getDAO();
private int idProdotto;
private List<Prodotto> prodotti = new ArrayList<Prodotto>();
private Prodotto prodotto;
private Scontrino scontrino = new Scontrino();
List<Scontrino> scontrini = new ArrayList<Scontrino>();
ScontrinoDAO scontrinoDAO = ScontrinoDAOFactory.getDAO();
ProdottoDAO prodottoDAO = ProdottoDAOFactory.getDAO();
public String showScontrino(){
scontrino = scontrinoDAO.getScontrino(idScontrino);
return "success";
}
//getters and setters
}
struts.xml
<action name="showScontrino" method="showScontrino"
class="it.unirc.pjam.Action.ScontrinoStruts">
<result name="success">/scontrino.jsp</result>
</action>
jsp
<table>
<tr>
<td>id</td>
<td>Descrizione</td>
<td>prezzo</td>
</tr>
<s:iterator value="scontrino.prodotti">
<tr>
<td><s:property value="idProdotto" /></td>
<td><s:property value="descrizione" /></td>
<td><s:property value="prezzo" /></td>
</tr>
</s:iterator>
</table>
回答1:
The fields a displayed via OGNL expression that is used to traverse the object properties to find the value. Attributes such as value
is used to parse for OGNL expression first before returning its value. How OGNL expression is evaluated you can find in this answer.
You can also read this answer to understand what is the action context that is used by OGNL when it's searching the values.
This answer will guide you how to provide getter for the list that is iterated.
Take a deep learning into OGNL language guide with this answer.
This answer will teach you how to use dot notation to access beans' properties.
来源:https://stackoverflow.com/questions/44978769/jsp-doesnt-get-struts2-action-fields