[英]PrimeFaces page Redirecting when checkbox is clicked
I am trying to attach a simple checkbox to a datalist in primefaces. 我试图将一个简单的复选框附加到质数表的数据列表中。 The checkbox is for the user to do multiple approvals for Purchase Orders. 该复选框供用户对采购订单进行多次批准。 When I do not attach the checkbox, I click on the datalist and it goes to next page successfully. 当我不附加复选框时,我单击数据列表,然后成功进入下一页。 But when I do attach the checkbox, it is not successful. 但是当我附加该复选框时,它不会成功。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thank you! 谢谢!
Front End Xhtml: 前端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: 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";
}
}
I just get stuck when I add in the checkbox. 当我添加复选框时,我只是卡住了。 Been trying for very long. 尝试了很长时间。
Add to call a bean and do a rederict, like this: 添加以调用bean并重新执行,如下所示:
<p:selectBooleanCheckbox id="ApprovePOcb" value="" itemLabel="Approve" />
<p:ajax event="change" listener="#{bean.checkboxChanged}"/>
</p:column>
and in the beans do: 然后在豆子里做:
public class bean implements Serializable {
//all variabile and methode
public void checkboxChanged() {
try {
FacesContext.getCurrentInstance()
.getExternalContext().redirect("./page.jsf");
}
catch (IOException e) {
//error
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.