How to set up the Field plugin not to display scientific notation from a Double variable in the Edit view? - grails

I have a Book domain with a Double variable Double commissionRate.
(e.g.) myBook.commissionRate = 0.0001
I am using the default Scaffolding. I didn't customize any of the views.
The show.gsp displays the Double as-is which is what I want.
(i.e.) 0.0001
However, the edit.gsp will show 1.0E-4 in the input box.
The code in the edit.gsp is just <f:all bean="book"/>
I look at the HTML split out from the view. The value in the HTML is also 1.0E-4. So, I think the Field plugin is converting 0.0001 to 1.0E-4.
Would you show me how to set up my book domain so the Field plugin (assuming the Field plugin is checking the data type and the constraint, and then make the conversion) will just show the value without the scientific notation in the edit.gsp please?

Related

How to supply hardcoded multiline content in h:inputTextarea

In HTML I can do:
<textarea>
line 1
line 2
line 3
</textarea>
However, the same thing doesn't work with the JSF <h:inputTextarea>, as I have to specify the value attribute instead of the body. Is there a way that I can specify a multiline value? Ideally I would like to be able to do it as seamlessly as in HTML, ie with no \n and actually putting it onto multiple lines, for easy readability.
You could try this :
<h:outputFormat escape="false" value="Line 1<br/>Line 2" />
Which would render:
Line 1
Line 2
Note:The escape="false" means you can embed html, like lists etc...
or else we can even try like this:
Alternatively you could set readonly to true on the inputTextArea and set the rows attribute.
I Hope this will help you
Well, I couldn't find a way to include the textarea content directly into the .xhtml, while keeping the content on several lines. There's probably a way with some javascript by using a different tag and then copying it in or something, but I wanted to keep it fairly clean.
What I ended up doing was using the value attribute of h:inputTextarea and I populated it from my managedBean. I created text files of the content I wanted (they were quite big files) and loaded them into the managedBean property using a FileReader. When you assign them to the value of the h:inputTextArea, the \n etc are respected, so that it gives you the identical effect to if you had hardcoded the text into the .xhtml between textarea tags.

render html in a rich text box in active reports software

I have a string with basic html markup which I want to put into a rich textbox
string ab = #"<b> a b </b>"
I want it to render as it would appear in a browser ie:
a b
how can I do this in active reports 7? According to http://www.datadynamics.com/forums/77664/ShowPost.aspx, a richtextbox supports these tags. Do I have to specify a property to allow it to render html? How should I approach this?
Thanks,
Sam
More information (Update 8/11):
I'm binding the data from a database field - an oracle nclob. The field repeats within the detail section (with different information each time).
If I bind the field directly to a textbox or label it renders the string, but doesnt encode the html
<b> a b </b>
but it encode the string.
Solution Summary
Solution (as suggested by #activescott)
Bind rtx directly to the datafield
'Reformat' the text into html in
the script
public void detail_Format()
{
rtxBox.Html = rtxBox.Text;
}
result: renders the html field with some degree of html formatting
notes:
binding directly in the script doesnt work,
ie. rtxBox.Html = pt.Fields["CONT_ID"].ToString(); yields some wierd meta data string
the Datafield only binding approach doesn't work
(it will yield it as text)
there are some extra spacing that occurs with p tags. It may be worth regexing them out or somehow providing some formatting control.
The actual property you are looking for is the Html Property. You can also load a file into that control using the step-by-step walkthrough here.
I am assuming you are using Section Reports and not Page Reports.
To use HTML from the database in a bound report, you should be able to use the DataField property of the RichTextBox control (set it to the name of the corresponding Data field at design time). However, I noticed this "Render HTML tags in DB in ActiveReport pdf or HTML" article which kind of implies that doesn't work since it loads the HTML from a database programatically. One of the two should work.

Safely rendering a user's template/view?

I have a model which has a template field. This template is HTML and has variables which get substituted. This template is then converted into a PDF using wicked_pdf.
How should I take the template which the user enters and safely do variable substitution? Allowing it to be an ERB template seems to be setting myself up for some huge security holes. What safe solutions are there?
Edit:
So, for example, I have my template class/model which has two fields, a name and an HTML field. This is a user editable class. There will be specific variables available to the HTML in the template class (Company Name, price, etc.). I am hoping to use a HTML templating system, but since this is user created content, it isn't trusted. Only variable substitution will be done, nothing more.
Rails provides a couple of helper functions, namely hto escape values on display for preventing such behavior.
<%= h #user.name %>
h is an alias of html_escape

Providing Required Format Information in Text Box in MVC view

How do you set a string to denote the required format pattern in a text box. For instance, if I have a text box displayed such as a date field, how do I display a format of "dd/mm/yyyy" to help the User complete the field. If the field is already populated when the view is displayed then the actual data should be displayed.
If the field is a drop down list, I would like to display "Please select from the list" if the field does not contain a value.
In HTML 5 you can achieve it using Placeholder attribute of input tag like this:
<input name="email" type="email" placeholder="validemail#email.com" />
However HTML5 is not yet supported by most browsers, so you will have to live with javascript based solution. Populate the desired value in textbox when page is loading (you can use CSS to make that text dim). Using javascript empty the field on "onfocus" event.
For drop down list populate "please select..." thing with Value as 0. This way you can validate on server that user has not selected any valid value.

Raw HTML in Form Filter

At my company, we had developed a athletes management solution, were each athlete is inserted in the application by administrators users. For the referred solution, it was used the symfony admin generator.
On the second project iteration, one of the clients request was to turn the printed athletes list more legible. To accomplish that, we had created proper CSS styles, to be used when the user selects the browser print option.
However, the athletes form filter has some HTML tags (symfony widgets) whose do not render properly, namely, the select tag that has possible multiple choices (the select choices do not appear on the print preview).
So, I would to know if is possible to insert raw HTML directly on the form filter (get the selected options and convert them is labels or plain text), that will be only visible when the user selects the print option.
You could put a custom widget in place of the standard choice widget that adds in the values you want to be shown when printing but hidden with styles by default. Then you show them using your print style sheet.

Resources