TechnologyRediscovery / codenforce

municipal code enforcement database application
GNU General Public License v3.0
2 stars 3 forks source link

Add control over default values when inserting batch enforcable code elements #230

Open edarsow opened 2 years ago

edarsow commented 2 years ago

Hints for building a default values form

  1. Create a member variable of type EnforcableCodeElement on CodeSetBB to hold your temporary object holding default values. Name it something logical.
  2. Inside initbean() the method that's automatically called by JSF before a page loads, and inject a new instance of the ECE into this member variable. Where is this object going to come from? The CoodeCoordinator will need a new method called something like EnforcableCodeElement getDefaultEnforcableCodeElement() in which the magic new is called. When you write this method you'll want to have something like new EnforcableCodeElement() -- but NOTE that this ECE is special since its underlying CodeElement object is empty. We are just using this is a container for the enforceability values during ECE creation.
  3. So now, you're CodeSetBB has a member on it which when given a getter and a setter method, the faces page codeSetManage.xhtml can access. If that backing bean member variable is called defaultECEValueContainer, then in the faces page we could use as the value= for say a <p:inputText ...> component something like #{codeSetBB.defaultECEValueContainer.minPenalty} and if the input text box is in the same form as the table of selected elements, then when the button is clicked, all of the member variable values on the defaultECEValueContainer will automatically reflect what the user typed in the form in their browser. Poof--all done by the JSF engine.
  4. Edit the CodeCoordinator method public int insertEnforcableCodeElement(EnforcableCodeElement ece, CodeSet cs, UserAuthorized ua) to accept a fourth parameter, your special EnforcableCodeElement that only has the wrapper members set. The job of the coordinator method will now be to call the setXXX() methods and inject the values from the chosen default values, so if your new param is called defece you'll have a line like ece.setMaxPenalty(defece.getMaxPenalty()). Do that for each member variable and ship it off to the Integrator!