You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Marko Asplund <ma...@gmail.com> on 2007/03/23 12:58:36 UTC

Submit form, validate input, open response in new window?

hi

I need to do the following in my JSF application:
- submit a form with input text fields
- validate form input
- if conversion or validation results in errors, show the original form
- if input is ok, open a new window and load a JSF response in it.
Input form window is left unchanged.

One option I can come up with would be to include a piece of
Javascript in the form page on postback that would open up a new
window and load the JSF view in it. Does this sound workable? How do I
generate Javascript code that would result in invoking a JSF action
method in a browser window?

Re: Submit form, validate input, open response in new window?

Posted by Simon Kitching <si...@rhe.co.nz>.
Marko Asplund wrote:
> hi
> 
> I need to do the following in my JSF application:
> - submit a form with input text fields
> - validate form input
> - if conversion or validation results in errors, show the original form
> - if input is ok, open a new window and load a JSF response in it.
> Input form window is left unchanged.
> 
> One option I can come up with would be to include a piece of
> Javascript in the form page on postback that would open up a new
> window and load the JSF view in it. Does this sound workable? How do I
> generate Javascript code that would result in invoking a JSF action
> method in a browser window?

How about:
   <t:div rendered="#{pageBean.showPopup}">
     <f:verbatim>
       <script type="text/javascript">
         window.open("/popup.jsf", "popupwin", "....");
       </script>
     </f:verbatim>
   </t:div>

Then in your method that is connected to the commandButton used to 
submit the page, just set a flag so that showPopup returns true.

The flag will be false initially, so the script won't render. After a 
successful submit, showPopup will return true so the script is rendered 
and the window will open.

Regards,

Simon

Re: Submit form, validate input, open response in new window?

Posted by David Delbecq <de...@oma.be>.
En l'instant précis du 23/03/07 12:58, Marko Asplund s'exprimait en ces
termes:
> hi
>
> I need to do the following in my JSF application:
> - submit a form with input text fields
> - validate form input
> - if conversion or validation results in errors, show the original form
> - if input is ok, open a new window and load a JSF response in it.
> Input form window is left unchanged.
>
> One option I can come up with would be to include a piece of
> Javascript in the form page on postback that would open up a new
> window and load the JSF view in it. Does this sound workable? How do I
> generate Javascript code that would result in invoking a JSF action
> method in a browser window?
when form is valid, your action is called and a navigation occured. In
the page, after navigation, have 2 forms. One is you original form
(probably empty now). The other is a form with only hidden input field
and a target to "_blank". All you javascript has to do is to call the
form_submit() method associated with your hidden form. JSF generate such
javascript function for each form. You just have to call it on page load :)