我正在使用 JSF 传递元素,并且我想向我的 Bean 发送整个对象,但是当我这样做时,我得到了 null。
我正在做这样的事情:
<f:metadata>
<f:viewParam id="id" name="id" value="#{productDetailBean.id}"/>
<f:viewAction action="#{productDetailBean.loadBook()}"/>
<form jsf:id="form" method="post" class="container">
<ul id="variants" class="clearfix">
<li class="buy-option"><input type="radio" name="id"
class="variant-radio"
id="product-variant-#{productDetailBean.book.id}"
value="#{productDetailBean.book.id}" checked="checked" />
<label class="variant-label"
for="product-variant-#{productDetailBean.book.id}"> E-book
+ Impresso </label>
<small class="compare-at-price">R$ #{productDetailBean.book.price}</small>
<p class="variant-price">R$ #{productDetailBean.book.price}</p>
</li>
</ul>
<button type="submit" jsf:action="#{shoppingCartBean.add(productDetailBean.id)}" class="submit-image icon-basket-alt"
title="#{productDetailBean.book.title}">Comprar</button>
还有我的 Bean:
public String add(Integer id){
Book book = bookDao.search(id);
ShoppingItem shoppingItem = new ShoppingItem(book);
shoppingCart.add(shoppingItem);
return "/site/carrinho?faces-redirect=true";
}
我想做以下事情:
<button type="submit" jsf:action="#{shoppingCartBean.add(productDetailBean.book)}" class="submit-image icon-basket-alt"
title="#{productDetailBean.book.title}">Comprar</button>
还有豆子:
public String add(Book book){
ShoppingItem shoppingItem = new ShoppingItem(book);
shoppingCart.add(shoppingItem);
return "/site/carrinho?faces-redirect=true";
}
但是当我这样做时,我得到了一本空书,是否可以这样做?