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!

    1 answer 1

    Not only are you doing something wrong (since it does not work), you are also guided by some kind of antediluvian guides. Now you can make it easier.

    Starting at least with JSF 2.0, methods with parameters can be actionable.

    On the page

     <h:commandLink value = "update" action = "#{updateManufcturerController.sendToUpdate(manufacturer.manu_code)}"/> 

    Controller method

     @ManagedBean @ViewScoped public class UpdateManufcturerController { ... public String sendToUpdate(Object manu_code) { // не знаю какого типа manu_code // только поэтому пишу Object Garage manu = dao.findByCode(manu_code); // Предполагаю, что должно // быть что-то для поиска // Garage по коду setManufacturer(manu); return "update-manufacturer"; } ... } 

    You can also send immediately Garage
    Page

     <h:commandLink value = "update" action = "#{updateManufcturerController.sendToUpdate(manufacturer)}"/> 

    Controller

     @ManagedBean @ViewScoped public class UpdateManufcturerController { ... public String sendToUpdate(Garage manu) { setManufacturer(manu); return "update-manufacturer"; } ... } 

    With regard to the specific issue, the identifier 'UpdateManufcturerController' resolved to null as it hints: "There is no such name UpdateManufcturerController " What is not surprising, because by default the name starts with a small letter updateManufcturerController .

    • Thanks Sergey! Where can I read a good guide or guide? Sorry, until I get a rating of +15, I can not raise the answer to +1 .. - GarRudo
    • I do not even know what to advise. Scraps from Google, specification, stack overflow aglitsky, answers of the BalusC dude. He has his own website. pdf somehow downloaded Ed Burns, Chris Schalk - JavaServer Faces 2.0, The Complete Reference - McGraw-Hill, 2010 but never read. Now the current version of JSF 2.2, which added some very useful features. - Sergey
    • Sergey, what do you think is good for JSF? Why is it used in writing web applications? What is the trend now and worth studying? - GarRudo
    • The most popular competitor to JSF and the entire JavaEE stack, as I see it, is the Spring framework. Spring uses JSP. JSP seems to be out of the box, but you can also tie other rendering libraries of representations of different degrees of attribution to it (there are quite interesting developments). Then there is the front-end completely based on the client side. If I owned javascript, I would have gone this way. But there is such an abundance of options that I can’t say anything as illiterate. I am more impressed by react.js. At the same time, the server is only RESTful - Sergey
    • Your answer is clear. Thank! Have a good evening. :) - GarRudo