aspose file tools*
The moose likes JSF and the fly likes JSF Form post to external URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF Form post to external URL" Watch "JSF Form post to external URL" New topic
Author

JSF Form post to external URL

Pedro blacap
Greenhorn

Joined: Apr 27, 2011
Posts: 5
Hello ...

Im begginer in JSF and have a problem ... i hope someone could bring me some light

I want to send a POST request to a external URL sending some pairs name-value

I want to submit this:

<form action="http://www.externalSystem.com">
<input type="hidden" name="name" value="value" />
</form>

this action gets the navigation gets redirected to http://www.externalSystem.com outside my application. Thats what i want to do.
But i dont know how

Of course, i need that the gode gets generated dynamically because i need some data that is stored into a managed session bean
I know i can ...

<h:form>
<h:inputHidden id="name" value="#{myBean.value}" />
</h:form>

but i cant set the action of the form ... how can i declare the target for the request?

Thanks thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15632
    
  15

If you're going to send form data to a non-JSF target, use the vanilla HTML <form> tag, not the JSF <h:form> tag. That applies to both "external" URLs and non-JSF targets (JSPs and servlets) within a JSF app. The JSF form tag is designed to facilitate JSF postback operations, which is why it has no "action" attribute.


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

Joined: Apr 27, 2011
Posts: 5
Tim Holloway wrote:If you're going to send form data to a non-JSF target, use the vanilla HTML <form> tag, not the JSF <h:form> tag. That applies to both "external" URLs and non-JSF targets (JSPs and servlets) within a JSF app. The JSF form tag is designed to facilitate JSF postback operations, which is why it has no "action" attribute.


Hi Tim!

Thanks for the suggestion but i have a problem with that ... i explain:

I could use vanilla static HTML (i will be happy doing that) but the values of the parameters (name/value pairs) are stored in a managed session bean.
How can i access the managed session bean from an HTML document?? ... i was thinking in JSTL but i dont know how to access to the jsf-managed bean only with jstl, i think in facelets, too, but i dont know if its possible and dont know how to do that with facelets.

i need something like ...

<form action="http://www.externalSystem.com">
<input type="hidden" name="name" value="#{mybean.fieldName}" />
</form>

... yeah ... could be also like ...

<h:form>
<h:hidden id="name" value="#{mybean.fieldName}" />
</h:form>

... but cant send it to the target.

Im trying to generate the POST request dynamically into a bean method and call that method from the jsf document with commandButton ...
... but it seems very awful to me ... :P :P ... i dont like it.

Thanks again.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15632
    
  15

JSF's session objects are the exact same thing as JSP/servlet session objects. The only difference is that JSF can automatically create them when they're referenced.

Your first (non-JSF) form example is just fine. Try it and see!
Pedro blacap
Greenhorn

Joined: Apr 27, 2011
Posts: 5
Tim Holloway wrote:JSF's session objects are the exact same thing as JSP/servlet session objects. The only difference is that JSF can automatically create them when they're referenced.

Your first (non-JSF) form example is just fine. Try it and see!


Oohh!! ... really?!

i made a turnarround compounding the url in the bean and sending it ...

String url ="http://www.externalSystem.com";
url = url + "?";
String paramString = "name="+mybean.field.toString();
FacesContext.getCurrentInstance().getExternalContext().redirect(url);

but i dont like it because it shows the url in the navBar and ... its awful.

I will try your suggestion!

... so ... i dont need any JSF declaration (f:vew, f_form) in order to make EL #{xxx} able to access to the managed beans?! ... that could be great!!
... also i dont need any importing or declaration? ... like the old jsp:useBean or something like that??

Thank you!!

I will try and post.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15632
    
  15

You can use "useBean" for traditional stuff, but EL has its own variable name resolvers, so that stuff doesn't need useBeans.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSF Form post to external URL
 
Similar Threads
JSF client side state saving
simple jsf form
appling ozeki send message to jsf application
JSF/JSP
Trying to post to an external jsp (jsf) service...