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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:17:30+00:00 2026-06-09T18:17:30+00:00

I wonder what is the common way to use get request, parameters and ajax

  • 0

I wonder what is the common way to use get request, parameters and ajax requests together with JSF?

What I want to achieve is to pass an id parameter to a JSF page, retrieve the entity with the given parameter from the database and display the entity on the JSF page. Then, I want to make some changes to the entity and populate it back to the database (via ajax).

I stuck on the step, where I want to populate the changes back to the database. Here is what I have so far:

I have a very simple JSF page and a controller (ManagedBean).

JSF page

<h:body>
    <h:form id="myForm">
        <p:messages />
        <h:panelGrid columns="3">
            <h:outputLabel value="#{requestController.id}" />
            <p:commandButton value="Update" action="#{requestController.updateEntity}" update="myForm" />
        </h:panelGrid>
    </h:form>
</h:body>

Controller

@Component("requestController")
@Scope("request")
public class RequestController {

@Value("#{request.getParameter('id')}")
private String id;

private String entity;

@PostConstruct
public void init() {
    if(id == null || id.equals("")) {
        entity = "Entity not found";
    }
    else if("1".equals(id)) {
        entity = "FirstEntity";
    }
    else {
        entity = "SecondEntity";
    }
}

public String getEntity() {
    return entity;
}

public void updateEntity() {
    entity += "_updated";
}

public String getId() {
    return id;
}
}

I can open the JSF page with an id parameter and the entity will be displayed correctly. But, when I click on the update button, the Controller will be newly instantiated and the id parameter is gone.

What is the common way to handle request parameters together with ajax requests in JSF?

  • 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-06-09T18:17:32+00:00Added an answer on June 9, 2026 at 6:17 pm

    Solution is to add the request parameter at every request in the page. This can be done with the <f:param> tag.

    So, to make the above code work, you just have to include the initial request parameter to the command button:

    <p:commandButton value="Update" action="#{requestController.updateEntity}" update="myForm" >
        <f:param name="id" value="#{requestController.id}" />
    </p:commandButton>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder what is the easiest and more common way to get the N-th
I wonder what folks use as a common data access pattern on Android? Content
Im newish to objective-c and am starting to wonder what is the common/standard/proper way
I want to pass ;;; string as a string parameter in my Ant task:
I want to use expression: !([1,2,3] & [43,5]).empty? => false !([1,2,3] & [3,5]).empty? =>
I want to have a common control library with a whole bunch of User
I wonder what is the best way to implement dynamic domain model persisted in
I wonder if there is a common mechanism implemented in operating systems to minimize
We have a request to use a select element's onchange to trigger a move
I want to use jQuery to create an effect of a line drawing being

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.