I have this expression in iReport.:
($F{Q3_February}==0)?"-":$F{Q3_February}
Expression class is Double, I want this to returns as "-" if the value of $F{Q3_February} is 0.
I get "-" only if I change it to Expression class String but the problem is if the value is false it doesn't return a value of #,##0.00 %
Your problem is that the textField pattern is not applied if the expression class is not numeric. You are trying to conditionally change not only the value, but also the class. This is not possible with a single textField.
I think your best bet is to separate this into two textFields, one string and one double. Place them on top of each other and then use printWhenExpressions to hide the one that is not wanted. The end result will be similar to having a single field with a conditional expression, but gives you more flexibility with the other element properties (i.e. class and pattern).
Example:
<textField pattern="#,##0.00 %">
<reportElement x="200" y="80" width="100" height="20">
<printWhenExpression>
<![CDATA[$F{Q3_February}!=0]]>
</printWhenExpression>
</reportElement>
<textFieldExpression class="java.lang.Double">
<![CDATA[$F{Q3_February}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="200" y="80" width="100" height="20">
<printWhenExpression>
<![CDATA[$F{Q3_February}==0]]>
</printWhenExpression>
</reportElement>
<textFieldExpression class="java.lang.String">
<![CDATA["-"]]>
</textFieldExpression>
</textField>
There are a few alternative ways [to GenericJon's suggestion to solve this]:
With 4.1.1 there is a field on text boxes called "Pattern Expression" it is a field based
field formatting option
You can format the field before it goes into the dataset [not recommended but works]
Lastly, you can call a scriptlet and pass in the values of the fields within the text section of the textbox.
[Define Scriptlet name="bob"]
<textFieldExpression class="java.lang.String">
<!CDATA[$P{[bob]_SCRIPTLET}.formatValues(fields1:n..)]]></textFieldExpression>
Related
I am trying to use DiffBuilder to ignore XML elements order when comparing two .xml files but it fails. I have tried every possible combination and read many articles before posting this question.
For example:
<Data:Keys>
<Data:Value Key="1" Name="Example1" />
<Data:Value Key="2" Name="Example2" />
<Data:Value Key="3" Name="Example3" />
</Data:Keys>
<Data:Keys>
<Data:Value Key="2" Name="Example2" />
<Data:Value Key="1" Name="Example1" />
<Data:Value Key="3" Name="Example3" />
</Data:Keys>
I want these two treated as same XML. Notice that elements are empty, they have only attributes.
What I did so far:
def diff = DiffBuilder.compare(Input.fromString(xmlIN))
.withTest(Input.fromString(xmlOUT))
.ignoreComments()
.ignoreWhitespace()
.checkForSimilar()
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.conditionalBuilder()
.whenElementIsNamed("Data:Keys").thenUse(ElementSelectors.byXPath("./Data:Value",
ElementSelectors.byNameAndText))
.elseUse(ElementSelectors.byName)
.build()))
But it fails every time. I don't know if the issue is the namespace, or that the elements are empty.
Any help will be appricated. Thank you in advance.
if you aim to match tags Data:Value by their attributes together, you should start with this:
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.conditionalBuilder()
.whenElementIsNamed("Data:Value")
and since that tag doesn't have any text, the byNameAndText won't work. You can only work on names and attributes. My advice is to do it like this:
.thenUse(ElementSelectors.byNameAndAttributes("Key"))
or
.thenUse(ElementSelectors.byNameAndAllAttributes())
//equivalent
.thenUse(ElementSelectors.byNameAndAttributes("Key", "Name"))
As of issues with namespaces, checkForSimilar() should output SIMILAR, this means they are not DIFFERENT, so this is what you need. If you didn't use checkForSimilar() the differences in namespaces would be outputed as DIFFERENT.
I have Spring bind form with freemarker. But large number show Exponent value. How to show value without Exponent.
For small numeber...
<#spring.formInput 'CaseMaster.year' 'placeholder="e.g. 2013" ' 'number'/>
For large number...
<#spring.formInput 'CaseMaster.suitValue' 'placeholder="e.g. Suit Value" ' />
HTML View:
I wnat to show value like 80000000 or 80000000.00 or like 8,00,00,000.00 in the second field.
I've dug down into the macro and it looks like you have no control over the formatting to the populated value. Perhaps there's a more elegant solution, but at this point, you might try creating your own macro that gives you formatting control. (This is untested.)
<#macro numberInput path attributes="">
<#spring.bind path/>
<input type="text"
id="${status.expression?replace('[','')?replace(']','')}"
name="${status.expression}" value="status.value?c" ${attributes}<#closeTag/>
</#macro>
You would call it like this:
<#numberInput 'CaseMaster.suitValue' 'placeholder="e.g. Suit Value" ' />
I want remove an xml attribute via xpath, but
the xml element could have more atrributes in the future.
html code:
<p class="red, blue, green">test/<p>
xpath:
<xpath expr="//p[contains(#class, 'green')]" position="attributes">
<attribute name="class">red, blue</attribute>
</xpath>
Is where a better way for fixtext "red, blue"?
In order to suppport possible new version of the html file like
"<p class="red, blue, green, brown">test</p>" in the future without need to change the xpath code again.
for instance actual attribute list as var + an xpath function
What about setting the #class to
concat(substring-before(#class, "green"), substring-after(#class, "green"))
You'll need to solve the abandoned commas, too, but as Björn Tantau commented, in real HTML the classes would be separated by spaces, so you can just wrap the result into normalize-space.
I have the following rad numeric textbox.
> <telerik:RadNumericTextBox ID="numTxtIMEI" runat="server"
> MaxLength="20" MinValue="0" Visible="false"
> maxvalue="99999999999999999999" AutoCompleteType="Disabled">
> <NumberFormat GroupSeparator="" DecimalDigits="0" /> <ClientEvents
> OnKeyPress="preventDecimalSeparator" /> </telerik:RadNumericTextBox>
Inspite of setting maxlength and maxvalue to allow 20 numbers into the textbox, it allows only 16numbers . when i type 17th number, it automatically turns to zero. what should i do to allow this numeric textbox to allow 20numbers?
"Telerik RadNumericTextBox control does not support maximum/minimum value more/less than +/- 2^46
Setting the MaxValue property more than 2^46 may cause abnormalities in the RadNumericTextBox behavior."
Quoted from a Telerik forum posting. I have linked it below. It does give an option on how to do a larger number, but I have not tested that myself.
http://www.telerik.com/community/forums/aspnet/input/change-max-value-of-radnumerictextbox.aspx
I maybe be trying to do something invalid here, but maybe someone smarter than me knows the correct syntax to solve my problem.
Given:
<group code="vehicle">
<line code="car">
<cell>
<box code="price">1000.00</box>
</cell>
</line>
<line code="car">
<cell code="sports">
<box code="price">500.00</box>
</cell>
</line>
</group>
If I use //*[#code="vehicle"]//*[#code="car"]//*[#code="price"], I will get both boxes returned (1000.00 and 500.00)--as expected but not what I want.
Is there an xpath syntax that will evaluate against all nodes that have an attribute of #code rather than skipping it if it doesn't match with the end result being that I only get back the first box (price of 1000.00)? Like asking, choose the first node with #code and that #code must equal "vehicle", then choose the next node with #code and that #code must equal "car", then choose the next node with #code and #code must equal "price".
Use:
"//box
[(#code='car' or #code='price' or #code='vehicle')
and
not(
ancestor-or-self::*
[
#code
and
not(#code='car'
or
#code='price'
or
#code='vehicle'
)
]
)
]
Not an expert on xpath but XmlSpy seems to indicate that this would work?
(//*[#code="vehicle"]//*[#code="car"]//*[#code="price"])[1]