|
Hey guys, I’ve got a tricky problem I’m hoping someone
has run into before. I have a dataTable with rows that, among other
things, have a selectOneMenu in them. Whenever I change the value of a
menu, I want to persist its new value in my database (I am using JPA…Glassfish’
implementation of EJB 3.0). The problem I’m having, is that once I
get the new value of the selectOneMenu in my updateTaskStatus backing bean
method, I don’t have a way of knowing what the corresponding row is that
contained the selectOneMenu. I’ve found several _similar_ examples using a selectOneMenu
with the dataTable, but in all cases, they have not set the initial value of
their selectOneMenu to the value of their table’s DataModel. As you can see, I am referencing “item.status”,
where “item” is the current row in my dataTable. I am using
item.status here because I need to set the initial value of the selectOneMenu to
whatever that particular row’s status is in the database. So, you
could say I have a persistence issue, because I should be able to persist my table’s
Collection….instead, however, I would like to find out if there is a way
to also pass the currently selected row when the dropdown menu’s value is
changed. With that, I could use my EntitManager’s find method
to get a managed object of the particular row and persist the new value. Unfortunately,
f:param and f:attribute are null when my valueChangeListener is fired. I’ve tried pushing the execution of updateTaskStatus off
to the UPDATE_MODEL_VALUES phase, but they are still null at that point. I
tried both f:param and f:attribute because I am grasping at straws at this
point. (I was following related advice at [1]). I can pass the row
ID in my other datatables, but in this case I am using an a4j:region…so I’m
guessing it is skipping a number of phases in the JSF lifecycle. Does
anyone have a suggestion on how to accomplish this? Is there an elegant
way to do this? <a4j:region selfRendered="true"> …
datable definition and some columns … <h:column>
<f:facet name="header">
<h:panelGroup id="panelxyz">
<h:outputText value="#{msg.status}" />
</h:panelGroup>
</f:facet>
<h:selectOneMenu value="#{item.status}" title="Status"
valueChangeListener="#{task.updateTaskStatus}">
<f:selectItems
value="#{taskStatus.taskStatusSelectItems}"/>
<f:param name="updatedTaskId" value="#{item.taskId}"/>
<f:attribute name="updatedTaskId2" value="#{item.taskId}"/>
<a4j:support event="onchange"
you sure you want to change the status?'))
{form.reset(); return false;}"
status succesfully stored.')"
reRender="panelxyz" />
</h:selectOneMenu>
</h:column> …
some more columns … </a4j:region> [1] http://java-server-faces.blogspot.com/2006/04/valuechangelisteners-what-you-need-to.html Tim |

