Note that there are some explanatory texts on larger screens.

plurals
  1. POJsf pages don't show newly added values
    text
    copied!<p>I'm using Java EE6 and JSF for making a simple CRUD application.</p> <p>In many of my JSF pages, I have a selectOneMenu for the user to select an existing item. For example, if the user is adding an "Exam", he/she can choose a "Department" from the combo-box, since they have a one-to-many relationship.</p> <p>The problem is that whenever a new Department is added, the combo-box values are not updated until the session times out. I need to use SessionScoped backing beans, because I need the values to persist across multiple Requests.</p> <p>Here is a function I'm using to populate the selectOneMenu (not exactly as the example described above, but very similar):</p> <pre><code>public SelectItem[] getExamsByDepartment(){ if(departmentMaster!=null){ Collection&lt;ExamMaster&gt; examMasterCollection = departmentMaster.getExamMasterCollection(); //Problem: newly added exams aren't shown until session is re-created if (examMasterCollection != null &amp;&amp; examMasterCollection.size() &gt; 0) { SelectItem[] selectItem = new SelectItem[examMasterCollection.size()]; Iterator&lt;ExamMaster&gt; i = examMasterCollection.iterator(); int count = 0; while (i.hasNext()) { ExamMaster tmpExamMaster = i.next(); selectItem[count++] = new SelectItem(tmpExamMaster, tmpExamMaster.getExamName()); } return selectItem; } } SelectItem[] selectItem = new SelectItem[1]; selectItem[0] = new SelectItem("", "[No exams found]"); return selectItem; } </code></pre> <p>Is there any workaround by which I can destroy and re-create the Session? Or any other way by which I can solve this problem?</p> <p>EDIT: I guess the issue boils down to why the Collection doesn't update after inserting a record, even though the one-to-many relationship is defined in the Persistence class</p> <p>EDIT 2: Instead of using the collection, I am using a Named Query now, and it fetches the new record as expected. I had assumed that the Collection should be updated automagically. Perhaps that is not true?</p>
 

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