Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF app, actions don't work if a different action has been invoked previously
    primarykey
    data
    text
    <p>I'm learning Java EE 6 and JSF 2.0 on JBoss6 and have built a <em>very</em> simple 1 page "Todo" app which works but with a very strange bug. Tested in Safari 5.0.5 and Firefox 5.</p> <p>There are two actions you can do (add a todo and check/uncheck todos). It all works, but not the first time an action is done after a different action has been done.</p> <p>And example usage might look like this:</p> <ol> <li>try to add a todo = success</li> <li>try to add a todo = success</li> <li>try to check a todo = fail</li> <li>try to check a todo = success</li> <li>try to add a todo = fail</li> <li>try to add a todo = success</li> <li>try to check a todo = fail</li> </ol> <p>The app has the following basic files (plus other bits and pieces):</p> <ul> <li>entities/Todo.java &lt;- JPA entity</li> <li>managers/TodoManager.java &lt;- EJB for handing the Todo entities, @Stateless</li> <li>controllers/TodoController.java &lt;- managed bean for the page, @SessionScoped </li> <li>todos.xhtml &lt;- the JSF page</li> </ul> <p>No faces-config.xml</p> <p>The form to add a todo looks like this:</p> <pre><code>&lt;h:panelGroup id="projects"&gt; &lt;h:message for="newtitle" /&gt; &lt;h:form id="newtodo"&gt; &lt;h:panelGrid columns="5"&gt; &lt;h:outputText value="New Todo: "/&gt; &lt;h:inputText id="newtitle" value="#{todoController.todo.title}" /&gt; &lt;h:outputText value="Due: "/&gt; &lt;h:inputText id="newDueDate" value="#{todoController.todo.dueDate}"&gt; &lt;f:convertDateTime pattern="dd/mm/yyyy"/&gt; &lt;/h:inputText&gt; &lt;h:commandButton action="#{todoController.addTodo}" value="add"&gt; &lt;f:ajax execute="@form" render=":projects"/&gt; &lt;/h:commandButton&gt; </code></pre> <p>the form to check/uncheck the todo "done" status looks like this:</p> <pre><code>&lt;h:form&gt; &lt;h:dataTable id="todolist" var="t" value="#{todoController.todolist}"&gt; &lt;h:column&gt; &lt;h:selectBooleanCheckbox id="rowCheckbox" value="#{t.done}" &gt; &lt;f:ajax event="click" listener="#{todoController.updateDone(t)}" render=":projects"/&gt; &lt;/h:selectBooleanCheckbox&gt; &lt;/h:column&gt; </code></pre> <p>TodoController looks like this:</p> <pre><code>@ManagedBean(name="todoController") @SessionScoped public class TodoController { @EJB private TodoManager todoManager; private Todo todo = new Todo(); private ArrayList&lt;Todo&gt; todolist = new ArrayList&lt;Todo&gt;(); public String addTodo() { todo.setDone(false); todo.setUser(this.getLoggedInUser()); todoManager.addTodo(todo); todo = null; return "todos.xhtml"; } public String updateDone(Todo t) { t.setDone(!t.getDone()); todoManager.updateTodo(t); return "todos.xhtml"; } </code></pre> <p>I did add logging messages to addTodo() and updateDone(Todo t) to verify when they get called. When the actions are "not working" they in fact don't seem to get called at all. :-(</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.
 

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