Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a view scoped bean. It should work. The problems which you describe there suggests that you're binding it to JSTL tags or <code>id</code> or <code>binding</code> attributes. You should not do that on a view scoped bean. See also <a href="http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#ViewScopedFailsInTagHandlers" rel="nofollow"><code>@ViewScoped</code> fails in tag handlers</a>. Another possible cause is that you're using CDI's <code>@Named</code> to manage the bean instead of JSF's <code>@ManagedBean</code>. That would also explain why <code>@ManagedProperty</code> doesn't work in one of your attempts as it also requires the bean to be managed by JSF's <code>@ManagedBean</code>.</p> <p>As to the master-detail page approach, use a <code>&lt;h:link&gt;</code> with <code>&lt;f:param&gt;</code> in the table page to create view/edit links in the master page.</p> <p>E.g. <code>user/list.xhtml</code></p> <pre class="lang-html prettyprint-override"><code>&lt;h:dataTable value="#{userList.users}" var="user"&gt; &lt;h:column&gt;#{user.id}&lt;/h:column&gt; &lt;h:column&gt;#{user.name}&lt;/h:column&gt; &lt;h:column&gt; &lt;h:link value="Edit" outcome="edit"&gt; &lt;f:param name="id" value="#{user.id}" /&gt; &lt;/h:link&gt; &lt;/h:column&gt; &lt;/h:dataTable&gt; </code></pre> <p>The bean can be just request scoped.</p> <p>Then, in the defail page, which is in this case an edit page, use <code>&lt;f:viewParam&gt;</code> to convert, validate and set the <code>id</code> as <code>User</code>.</p> <p>E.g. <code>user/edit.xhtml</code></p> <pre class="lang-html prettyprint-override"><code>&lt;f:metadata&gt; &lt;f:viewParam name="id" value="#{userEdit.user}" converter="#{userConverter}" converterMessage="Bad request. Unknown user." required="true" requiredMessage="Bad request. Please use a link from within the system." /&gt; &lt;/f:metadata&gt; &lt;h:messages /&gt; &lt;h:link value="Back to all users" outcome="users" /&gt; &lt;h:form id="user" rendered="#{not empty userEdit.user}"&gt; &lt;h:inputText value="#{userEdit.user.name}" required="true" /&gt; ... &lt;h:commandButton value="Save" action="#{userEdit.save}"&gt; &lt;f:ajax execute="@form" render="@form" /&gt; &lt;/h:commandButton&gt; &lt;/h:form&gt; </code></pre> <p>Use a <code>@ViewScoped</code> bean to hold the data, service and action methods:</p> <pre><code>@ManagedBean @ViewScoped public class UserEdit { private User user; @EJB private UserService service; public String save() { service.save(user); return "users"; } // Getter+setter. } </code></pre>
    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.
 

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