Removing commas from Grails' Scaffolds for Longs - grails

I'm completely new to grails and I'm trying to deploy some simple applications using grails' scaffolding. I have a field in a domain class that stores barcodes as Longs. The default display in Grails' scaffolding is to display these Longs with commas separating every third numeral (e.g. 1,234,567). My searching of the documentation is getting me nowhere, is there a way of easily turning off this formatting until I can get a proper layout set up.
Thanks.

After generation of the scaffolded controllers and gsp files you could use the gsp tag g:formatNumber (see http://www.grails.org/GSP+Tag+-+formatNumber?xhr=true).
Maybe you can also customise the templates used for generation see docs for "grails install-templates" (http://www.grails.org/Artifact+and+Scaffolding+Templates) and get it working for dynamic scaffolding also... ymmv.
('tis my first post, be gentle)

Related

Grails 5 how can I install the fields-templates

Grails 5 is using the fields-plugin (as stated in the scaffolding plugin and I see it in the Intellij-IDEA Grails-View of my project under plugins).
But how can I install the fields-plugin templates?
Even in the GitHub-sources I could only find the templates for _embedded, _list and _table.
what am I missing?
(The reason for all that is, that I want to know, how the inList constraint is handled in a g:select. I know it's working, but if I try it the "old-fashioned" way with
from=${MyDomain.constraints.myField.inList}
grails throws errors Cannot get property 'myField' on null object
Please correct me if I'm wrong, but the delivered plugin has no other template files as the mentioned ones, the base "template" is done through the taglib and you can override with "self-made" tag-gsps in views.
But I would like to see some documentation, which variables you could use in own template-files... or did I miss it?
The constraints attribute has changed to constrainedProperties.

30Bees/Presta 1.6 shop translation in frontController

I am trying to add a few translations to the frontend of our module. When the translations are in the .tpl files they do get rendered. However no translation fields get shown in the backend my code for the .tpl files is:
{l s="Text" mod="myModule"}
I also do need to do some translating in the FrontControllers (mainly Error handling and feedback for serverside validation).
In the AdminController I simply use $this->l('Text'); which works. However, in the FrontController this is not available. I've checked the ControllerCore and FrontControllerCore, l() is not defined in those and only available in AdminController.
Can anyone give me a detailed explanation of what I need doing? All my research on the web always points to $this->l() being the thing to use...
When using translations in tpl files you need to use single quotes not double quotes.
{l s='Text' mod='myModule'}
As for front controllers... well if you're using custom module controllers as in controllers that extend ModuleFrontController you can use
$this->module->l('Text');
And if you're not using those controllers then... start using them.
Some things might be different since thirtybees is a fork of PrestaShop but I guess translation mechanism is the same.

Easiest way to render an Integer without thousands separator when using Fields plugin 2.0.2

I'm building a very basic app using Grails 3.0.2.
I have a domain class called Unit which contains, among others, a field called season, whose type is Integer and represents a year.
I have used the command generate-views to generate the scaffolded views.
Once running the application, when an existing instance is shown, the season is displayed using "," as thousands separator, and I want to remove it.
What is the easiest way to override (only) the format of the season?
For testing purposes, I have modified the show.gsp of the Unit class in the following manner:
<f:with bean="unit">
<f:display />
<f:display property="season" />
</f:with>
The <f:display property="season" /> displays simply "1,975", but ignores the label.
I've tried to understand the documentation of the Fields plugin, but I do not achieve what I want so it's obvious that I do not understand it.
I have added _displayWidget.gsp under views/_fields/unit/season (I have also tried under views/unit/season), but the outcome is exactly the same than before, so I assume the plugin is not taking them into account.
<g:formatNumber groupingUsed="false" number="${value}" />
I am not familiar with the _displayWidget.gsp convention, but a simpler approach might be to override the display of the unit.season property by adding a _display.gsp under views/_fields/unit/season containing just the following:
${value}
Diego, you can format any given number using the taglib formatNumber:
https://grails.github.io/grails-doc/latest/ref/Tags/formatNumber.html
Use the param 'format' and check the DecimalFormat patterns to find the one that suits fine for you.
Hope it helps!
I was able to get this working in Grails 3.1.14 by creating views/_fields/myDomainClass/myFieldName/_displayWrapper.gsp and containing a single line of ${value}

Two Step View Pattern

Martin Fowler's PoEAA catalog is like a repository for Ruby gems and Rails modules, for example the ActiveRecord ORM from Rails is based on Fowler's ActiveRecord, and the DataMaper gem is based on the Data Mapper pattern. Are there any useful implementations of Martin Fowler's two-step view pattern in Ruby, e.g. in combination with a template engine?
The pattern turns domain data into HTML in two steps. It is particularly interesting if you want to compose your views into decoupled, reusable view components.
One possible solution to implement the two step view seems to be an XSLT transformation, for example with XML and Nokogiri. This means to create an intermediate xml representation of the page:
XML == (XSLT) ==> XML
XML == (XSLT) ==> HTML
A second possible solution is to use a JS template engine like vue.js, KnockoutJS, Ractive.js or React. Rails does the first step and creates an intermediate view, the JS template engine the second:
Rails Template == (Rails) == > View-Template
View-Template + JSON-Data == (vue.js/KnockoutJS/Ractive.js/React) ==> HTML
This is a new pattern to me, but I can two ways to conceptualize it. The core of the pattern seems to be building an intermediate representation first, then run it through a formatting step. In each case, the outcome is a view that looks identical regardless of which class of ActiveRecord model is being displayed.
Option 1: Intermediate Ruby Object
Using a Presenter library (Draper, ActiveDecorator, roll-your-own), you can normalize multiple ActiveRecord classes to a single public API. Then you write a single view template that can render objects with that API.
In this case you create a single view template plus one Presenter object for each ActiveRecord class you need to render. If you need to add new data to the page, you have to touch the template and all of the Presenter classes.
Option 2: HTML + CSS
It's odd, but I think HTML is a valid format to represent data, and could be considered as an intermediate, unformatted representation.
In this case you create a view template (probably a partial, possibly polymorphic) for each ActiveRecord class that produces (nearly) identical HTML. Then you use a CSS component framework to "format" the HTML into identical renderings. The HTML doesn't need to be strictly identical, as long as it all conforms to what your component framework is expecting. Adding data here means changing each view template (the CSS usually won't need modification).
I think both of these approaches are valid. The second feels more "rails-y" to me, but I think it's a departure from the spirit of the pattern, even if it technically conforms (which might be debatable).

Grails internationalization for the views

In Grails views, I need to change the language for labels, buttons, etc., depending on the language that the user picked. How can that be achieved?
i found a soultion to my problem .
A great thing of the scaffolding is that internationalizing the elements on the screen is a breeze! Default translations for Home and Create have already been provided for a dozen or so languages in the i18n folder. The name of the entity itself (“Product”) and its properties can be defined by following a convention: [entity name].label and [entity name].[property name].label – see your Grails installation /src/grails/templates/scaffolding folder.
Take a look at how we would translate a few things into Dutch, by adding a few keys to messages_nl.properties:
product.label=Product
product.name.label=Naam
product.status.label=Status
here is the link (http://tedvinke.wordpress.com/2012/08/22/grails-scaffolding-enums-and-i18n/)

Resources