Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I transport an entity from one jsf-view to another?
    primarykey
    data
    text
    <p>I have the following structure:</p> <p><strong>listView.xhtml</strong></p> <pre><code>&lt;h:dataTable value="#{listBean.myList} ...&gt; //for every row I create a commandLink &lt;h:commandLink action="editView" value="edit" /&gt; &lt;/h:dataTable&gt; </code></pre> <p><strong>ListBean.java</strong></p> <pre><code>@ManagedBean @ViewScoped public class ListBean{ public List&lt;Entity&gt; myList; // also getters and setters } </code></pre> <p><strong>editView.xhtml</strong></p> <pre><code>&lt;h:inputText value="#{editBean.selectedEntity.name}" /&gt; </code></pre> <p><strong>EditBean.java</strong></p> <pre><code>@ManagedBean @ViewScoped public class EditBean{ public Entity selectedEntity; // also getters and setters } </code></pre> <p>You know the question: How can I transport the selected Entity from listView to editView? This should be very simple I thought, but after a whole day, I didnt get it work.</p> <p>I tried different stuff, like <strong><code>@ManagedProperty</code></strong> and <strong><code>&lt;f:param name="" value=""&gt;</code></strong> but I didnt help me. So please, show me how simple and nice this can be :)</p> <p>Thanks in advance!</p> <hr> <p><em><strong>UPDATE - Solution#1</em></strong></p> <p>Thanks to Daniel, a possible way that works is, when the entity is hold by an EntityManager, so you can access the entity by its id. So you will pass the id as an request Parameter. Here we go:</p> <p><strong>listView.xhtml</strong></p> <pre><code>&lt;h:dataTable value="#{listBean.myList} ...&gt; //for every row I create a commandLink, so you can click on that entity to edit it &lt;h:commandLink action="editView" value="edit"&gt; &lt;f:param name="selectedEntityId" value="#{entity.id}" /&gt; &lt;/h:commandLink&gt; &lt;/h:dataTable&gt; </code></pre> <p><strong>EditBean.java</strong></p> <pre><code>@ManagedBean @ViewScoped public class EditBean{ private Entity selectedEntity; @PostConstruct public void init() { Map&lt;String, String&gt; params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); long selectedEntityId = Long.parseLong(params.get("selectedEntityId")); selectedEntity = SomeEntityManagerUtil.getEntity(selectedEntityId); } } </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.
 

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