我试图将一个简单的复选框附加到素面中的数据列表。复选框用于用户对Purchase Orders进行多个审批。当我不附加复选框时,我单击数据列表,它成功地转到下一页。但是当我附加复选框时,它不成功。任何帮助都将非常感激。谢谢你!
Xhtml:<p:dataList id="poList" value="#{purchaseOrder.purchaseOrders}"
var="po" type="inset">
<f:attribute name="filter" value="true" />
<f:attribute name="placeholder" value="Search" />
<f:attribute name="autoDividers" value="true" />
<f:attribute name="icon" value="grid" />
<f:attribute name="iconSplit" value="true" />
<h:outputLabel for="name" value="Standard Label:" />
<p:column>
<p:commandLink id="poItem" action="pm:poDetails?transition=slide"
update=":poDetailsForm:content" styleClass="selection">
<f:setPropertyActionListener value="#{po}"
target="#{purchaseOrder.po}" />
#{po.poNumber}9 for #{po.vendorName} at <br />
<font color='red'>#{po.moneyValue}</font>
<p:column>
<p:selectBooleanCheckbox id="ApprovePOcb" value=""
itemLabel="Approve" />
</p:column>
</p:commandLink>
</p:column>
<f:facet name="footer">
<strong>#{fn:length(purchaseOrder.purchaseOrders)} PO(s)</strong>
</f:facet>
</p:dataList>
PurchaseOrderMBean:
public class PurchaseOrderMBean implements Serializable
{
List<PurchaseOrder> purchaseOrderList;
PurchaseOrder selectedPo;
public PurchaseOrderMBean()
{
purchaseOrderList = new ArrayList<PurchaseOrder>();
purchaseOrderList.add(
new PurchaseOrder(232324, "ABC", "USD" , 500000.00, "LargeCap"));
purchaseOrderList.add(
new PurchaseOrder(43342, "XYZ", "USD", 700000.00, "MediumCap"));
}
public List<PurchaseOrder> getPurchaseOrders()
{
List<PurchaseOrder> pendingPos = new ArrayList<PurchaseOrder>();
for (PurchaseOrder po : purchaseOrderList)
{
if ((po.getStatus().equals("PEN")))
{
pendingPos.add(po);
}
}
return pendingPos;
}
public void setPo(PurchaseOrder po)
{
selectedPo = po;
System.out.println("PO selected: " + po);
}
public PurchaseOrder getPo()
{
return selectedPo;
}
public void savePurchaseOrder()
{
System.out.println("savePurchaseOrder() called");
}
public void setUpdateStatus(String poid)
{
System.out.println("setUpdateStatus() called");
PurchaseOrder po=(PurchaseOrder)getPurchaseOrder(poid);
po.setStatus("APPROVE");
System.out.println("setUpdateStatus() updated");
}
public String getUpdateStatus()
{
return "";
}
public PurchaseOrder getPurchaseOrder(String poid)
{
PurchaseOrder po=null;
System.out.println("getPurchaseOrder() called");
for (int i=0;i<this.getPurchaseOrders().size();i++)
{
po=(PurchaseOrder)getPurchaseOrders().get(i);
if (po.getPoNumber()==Long.parseLong(poid))
break;
}
System.out
.println("getPurchaseOrder() po returned");
return po;
}
public String gotoDetails()
{
return "po_details?transition=slide";
}
}
我只是卡住了当我添加复选框。我试了很久了
添加调用bean并进行重定向,这样的:
<p:selectBooleanCheckbox id="ApprovePOcb" value="" itemLabel="Approve" />
<p:ajax event="change" listener="#{bean.checkboxChanged}"/>
</p:column>
和在bean做:
public class bean implements Serializable {
//all variabile and methode
public void checkboxChanged() {
try {
FacesContext.getCurrentInstance()
.getExternalContext().redirect("./page.jsf");
}
catch (IOException e) {
//error
}
}
}