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 6998543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:25:29+00:00 2026-05-27T20:25:29+00:00

I have two image buttons: <div class=sidebarOptions> <input type=image src=images/homeButton.jpg onclick=#{home.setRendered(1)}/> </div> <div class=sidebarOptions>

  • 0

I have two image buttons:

<div class="sidebarOptions">
    <input type="image" src="images/homeButton.jpg" onclick="#{home.setRendered(1)}"/>
</div>
<div class="sidebarOptions">
    <input type="image" src="images/memberButton.jpg" onclick="#{home.setRendered(2)}"/>
</div>

However, the both methods are immediately invoked when the page loads with values 1 and 2. Also when I click it, the both methods are invoked.

How can I achieve the desired functionality of only calling the bean method when the image button is actually clicked?

  • 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-27T20:25:30+00:00Added an answer on May 27, 2026 at 8:25 pm

    This approach will not work. You seem to be confusing/mixing the basic web development concepts of the “server side” and “client side” and to be misunderstanding the role of JSF and EL.

    JSF is a server side language which runs on the webserver upon a HTTP request and produces HTML/CSS/JS code which get returned with the HTTP response. All EL expressions in form of ${} and #{} will be executed in the server side during generating the HTML output. JavaScript is a client side language which runs on the webbrowser and works on the HTML DOM tree. The HTML onclick attribute should specify a JavaScript function which will be executed in the client side on the particular HTML DOM event.

    In order to invoke a JSF managed bean method, you need the action or *listener attribute. JSF provides components to generate the desired HTML and specify the desired ajax actions which would change the server side state. An <input type="image"> can be generated using a <h:commandButton image>. A bean method can be invoked by the action attribute of that component. That component can be ajaxified by embedding the <f:ajax> tag.

    So, the following should do it for you:

    <h:form>
      <div class="sidebarOptions">
        <h:commandButton image="images/homeButton.jpg" action="#{home.setRendered(1)}">
          <f:ajax execute="@this" render=":sidebar" />
        </h:commandButton>
      </div>
      <div class="sidebarOptions">
        <h:commandButton image="images/memberButton.jpg" action="#{home.setRendered(2)}">
          <f:ajax execute="@this" render=":sidebar" />
        </h:commandButton>
      </div>
    </h:form>
    
    <!-- The below is just a guess of what you're really trying to achieve. -->
    <h:panelGroup id="sidebar" layout="block">
      <h:panelGroup rendered="#{home.rendered eq 1}">
        Home
      </h:panelGroup>
      <h:panelGroup rendered="#{home.rendered eq 2}">
        Member
      </h:panelGroup>
    </h:panelGroup>
    

    See also:

    • Differences between action and actionListener
    • How to invoke a managed bean action method in on* attribute of a JSF component
    • How to invoke a JSF managed bean on a HTML DOM event using native JavaScript?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine you have two images A and B, and a third grayscale image T.
I have a two sprite images. One image contains the body of a rounded
I have a search textbox and two image buttons on a page I created
i have two buttons in menu on mouse over the button change image to
So, I have a DIV full of four HTML buttons that use an image
I have two image buttons with Click events assigned to them. There is code
I have two clickable images inside a div . They jump 3-6 pixels when
I am trying to something pretty simple. I have two buttons inside a div.
Here is a simplified version of my database model. I have two tables: Image,
I have two models, Room and Image . Image is a generic model that

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.