Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, it's definitely possible. Just bring in some good shot of JavaScript and/or CSS to show/hide and style the popup window. That's also what the average component library like RichFaces is doing with the only difference that it's all wrapped in a simple JSF component.</p> <p>At its simplest you can use JS <code>window.open()</code> on click of a button/link.</p> <pre class="lang-xml prettyprint-override"><code>&lt;h:commandButton value="Edit" onclick="window.open('edit.jsf?id=#{item.id}'); return false;" /&gt; </code></pre> <p>The <code>window.open()</code> allows for fine grained customization of the window, such as the size and the browser bars which are to be displayed/hidden. Read the <a href="https://developer.mozilla.org/en/DOM/window.open" rel="nofollow">MDN documentation</a> to learn about them. Returning <code>false</code> is mandatory to prevent the button from unnecessarily submitting the form.</p> <p>Then, in the constructor of the backing bean associated with <code>edit.jsf</code>, you can grab the item by the <code>id</code> which is been passed as request parameter.</p> <pre><code>private Item item; public EditItemBean() { String id = (String) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"); this.item = someItemService.find(Long.valueOf(id)); } </code></pre> <p>Nasty, but that's what you get with JSF 1.1 which doesn't offer a JSF 1.2-supported <code>@PostConstruct</code> annotation or JSF 2.0-supported <code>&lt;f:viewParam&gt;</code> tag.</p> <p>Finally, in the <code>edit.jsf</code> you need to bring in some conditionally rendered JavaScript piece which reloads the parent window (so that the edited data is redisplayed) and closes the popup window.</p> <pre class="lang-xml prettyprint-override"><code>&lt;h:form&gt; ... &lt;h:commandButton value="Save" action="#{editItem.save}" /&gt; &lt;/h:form&gt; &lt;h:panelGroup rendered="#{editItem.success}"&gt; &lt;script type="text/javascript"&gt; window.opener.location.reload(true); window.close(); &lt;/script&gt; &lt;/h:panelGroup&gt; </code></pre> <p>Set the <code>success</code> boolean in the action method when the saving is successful.</p> <pre><code>public void save() { // ... this.success = true; } </code></pre> <p>There exist also solutions using a so-called "overlay window" dialog which is basically <code>&lt;div&gt;</code> which is positioned using CSS <code>position: fixed;</code> and spans the entire browser window with a transparent background and then therein another <code>&lt;div&gt;</code> which is centered and contains the real form. This however requires a bigger shot of JS/CSS. This is also what the average JSF component library and JavaScript framework/plugin (such as jQuery or YUI) is basically doing. It's only trickier to get it work seamlessly together with JSF as you would of course like to redisplay the popup when a validation error on the popup form occurs and that kind of things. It's much easier if you're using an ajax-enabled JSF implementation/library.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload