I use thymeleaf 3 with spring boot 2
have a integer and a string to do a compare
i tried
${car.id}==${generic.value}"
but it's always false
This should help you: ${#strings.equals(generic.value, #strings.toString(car.id))}
Related
I have a domain class with a float field:
class DvQuantity {
float magnitude
String units
}
When I have this:
new DvQuantity( magnitude: '11.0', units: 'm' ).save()
In the database I see: magnitude = 110.0 instead of 11.0
Is this a Grails bug? Is there any workaround?
It is not a bug. As stated in the comment, parsing of numbers depends on your locale. See example below:
import java.text.NumberFormat
String a = '11,0'
assert NumberFormat.getInstance(Locale.US).parse(a).floatValue() == 110
assert NumberFormat.getInstance(Locale.FRANCE).parse(a).floatValue() == 11.0
There are many different ways to change your default number format - for example PropertyEditorRegistrar or ValueConverter. You can also enforce format on the view using validators.
Here Grails databinding with decimal delimiter is answer with example code how to do that for Grails <2.3 and >=2.4
question from a groovy newbie:
sql is initiated as follows
final Binding binding = new Binding();
binding.setProperty("sql", sql);
final groovy.sql.Sql sql = Sql.newInstance(dbConfig.getUrl(), dbConfig.getUserName(), dbConfig.getPasswd(),"oracle.jdbc.OracleDriver");
I am running a query in groovy like this
def listOfRows = sql.rows (select column1 from table1);
listOfRows when printed shows contents like [[column1_name:value1], [column1_name:value2], [column1_name:value3]]
I want to check if value2 (a String) exists in the returned list of values from the above query.
I have tried doing listOfRows.contains('value2') and listOfRows.find('value2'),
it complains that the method does not exist for lists..
what's the best way of doing this ?
EDITED: I have corrected the list of printed values. What's being returned is List<GroovyResultSet>
and I have also added the definition of sql.
I would suggest you to take a look at groovy documentation, and particularly to collections documentation (both tutorial and JDK/GDK).
in that case, the most specifically adapted solution would be to use Collection#find() ... with something like
listOfRows.find { it.contains(':value2') }
Which can be translated into human-readable
find the first element in this collection which string contains ":value2".
You probably want
listOfRows.column1.contains( 'value2' )
You are probably invoking this method which takes a GString (note that GString != String) as an argument. According to this question, a string in single quotes is a standard java string, and a string in double quotes is a templatable string.
'hello' //java.lang.String
"hello" //groovy.lang.GString
Try this:
listOfRows.contains("value2")
what i ended up doing is following :
iterate the listOfRows, get all the values for column1 from each GroovyResultSet into a listOfValues ,then check for my values in that list.
def listOfValues=[];
listOfRows.collect(listOfValues){it.getAt('column1')};
if(listOfValues.size()==3){
println('success');
}
I am getting error on
I.ID=((Element) nl.item(i)).getAttributes().getNamedItem("ID").getNodeValue();
the error is that
getNamedItem required INT and found String
When i give an Int value then the error said that it required String and found Int.
Issue Resolved.
getNamedItem is returning String value while ID is an integer value. so i put string to integer parser which resolved my issue.
I have the following combobox:
<g:select name="ticketType" from="${app.domain.enums.TicketType?.values()}"
keys="${app.domain.enums.TicketType.values() }"
value="${ticketInstance?.ticketType}"
noSelection="${['null': 'Select One...']}"
/>
I've setup the following constraint for ticketType in command object
ticketType nullable: true, blank:true
TicketType is a very simple enum:
public enum TicketType {
QUESTION, SUPPORT, MAINTENANCE, NEW_FUNCTIONALITY, MALFUNCTION
}
And every time I don't setup some value for ticketType in my GSP I get the following error:
Failed to convert property value of type 'java.lang.String' to required type 'com.coming.enums.TicketPriority'
It's like in case of no selection g:select sets the value for "null" (string).
What am I missing?
Rather than using the 'null' literal, have you tried using an empty string as your noSelection attribute? e.g. noSelection="${['':'Select One...']}"? This may do a proper conversion to a true null value during data binding.
As your error says - you do have a string in your noSelection. This can't be converted to any of your enum values.
Remove the quotation marks of your null and it should work (it works for me with grails 2.0):
<g:select name="ticketType" from="${app.domain.enums.TicketType?.values()}"
keys="${app.domain.enums.TicketType.values() }"
value="${ticketInstance?.ticketType}"
noSelection="${[null: 'Select One...']}"/>
Under Rails 3.3.x, no variation of providing the "null" value worked. In the end, I resolved it by adding this line in to the controller+action before doing any use of the params:
// convert "null" strings to REAL nulls
params.account.each { it.value = (it.value == 'null' ? null : it.value) }
After that, the following worked fine:
account.properties = params.account
I'm working on a biztalk project and use a map to create the new message.
Now i want to map a datefield to a string.
I thought i can do it on this way with an Function Script with inline C#
public string convertDateTime(DateTime param)
{
return System.Xml.XmlConvert.ToString(param,ÿyyyMMdd");
}
But this doesn't work and i receive an error. How can i do the convert in the map?
It's a Biztalk 2006 project.
Without the details of the error you are seeing it is hard to be sure but I'm quite sure that your map is failing because all the parameters within the BizTalk XSLT engine are passed as strings1.
When I try to run something like the function you provided as inline C# I get the following error:
Object of type 'System.String' cannot be converted to type 'System.DateTime'
Replace your inline C# with something like the following:
public string ConvertDateTime(string param1)
{
DateTime inputDate = DateTime.Parse(param1);
return inputDate.ToString("yyyyMMdd");
}
Note that the parameter type is now string, and you can then convert that to a DateTime and perform your string format.
As other answers have suggested, it may be better to put this helper method into an external class - that way you can get your code under test to deal with edge cases, and you also get some reuse.
1 The fact that all parameters in the BizTalk XSLT are strings can be the source of a lot of gotchas - one other common one is with math calculations. If you return numeric values from your scripting functoids BizTalk will helpfully convert them to strings to map them to the outbound schema but will not so helpfully perform some very random rounding on the resulting values. Converting the return values to strings yourself within the C# will remove this risk and give you the expected results.
If you're using the mapper, you just need a Scripting Functiod (yes, using inline C#) and you should be able to do:
public string convertDateTime(DateTime param)
{
return(param.ToString("YYYYMMdd");
}
As far as I know, you don't need to call the System.Xml namespace in anyway.
I'd suggest
public static string DateToString(DateTime dateValue)
{
return String.Format("{0:yyyyMMdd}", dateValue);
}
You could also create a external Lib which would provide more flexibility and reusability:
public static string DateToString(DateTime dateValue, string formatPicture)
{
string format = formatPicture;
if (IsNullOrEmptyString(formatPicture)
{
format = "{0:yyyyMMdd}";
}
return String.Format(format, dateValue);
}
public static string DateToString(DateTime dateValue)
{
return DateToString(dateValue, null);
}
I tend to move every function I use twice inside an inline script into an external lib. Iit will give you well tested code for all edge cases your data may provide because it's eays to create tests for these external lib functions whereas it's hard to do good testing on inline scripts in maps.
This blog will solve your problem.
http://biztalkorchestration.blogspot.in/2014/07/convert-datetime-format-to-string-in.html?view=sidebar
Regards,
AboorvaRaja
Bangalore
+918123339872
Given that maps in BizTalk are implemented as XSL stylesheets, when passing data into a msxsl scripting function, note that the data will be one of types in the Equivalent .NET Framework Class (Types) from this table here. You'll note that System.DateTime isn't on the list.
For parsing of xs:dateTimes, I've generally obtained the /text() node and then parse the parameter from System.String:
<CreateDate>
<xsl:value-of select="userCSharp:GetDateyyyyMMdd(string(s0:StatusIdChangeDate/text()))" />
</CreateDate>
And then the C# script
<msxsl:script language="C#" implements-prefix="userCSharp">
<![CDATA[
public System.String GetDateyyyyMMdd(System.String p_DateTime)
{
return System.DateTime.Parse(p_DateTime).ToString("yyyyMMdd");
}
]]>