D
D
Dmitry2014-08-02 13:52:47
JavaScript
Dmitry, 2014-08-02 13:52:47

How to write an ajax request that returns an .xhtml page in JSF?

I am writing a project using JSF.
One of the .xhtml pages has the following table of users.

<ui:repeat value="#{UsersAction.usersList}" var="item">
  <tr style="cursor: pointer;" onclick="javascript:load(#{item.id}, this)">
    <td><h:outputText value="#{item.username}" /></td>

In which, each line calls the JS script (passing the user id). In which there is an ajax request that should send an asynchronous request to the server with id and return a filled page with the edit form of the selected user.
function load(id,e) {
    console.log(id);
  
    $.ajax({
        type: 'POST',
        url:'#{UsersAction.asyncLoadUser()}?id=' + id, 
        dataType: 'text',
        success: function(data){
           $("#table_div").html(data);
                },
 	error : function(xhr, errmsg) {alert("No values found..!!");}
    });
  }

The bean has a method that accepts a request.
public String asyncLoadUser() {	
    loadUser = usersLogic.selectUserById(id);
    return "editUser.xhtml";
  }

But in this case, the parameter is not passed and the page with an empty form is returned, I tried several options, for example, using the built-in tag in JSF for asynchronous requests, but when using it, it is not possible to return the page ..

Who knows how to achieve the desired result? Tell me please.

PS I can provide more information if needed
Thank you in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question