Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF post form data

 
Kevin Gutch
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is probably a very basic problem but I am not sure how to solve it.
I would like to use a commandLink actionListener to post some data to a specific URL as such http://api.mypage?data1=.

However, I do not want to go to the page (which is what happens if I post the form from a commandLink).

Can anyone suggest a method for doing this?

Thanks

Kevin
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18094
48
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTTP is a request/response protocol. Regardless of whether you're programming in JSF, Struts, raw JSP, servlets, or even Perl or Python, assembly Lnaguage, C or FORTRAN, the #1 rule is this:

For every request there must be a response.

It's why no HTTP service can ever do do true MVC - an HTTP server cannot send out an unsolicited response, and it's why you can't have what you want; every request must be followed by a response. Even AJAX isn't immune to that most fundamental of strictures.

On the other hand, in JSF, the default response is to redisplay the requesting JSF page, so visually it makes no difference other than a delay and maybe a screen flicker.

If, however, you want your page to post data to some other location and remain on the current page, what you can do is have the JSF action method do an HttpURLConnection request from the JSF server to the other location. Which can be on the same server or any other server in the world, as long as the JSF server can access it. The Secondary server must response with something, since it's subject to the First Law of HTTP, although a simple empty "200 OK" status is good enough. Once your JSF backing bean's action method sees that response, it can then complete its action - or, if something went wrong, it can throw an exception or something.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic