Ended this week with this unresolved problem. A Clear button is supposed to clear some input fields and some dropdown selections from the form. Nothing is needed to be submitted from the form, I just use execute="@this" in the f:ajax tag. I send two parameters to the action method: a record id and its index in the list of records held in a model SessionScope bean.
The action method looks like:
public void clear(Integer id, Integer index)
{
// param id is used for logging and for checking
Employee emp = model.getEmployeeList().get(index);
emp.setCorrectedTitle(null); // wipe out
emp.setCorrectedManager(null); // wipe out
emp = DAO.update(emp);
model.getEmployeeList().set(index, emp);
}
At this moment I run manually a query in MySql and the employee record has been updated as requested, all other fields are intact, specially the primary key. When the ajax request returns the page still shows the same old data for the 'title' and 'manager' fields.
Why the page is not refreshed? the model was updated in the action method so I assume the render phase should see the wiped out fields but I guess it didn't.
On top of my head this is how the h:commandLink looks like:
<ui:repeat value="#{model.employeeList}" var="employee" varStatus="status">
<h:panelGroup id="container">
<h:inputText value="#{employee.correctedTitle}" />
....link goes here...
</ui:repeat>
<h:commandLink value="Clear"
action="#{bean.clear(employee.id, status.index)}">
<f:ajax render="container" execute="@this"
onevent="monitorclear" />
</h:commandLink>
My env is Java 6, Glassfish 3.1.2 with Mojarra 2.1.18, NetBeans 7.4 with Java 7. No chance of any upgrade.
please any idea what I am doing wrong. thanks.
EDIT. Ok, here is the simplidied code.
This is the details.xhtml page:
<ui:define name="content">
<h:form id="detailForm">
<h:messages id="messages" />
<ui:include src="/WEB-INF/include/employees.xhtml"/>
</h:form>
<div id="freeow"></div>
</ui:define>
The employees.xhtml page:
<ui:composition ...>
<h:panelGroup id="employees" layout="block">
<ui:repeat id="employeeRepeat" value="#{beanDetail.employeeList}" var="employee" varStatus="status">
<h3 class="employeeInfoH3">
<h:panelGroup id="employeeInfoH3" layout="block">
<h:outputText id="status" value="#{employee.status}" />
</h:panelGroup>
</h3>
<h:panelGroup id="employeeInfoDiv" class="employeeInfoDiv" layout="block">
<ui:include src="#{beanDetail.employeeFile>
<ui:param name="employee" value="#{employee}"/>
</ui:include>
<h:panelGroup id="detailButtons" class="detailButtons" layout="block">
<h:commandLink id="revertCall"
action="#{beanDetail.revertChangesToEmployeed, status.index)}"
value="Revert">
<f:ajax render=":detailForm:messages :detailForm:employeeRepeat:employeeInfoH3 :detailForm:employeeRepeat:employeeInfoDiv"
onevent="monitorClearOrRevertCall"
execute="@this" />
</h:commandLink>
</h:panelGroup>
</h:panelGroup>
</ui:repeat>
</h:panelGroup>
</ui:composition>
Finally the page with the fields to clear out, employeeFile.xhtml:
<ui:composition...>
<fieldset class="employeeInput">
<legend>Updated Information</legend>
<p class="rightInfo">
<h:outputLabel for="correctedTitle">Corrected Title:</h:outputLabel>
<h:inputText id="correctedTitle" value="#{employee.correctedTitle}" />
</p>
<p class="rightInfo">
<h:outputLabel for="correctedEmployeeStatus">Corrected Status</h:outputLabel>
<h:selectOneMenu id="correctedEmployeeStatus" value="#{employee.correctedEmployeeStatus}">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItem itemLabel="Permanent" itemValue="P" />
<f:selectItem itemLabel="Contractor" itemValue="C" />
<f:selectItem itemLabel="Student" itemValue="S" />
</h:selectOneMenu>
</p>
</fieldset>
</ui:composition>
One thing I noted is I have to prefix the name of the form with colon, :detailForm, even when all fields are inside the form.