jQuery in Action, 2nd edition*
The moose likes JSF and the fly likes jsf post to a page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "jsf post to a page" Watch "jsf post to a page" New topic
Author

jsf post to a page

subu ananthram
Ranch Hand

Joined: May 16, 2004
Posts: 102
Hi
I would like to post to a form given an URL how do I do this in jsf What we actually want to do is post from smart phones to an URL
and get back a response from it...
i.e http://www.myform.com is some kinda servlet and I post to this
subu ananthram
Ranch Hand

Joined: May 16, 2004
Posts: 102

Hi
I am really banging my head over this we are developing an application using JSF and I would like to be able to POST to a specific url and on POST I want to invoke a action method
How do I do that in JSF i.e no command button or command link we just want to do http://blablabla.com/app/handle.iface and post to that url somehow and then trigger an action
I could normally do http://blablabla.com/app?action=doStuff and it would trigger doStuff method how do I do it using a url in jsf
Cheers
Priya
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

subu ananthram wrote:

I could normally do http://blablabla.com/app?action=doStuff and it would trigger doStuff method


No you wouldn't. That behavior is something that a special Struts action processor does, and in fact, I stopped using Struts before it even became available. I think it came in with Struts 1.2. One reason I don't do Struts anymore was because of awkward constructs like that.

JSF is based on presenting a View with a Form in it and posting back the Form data, repeating until the action process indicated that a different View was needed. Handling raw GET/POST requests isn't what JSF is all about. However, you can mix servlets, raw JSPs and even Struts actions with JSF if you need to, and they would process POST requests in the normal way.

There are also 2 alternatives within JSF. One is to get the HttpRequest object from the internal JSF context and extract the data by brute force. I don't really recommend this, as it detracts from the portability and testability of the JSF backing beans. Another is to use the PrettyFaces add-on for JSF, but I think that that only works on GET requests.


Customer surveys are for companies who didn't pay proper attention to begin with.
Srini Mutpur
Greenhorn

Joined: Mar 29, 2008
Posts: 24

We can work out this using some alternative approach.

Create invisible h:commandButton inside the same form and click it using javascript on hyperlink click event.

<h:commandButton id="VButton" action="#{managedBean.myAction}" style="display:none;"/>



function submitAction(){
document.getElementById('VButton').click();
}

Hope it may solve your problem.

Srini


SCJP 1.5
subu ananthram
Ranch Hand

Joined: May 16, 2004
Posts: 102
Seems wrong that I need to use hidden buttons to trigger actions on a form what if I needed to write a REST based webservice ?
I will try your option Thanks for your time
Cheers
Priya
Srini Mutpur
Greenhorn

Joined: Mar 29, 2008
Posts: 24

The other option would be make an ajax call onclick on hyperlik and get the response and process it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsf post to a page