I have one command button for task add to cart, it means when items quantity instock is geater than 0 command button will display but if items quantity instock is 0 it doesn’t display.
How can i write one method render with command button for my upon requirement?
Edited
=================================================================================
i post my code attach with question following:
i write one method in Session Bean select list of Quantity on hand in stock are zero following:
public List<Items> checkItemsInstock(){
Query query = em.createNamedQuery("Items.findByInstockgtZero");
query.setParameter("instockgtzero", 0);
return query.getResultList();
}
and Namequery is:
@NamedQuery(name = "Items.findByInstockgtZero", query = "SELECT i FROM Items i WHERE i.instock = :instockgtzero")
in JSF Managed Bean i wrote a method return list of items , and Quantity on hand are zero
public List<Items> getQuantityOnHand(){
return itemDAO.checkItemsInstock();
}
and in JSF Page i was rendered h:commandButton is:
<h:commandButton value="add to cart" style="font-size: x-small" action="#{catItemsListController.addtoCart(item)}" id="addcart" rendered="#{not empty catItemsListController.quantityOnHand}"/>
but it not work, all items have QOH is zero or not zero are display CommandButton
i need help !
Thank you
The
emptykeyword of Expression Language will check if the given property isnullor empty. So in your case, usenot empty:So this button will only be displayed when the list exists and is not empty.
Another idea is to provide a specific method:
and use it in the XHTML code:
Edit
I think there is a misunderstanding on what you expect regarding the solution I provided. My solution is working if you want to test the list itself (i.e. the list is
nullor does not contains any element).In your case, it seems that your list is not empty, but contains elements (objects
Items) that has a value that can be equals to0or not.I don’t know the code of your
Itemsclass, so I will consider that this class holds ainstockintproperty.So as far as I know, you iterate on your
Listwithin adatatable:As shown in my code, you have a
commandButtonthat will be displayed only if the value ofinstockof theitemelement is greater than (gt)0.