Hi all!
Help deal with the task.
I deduce the table from a database on page:
<h:dataTable value="#{garageController.manufacturers}" var="manufacturer" styleClass = "garageTable" headerClass = "tableHeader" rowClasses = "tableOddRow, tableEvenRow"> <h:column> <f:facet class = "header" name = "header"> <h:outputText value = "Manufacturer Code"/> </f:facet> <h:outputText value = "#{manufacturer.manu_code}"/> </h:column> <h:column> <f:facet class = "header" name = "header"> <h:outputText value = "Manufacturer Name"/> </f:facet> <h:outputText value = "#{manufacturer.manu_name}"/> </h:column> <h:column> <f:facet class = "header" name = "header"> <h:outputText value = "Manufacturer Details"/> </f:facet> <h:outputText value = "#{manufacturer.manu_details}"/> </h:column> In GarageController I keep a list:
private ArrayList<Garage> manufacturers; /* Getting ArrayList */ public ArrayList<Garage> getManufacturers() { return manufacturers; } The task is to save the selected row of the table as an object in the UpdateManufcturerController controller, and on another page set the values of the variables of this object as default on the input lines.
In the last column of the table inserted a "button":
<h:column> <f:facet class = "header" name = "header"> <h:outputText value = "Action"/> </f:facet> <h:commandLink value = "update" action = "#{UpdateManufcturerController.sendToUpdate}"> <f:setPropertyActionListener target="#{UpdateManufcturerController.manu_code}" value="#{manufacturer.manu_code}" /> </h:commandLink> </h:column> In the controller, I create an object to store the selected row and transfer it to another page by pressing a button:
package ie.gmit.sw; import javax.faces.bean.ManagedBean; import javax.faces.bean.ViewScoped; @ManagedBean @ViewScoped public class UpdateManufcturerController { // local objects private DAO dao; private Garage manufacturer; public Garage getManufacturer() { return manufacturer; } public void setManufacturer(Garage manufacturer) { this.manufacturer = manufacturer; } /* Constructor that creates instance of DAO to communicate with database and manipulate data */ public UpdateManufcturerController() { try { dao = new DAO(); } catch (Exception e) { e.printStackTrace(); } } public String sendToUpdate(){ return "update-manufacturer"; } } By pressing the button, it throws out such an error:
HTTP Status 500 - /manage-manufacturers.xhtml @54,123 target="#{UpdateManufcturerController.manu_code}": Target Unreachable, identifier 'UpdateManufcturerController' resolved to null PS We pass as a semester module for the course, there is no experience in JSF ... Maybe there are better ways to cope with this task ??
Grateful for the help and criticism!