• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF Form post to external URL

 
Pedro blacap
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pedro blacap
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18098
50
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use "useBean" for traditional stuff, but EL has its own variable name resolvers, so that stuff doesn't need useBeans.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic