JSS files are BeanShell scripts and normal Beanshell commands apply. In addition, there are a number of JSS-specific commands that can be used for your convenience.
Redirects the browser to the given action, for the same controller. Use this to redirect after a committing a transaction.
redirect_to(String controller, String action)
Redirects the browser to another controller and action. Use this to redirect after a committing a transaction.
render_view(String layout, String view, Object data)
Forward the request to the view, given the layout and the data. Use this if you still want the request to be used by the receiving view.
render_view(String view, Object data)
Forward the request to the view, with the given data. Use this if you still want the request to be used by the receiving view.
Forward the request to the view. Use this if you still want the request to be used by the receiving view.
Get the parameter of the given name from the request object
Remove the persistence of this object from the database
Update the persistence of the object
update(Object object, Map params)
Populate the object with the given parameter map and update the persistence in the database. If the object doesn’t exist, create it
find(Class clazz, Serializable id)
Finds and returns a single object of Class clazz given the id
Creates and returns a Hibernate Query object
Creates and returns a Hibernate SQLQuery object
sql(String sql, Class clazz)
Executes the SQL query provided for the provided class, and returns a list of objects
Retrieves the id from the request parameters
With these changes in the JSS commands, a simple controller file (from the tutorial) becomes something like this:
Notice that this file has become much simpler than before. Noticeably, I dropped the usage of the ‘jss’ default object, as well as created a command id() that extracts the id from the request parameters automatically. This controller is much more readable than the previous one. One comment I had from someone is that such code becomes ‘un-Java like’ and it becomes another chore to understand another programming language, which is counter to JSS’s simplicity principle. Not really. The code is still Java, and if you choose to do so, you can still program the whole thing in 100% Java — but you have ‘helper’ commands that simplify the command tasks and makes the code much more readable and maintenable.
Note that JSS’s simplicity principle is largely meant for the maintenance of the software, and not for building it. Anyone can write complex code. The rationale for writing simple code is not to build faster applications — piling enough competent programmers in a project can usually do the job (to a certain extent). However complex code is hugely difficult to maintain and that is usually the trick in large-scale software development. It’s not in the building but in the maintaining. There’s a saying in Chinese — ‘Building an empire is easy but maintaining it is difficult.’ Heed the saying.