Edit Action in ContextMenu of DataTable
bemar May 6, 2011 5:19 AMHello together,
I have a DataTable with some lines of Incidents. Now I want to implement a context menu in which the user can edit or view the details of the selected line.
How can I do this? The problem is I outject the details object by a action method in an application bound IncidentHandler
which has the id of the incident as parameter, loads the incident and outjects it to get viewed or edited in the related page.
So my question is, how can I call the method of the handler with the right id parameter?
Currently I'm using a s:button. Are there other ways to do this?
Heres my code. The incidentId
parameter is in every case 0 (zero).
Any help would be apreciated.
Thx in advance
Ben
Handler: @Name("incidentHandler") @Scope(ScopeType.CONVERSATION) public class IncidentHandler { @In protected EntityManager entityManager; @In protected FacesMessages facesMessages; @Out private Incident incident; @In(create = true) Failmessage failmessage; @Begin(join = true, flushMode = FlushModeType.MANUAL) // @Begin(join = true, flushMode = FlushModeType.MANUAL) @Restrict("#{identity.loggedIn}") // avoids having to add login redirect logic in flow (see chapter 11) public String editIncident(Long incidentId) { Incident inc = entityManager.find(Incident.class, incidentId); if (inc != null) { this.incident = inc; return "loaded"; } else { this.incident = new Incident(); facesMessages.add("The incident with id ["+incidentId+"] was not found."); return "failed"; } } ..... }
My List Page
<h:form id="incidentTable" styleClass="edit"> <rich:contextMenu attached="false" id="menu" submitMode="ajax"> <rich:menuItem ajaxSingle="true" event="oncontextmenu"> <s:button action="#{incidentHandler.editIncident(incidentId)}" id="incidentEdit" value="#{messages.text_incidentedit}" /> </rich:menuItem> <rich:menuItem ajaxSingle="true"> <s:button action="#{incidentHandler.viewIncident(incidentId)}" id="incidentView" value="#{messages.text_incidentview}" /> </rich:menuItem> </rich:contextMenu> <rich:panel> <f:facet name="header">#{messages.text_foundincidents} (#{empty incidentList.resultList ? 0 : (incidentList.paginated ? incidentList.resultCount : incidentList.resultList.size)})</f:facet> <div class="results" id="incidentList"><h:outputText value="#{messages.text_nothingfound}" rendered="#{empty incidentList.resultList}" /> <rich:dataTable onRowMouseOver="this.style.backgroundColor='#F1F1F1'" onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" id="incidentList" var="_incident" value="#{incidentList.resultList}" rendered="#{not empty incidentList.resultList}"> <rich:dataTable> ... here are the headers and columns of the table ... <rich:componentControl event="onRowClick" for="menu" operation="show"> <f:param value="#{_incident.idIncident}" name="incidentId" /> </rich:componentControl> </rich:dataTable> </rich:panel> </h:form>
Here is the list.page file
<param name="incidentId" /> <navigation from-action="#{incidentHandler.viewIncident(incidentId)}"> <rule if-outcome="loaded"> <redirect view-id="/Incident.xhtml" /> </rule> <rule if-outcome="failed"> <redirect view-id="/fail.xhtml" /> </rule> </navigation> <navigation from-action="#{incidentHandler.editIncident(incidentId)}"> <rule if-outcome="loaded"> <redirect view-id="/IncidentEdit.xhtml" /> </rule> <rule if-outcome="failed"> <redirect view-id="/fail.xhtml" /> </rule> </navigation>