Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3311986
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:56:27+00:00 2026-05-17T21:56:27+00:00

I have one command button for task add to cart, it means when items

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T21:56:28+00:00Added an answer on May 17, 2026 at 9:56 pm

    The empty keyword of Expression Language will check if the given property is null or empty. So in your case, use not empty:

    <h:commandButton ... rendered="#{not empty myBean.myList}"/>
    

    So this button will only be displayed when the list exists and is not empty.

    Another idea is to provide a specific method:

    public boolean isCommandButtonRendered() {
        return myList != null && !myList.isEmpty();
    }
    

    and use it in the XHTML code:

    <h:commandButton ... rendered="#{myBean.commandButtonRendered}"/>
    

    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 null or 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 to 0 or not.

    I don’t know the code of your Items class, so I will consider that this class holds a instock int property.

    So as far as I know, you iterate on your List within a datatable:

    <h:datatable var="item" value="#{catItemsListController.quantityOnHand}" ...>
        ...
        <h:column>
            <h:commandButton ... rendered="#{item.instock gt 0}"/>
        </h:column>
    </h:datatable>
    

    As shown in my code, you have a commandButton that will be displayed only if the value of instock of the item element is greater than (gt) 0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two JavaScript code snippets. These perform specific task when an 'Update' button
i have one function in jquery like this $(#Button_save).click(function() { Save Command; }); this
I have one <form id=inputdefect> ,and one <input id=item> , but inside that I
I have two JSF <h:selectOneMenu> components. One called category another is subcategory . If
In my WPF application I have 2 Windows (both Windows have their own ViewModel):
(Please forgive my ignorance on Excel add-ins, and feel free to correct my teminology
I have a / group of radio buttons , and a CommandButton Two cases
I have a page start.jsf which points to an action #{ruler.start}, this action forwards
We have a requirement in application that on clicking on all images which do
Weird behaviour, I'm sure it's me screwing up, but I'd like to get to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.