javascript - Grails controller - link to select element from .gsp file -


So, I'm working on this grails application to create a web dashboard. So far, I have created a controller who asks the matrix from my database and presents it as a JSON file, which I feed on D3 and other JavaScript libraries on front-end GSP file.

My question is: At the end of my face I have a certain drop down menu:

    Source def listJson = {def sql = new Sql (dataSource) def rows = sql.rows ("select date_hour, total_value as sale, visit from table") sql.close () JSON} render rows   

The problem is now, I have a bunch of drop down menus, and each has a lot of options, for each of which, if I If I have done so, then I have to make a new Jason file for D3. Instead, can I in no way contain the value of the option from the element given above in the SQL statement in the controller?

Below is something similar, but I do not know if this is possible, and if it is, then the correct syntax. I'm using grails 2.3.4.

  def listJson = {def sql = new SQL (datasource) def rows = sql.rows ("date_hour, sale as a total sale, from $ {index # metric} table") sql Provide rows in the form of .close () JSON}   

where the index is my index.gsp file (where is the option to select), and #metric, element id

Thanks in advance!

You can get the value from from your controller select For example:

  def listJson = {def metric = params.metric // built query ... def query = "... $ {metric} ..."}   

However, I want to advise against the creation of a SQL query like this at any time when you accept User Input as part of SQL Query, then it is a B for SQL injection attacks. The Ha opportunity. Why not use a high-level database intangible like GORM? Also keep in mind that Groovy SQL uses different parameter expansions in question than regular strings generated for preparations. You have to type your example in this way: sql.rows ("Select date of date, total sales in sales form," + "metric + from table")

Lastly, while depending on how you are submitting the request in loadData () , value for the HTML input elements with the usual convention element name attribute Presentation is ID .

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -