How to convert String to Double value in jasper Reports?
I am having two fields in .jrxml file like below
<field name="secRate" class="java.lang.String"/>
<field name="secPrice" class="java.lang.String"/>
i need to subtract both the field
$V{Variable} = $F{secRate} - SF{secPrice}
i tried this way but not working
(new Double(Double.parseDouble($F{mktVal})))
any idea? please help me guys..
If the mktVal field is a String, you can try using Double.valueOf(${mktVal}).
Set Text Field Expression: Double.parseDouble($F{PARAM})
Set Expression Class: java.lang.Double
Add rt.jar (from java runtime) to classpath [Tools >> Options >> Classpath]
And Compile
Try
Double.valueOf(${mktVal}).
Pls try this one - ($F{PARAM}.trim().isEmpty()) ? 0.0 : new Double($F{PARAM})
Related
I have a jrxml file which has a field of BigDecimal value and when I try to execute the report. I get an error called " Cannot cast from BigDecimal to String in jasper". Im doing the report using ireport 5.6.0, and I get a weird error like this,
1. Cannot cast from BigDecimal to String
value = (java.lang.String)(((java.math.BigDecimal)variable_variable1.getValue())); //$JR_EXPR_ID=18$
<----------------------------------------------------------------------->
2. Cannot cast from BigDecimal to String
value = (java.lang.String)(((java.math.BigDecimal)variable_variable1.getOldValue())); //$JR_EXPR_ID=18$
<-------------------------------------------------------------------------->
3. Cannot cast from BigDecimal to String
value = (java.lang.String)(((java.math.BigDecimal)variable_variable1.getEstimatedValue())); //$JR_EXPR_ID=18$
<-------------------------------------------------------------------------------->
3 errors
I tried to change the expression class. but nothing seems to work. I need the value to get the sum and also as a field.
You have a field e.g $F{ID} with field class=java.math.BigDecimal.As you want to use this field as a string as well as decimal;
You can create two variables variable1 with variable Class=java.math.BigDecimal with Variable Expression as $F{ID}
and create another variable variable2 with variable Class=java.lang.String with Variable Expression as $F{ID}.toPlainString()
When I removed tag "printWhenExpression" for that text field with error, the error did not show again.
How can i parse xml result to tableview with two lines per cell in Swift?
I want to show the result like this in a table view
TableView
================
userID: brat_peet
password: 12124521
================
userID: Miketyson
password: Miketyson
================
How can i do it?
Here is my xml result.
<Record table="User" partial="true">
<Field name="userID" primaryKey="true"><![CDATA[brat_peet]]></Field>
<Field name="password" primaryKey="true"><![CDATA[12124521]]></Field>
</Record>
<Record table="User" partial="true">
<Field name="userID" primaryKey="true"><![CDATA[Miketyson]]></Field>
<Field name="password" primaryKey="true"><![CDATA[Miketyson]]></Field>
</Record>
<Record table="User" partial="true">
<Field name="userID" primaryKey="true"><![CDATA[Kennedy]]></Field>
<Field name="password" primaryKey="true"><![CDATA[754123654]]></Field>
</Record>
</ATBResponse>
For the tableView:
"Two lines per cell" is an irrelevant value. You can use "custom" style cells and put in as many Text Labels (and images and whatever) you want inside each cell. So, to have two "lines" per cell you can simply choose "custom" cell, drag it down to increase the size and insert two Labels inside.
For the XML parsing:
First you have to understand how a XML is parsed in Swift. Here's a tutorial I wrote:
https://medium.com/#lucascerro/understanding-nsxmlparser-in-swift-xcode-6-3-1-7c96ff6c65bc
In your case, you have to construct your code so you only check the <Field> element when inside a <Record> element. Then you differentiate between "username" and "password" data by checking your <Field>'s attributes.
For the String:
Lastly, your resulting foundCharacters will not be the final data you need. There are many methods of the String type that can solve this. One example is to use the method removeRange to remove the starting and ending characters, since they appear to always be the same ones (in your case: "<![CDATA[" and "]]>", assuming you're getting them returned as String types).
When I try to use date format tag in gsp view to change the format of my date but it doesn't work.
This is my code:
class MyDate {
Date date
}
MyDateController:
....
def unixSeconds = params["date"].replaceAll("\"", "") as long //params["date"]="1386157660"
Date date = new Date(unixSeconds*1000L)
myDateInstance = new MyDate(date:date)
....
gsp View:
${myDateInstance.date.format('yyyy-MM-dd HH:mm')}
The format that I have is 2013-12-04 12:47:40.0 instead of 2013-12-04 12:47
Afaict, that shouldn't happen and I can't see how it is happening...
Are you sure that's the line of code that's generating the output you're seeing?
You could try the Grails formatDate tag in its place:
<g:formatDate format="yyyy-MM-dd HH:mm" date="${myDateInstance.date}"/>
You can use "formatDate" in value attribute like following
<g:textField name="saleDate" value="${formatDate(format:'dd-MM-yyyy',date:saleItem?.saleDate)}"/>
In addition to #tim_yates's answer above, there is another point I want to add:
I observed that if type and style are given, format is not used. I think they work as alternatives for each other. Also, using format would be beneficial as the Date string format could differ on different operating systems.
I am using dynamic MenuContribution and get a warning that two of my referenced identifiers "cannot be found". Even though the contribution works. These warnings bug me.
I have a CompoundContributionItem implementation defined in one of my plugins. Basically it looks like this:
public class ViewerHistoryMenuItems extends CompoundContributionItem
implements IExecutableExtension {
private static final String PARAM_TYPE = "type";
private static final String PARAM_COMMAND = "command";
// some fields
public void setInitializationData(final IConfigurationElement config,
final String propertyName, final Object data) {
/* set fields */
}
protected final IContributionItem[] getContributionItems() {
/* create Items */
}
}
In other plugins I use this ContributionItem implementation by declaring the following:
<menuContribution locationURI="menu:mylocationUri">
<dynamic id="myId">
<class class="ViewerHistoryMenuItems">
<parameter
name="type"
value="someValue">
</parameter>
<parameter
name="command"
value="someCommandId">
</parameter>
</class>
</dynamic>
<command
commandId="someCommandId"
icon="anIcon.png">
</command>
</menuContribution>
When looking at the Problems-View I get two entries there (for each plug-in, which uses this contribution):
**Referenced identifier 'type' in attribute 'name' cannot be found**
**Referenced identifier 'command' in attribute 'name' cannot be found**
What am I missing here? Any ideas, why I get this warning?
PS: It doesn't help, to make the two fields PARAM_TYPE & PARAM_COMMAND public
I do not think this is related to the presence of internal fields within a class.
If you look at a similar error (not the same since it includes annotationType), the correction involved the definition of said Referenced identifier:
Referenced identifier 'com.atlassian.connector.eclipse.cruicible.ui.comment.annotation'
in attribute 'annotationType' cannot be found
Fixed with:
+ <extension
+ point="org.eclipse.ui.editors.annotationTypes">
+ <type
+ markerType="com.atlassian.connector.eclipse.crucible.ui.com.atlassian.connector.eclipse.cruicible.ui.comment.marker"
+ name="com.atlassian.connector.eclipse.cruicible.ui.comment.annotation">
+ </type>
+ </extension>
+ <extension
+ id="com.atlassian.connector.eclipse.cruicible.ui.comment.marker"
+ point="org.eclipse.core.resources.markers">
+ </extension>
Considering the extension point org.eclipse.ui.menus help page:
<!ELEMENT parameter EMPTY>
<!ATTLIST parameter
name IDREF #REQUIRED
value CDATA #REQUIRED
>
A parameter to either an executable extension or a command -- depending on where it appears in the extension.
name - The name is either the name of the parameter to pass to the executable extension, or the identifier of the parameter for the command.
value - The value to pass for this parameter.
You need to reference in the name attribute an id present somewhere else in your plugin.xml.
Sure thing, VonC. Here we go:
Within the dynamic declaration (see above) there are two parameter references
<parameter
name="type"
value="someValue">
</parameter>
<parameter
name="command"
value="someCommandId">
</parameter>
These two parameter are meant to be passed to the command itself. The command declaration is within the same plugin.xml but wasn't declaring these two commandParameters.
What I did was adding these missing commandParameters, resolving the missing reference, which was clearly stated by the warning.
<command
categoryId="aCategory"
id="someCommandId"
name="%theName">
<commandParameter
id="type"
name="type"/>
<commandParameter
id="command"
name="command">
</commandParameter>
</command>
So, you were absolutely right by saying "the correction involved the definition of said reference identifier". The question just was where and what I had to define.
I think, I wasn't thinking about the most obvious in this case.
my form is passing the String name of the country to the action. how can i pass the id of the object country from the combobox to the action?
this is what i have:
s:combobox label="Country" name="country" headerValue="Select" headerKey="1" list="%{countries}" listValue="name"/>
thanks.
You have missed the listKey attribute.
If you change it as:
<s:combobox label="Country" name="country" headerValue="Select" headerKey="1"
list="%{countries}" listValue="name" listKey="id"/>
It will probably work.
See http://struts.apache.org/2.0.14/docs/combobox.html for all the attributes available.