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

  • SEARCH
  • Home
  • 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 1084861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:36:57+00:00 2026-05-16T22:36:57+00:00

Some background: I am building a custom JSF component. The component is basically a

  • 0

Some background: I am building a custom JSF component. The component is basically a text editor and it should have a “Save” -button for saving the content string of the editor. As I am using the CodeMirror library, I need to fetch the content (string) from the editor with javascript and send that to the server. Therefore, in this case I cannot use XML-based JS invocation such as f:ajax.

The question: I was planning to send the string with jsf.ajax.request, but it doesn’t directly support calling methods on beans. How can I invoke a method in a bean with JSF in AJAX manner?

There at least two ways to get around this:

  • Include a hidden form to page with hidden inputfield. Update that inputfield from javascript and then call jsf.ajax.request to post that form. Custom actions can be invoced in the property’s getter or setter if needed.
  • Do the request with raw XMLHttpRequest (or maybe with help from some other JS library). Create a servlet and call that.

Both ways are clumsy and the latter also breaks out of JSF scope.

Am I missing something? How do you do these?

There is a quite similar question, but the answers given only refer to XML-based AJAX invocations. There is also another similar question, but that refers to XML-based AJAX calls as well.

  • 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-16T22:36:58+00:00Added an answer on May 16, 2026 at 10:36 pm

    I couldn’t find out how to call beans direcly with javascript, but here is a hack around calling f:ajax-declaration from javascript:

    1) Create a hidden form with fields for all the data that you want to send to the server. Include a h:commandButton as well:

    <h:form id="hiddenForm" style="display: none;">
        <h:inputHidden id="someData" value="#{someBean.someData}" />
        <h:commandButton id="invisibleClickTarget">
            <f:ajax execute="@form" listener="#{someBean.myCoolActionOnServer()}" />
        </h:commandButton>
    </h:form>
    

    As usual, listener attribute, #{someBean.myCoolActionOnServer()} in this case, refers to the method that you want to execute on the server.

    2) In some other button use onclick to call for your special javascript AND click the trigger-button via javascript:

    <h:commandButton value="Click me" onclick="populateTheForm('hiddenForm'); document.getElementById('hiddenForm:invisibleClickTarget').click(); return false;" />
    

    populateTheForm() should actually fill the data into hiddenForm’s fields.

    This is a simplification of my case but should work. Still looking for more conventient approach, though.

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

Sidebar

Related Questions

I am building a Recent Activity page just to give some background. Basically this
Some background I'm currently building a predominantly classic web app (rather than a single
Some Background to begin: I've implemented a custom MembershipProvider that validates a user from
Right now I'm building a project management app in rails, here is some background
Right now I'm building a project management app in rails, here is some background
Some Background: I have a VS 2008 Deployment project I am not using the
First some background: I already have a Result class that I've implemented to carry
I am building an application at work and need some advice. I have a
I'm building a monitor app and am having some threading issues. I have, using
Some background: For a project I'm working on (building an XML DOM from a

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.