0

I need to pass 2 object from jsp to action, but I think something is wrong. I get this error: ERROR ParametersInterceptor Developer Notification (set struts.devMode to false to disable this message): Unexpected Exception caught setting 'idprodotto' on 'class it.unirc.pjam.Action.CatalogoStruts: Error setting expression 'idprodotto' with value ['5', ]. How can i fix it?

JSP

        <s:iterator value="catalogo" var="c">
            <s:iterator value="#c.prodotti" var="p">
                <s:url action="cancellaProdottoDaCatalogo.action" var="urlCancel">
                    <s:param name="idprodotto" value="#p.id" />
                    <s:param name="idcatalogo" value="#c.id" />
                </s:url>
                <tr>
                    <td><s:property value="#p.id" /></td>
                    <td><s:property value="#p.descrizione" /></td>
                    <td><s:property value="#p.prezzo" /></td>
                    <td><s:property value="#p.nPezziVenduti" /></td>
                    <td><a
                        href='<s:property value='urlCancel'/>'>rimuovi
                            dal catalogo</a></td>
                </tr>
            </s:iterator>
        </s:iterator>

ACTION

public class CatalogoStruts extends ActionSupport implements UserAware{

private Catalogo catalogo = new Catalogo();
private CatalogoDAO catalogoDAO = CatalogoDAOFactory.getDAO();
private List<Catalogo> cataloghi = null;

private Prodotto prodotto = new Prodotto();
private ProdottoDAO prodottoDAO = ProdottoDAOFactory.getDAO();
private List<Prodotto> prodotti = null;

public String cancellaProdottoDaCatalogo(){
    Catalogo tmp = catalogoDAO.getCatalogo(catalogo.getId());
    for(Prodotto p:catalogo.getProdotti()){
        System.out.println(p.getDescrizione());
    }
    //catalogoDAO.aggiornaCatalogo(tmp);
    return SUCCESS;
}

public Catalogo getCatalogo() {
    return catalogo;
}

public void setCatalogo(Catalogo catalogo) {
    this.catalogo = catalogo;
}

public List<Catalogo> getCataloghi() {
    return cataloghi;
}

public void setCataloghi(List<Catalogo> cataloghi) {
    this.cataloghi = cataloghi;
}

public List<Prodotto> getProdotti() {
    return prodotti;
}

public void setProdotti(List<Prodotto> prodotti) {
    this.prodotti = prodotti;
}

}

struts.xml

    <action name="cancellaProdottoDaCatalogo" method="cancellaProdottoDaCatalogo"
        class="it.unirc.pjam.Action.CatalogoStruts">
        <result name="success" type="redirect">
            listCataloghi
        </result>
    </action>
Manlio
  • 41
  • 1
  • 8
  • @Roman-C question is different. solution as old page doesn't work for me. – Manlio Jul 12 '17 at 10:28
  • 1
    Take a look at simple struts2 CRUD examples like this [one](https://dzone.com/tutorials/java/struts-2/struts-2-example/struts-2-crud-example-1.html), your code is not doing what you want to reach at this point. – beendr Jul 12 '17 at 11:14

0 Answers0