Display formatted decimal numbers in Primefaces 4 [duplicate] - jsf

This question already has an answer here:
Displaying a number in 2 point decimal format in jsf
(1 answer)
Closed 5 years ago.
I have a database table with a float field and I want to display it through Primefaces.
I want to display the numbers formatted as (one thousand, for example): 1.000,00
I tried:
<p:column sortBy="#{item.value}" filterBy="#{item.value}">
<f:facet name="header">
<h:outputText value="#{epoBundle.ListUpbTitle_value}"/>
</f:facet>
<h:outputText value="#{item.value}"/>
<f:convertNumber pattern="#0.000" locale="pt_BR"/>
</p:column>
But got:
/WEB-INF/include/entity/upb/List.xhtml #80,55 Parent not an instance of ValueHolder: org.primefaces.component.column.Column#13ec99d0
Can someone help me?
Thanks in advance.

f:convertNumber must be inside h:outputText.
<h:outputText value="#{item.value}">
<f:convertNumber pattern="#0.000" locale="pt_BR"/>
</h:outputText>

Related

Concatenation inside a JSF expression [duplicate]

This question already has answers here:
How to concatenate a String in EL?
(5 answers)
Closed 4 years ago.
I'm trying to concatenate a number inside my JSF expression:
<h:dataTable class="seminaire" value = "#{seminaireControl.getList()}" var = "seminaire">
<c:forEach begin="1" end="#{extraControl.getNb()}" var="nb">
<h:column>
<f:facet name="header">seminaire #{nb}</f:facet>
<h:inputText value="#{seminaire.value+#{nb}"/>
</h:column>
</c:forEach>
</h:dataTable>
What I'm trying to have is something like #{seminaire.value1}, #{seminaire.value2}, ...
Concluding the above, to help other users for EL syntax to be used in proper manner.
(The + operator is in EL exclusively a sum operator.)
<h:dataTable class="seminaire" value = "#{seminaireControl.getList()}" var = "seminaire">
<c:forEach begin="1" end="#{extraControl.getNb()}" var="nb">
<h:column>
<f:facet name="header">seminaire #{nb}</f:facet>
<h:inputText value="#{seminaire['value'.concat(nb)]}"/>
</h:column>
</c:forEach>

If else condition in jsf [duplicate]

This question already has answers here:
Correct syntax to compare values in JSTL <c:if test="${values.type}=='object'"> [duplicate]
(1 answer)
The representation of if-elseif-else in EL using JSF
(4 answers)
Closed 7 years ago.
I have to display a list of element in groups. I am expecting out like in the image.
If I remove if condition its printing all option in all groups.
<p:accordionPanel value="#{menuView.menunames}" var="name">
<p:tab title="#{name}">
<c:forEach items="#{menuView.menu}" var="entry">
<h:outputText value="(#{entry.key} == #{name})"></h:outputText>
<c:if test='#{entry.key} == #{name}'>
<h:dataTable value="#{entry.value}" var="submenu">
<h:column>
<h:outputText value="#{submenu}" />
</h:column>
</h:dataTable>
</c:if>
</c:forEach>
</p:tab>
</p:accordionPanel>
private Map<String, List<String>> menu;
private List<String> menunames;
The EL expression should be like this:
<h:outputText value="#{entry.key == name}">
<c:if test="#{entry.key eq name}">
I use a c:choose for this, with the c:when for the if part and c:otherwise for the else part.

How to get multiple h:selectOneMenu values inside h:dataTable [duplicate]

This question already has answers here:
Input field in <h:dataTable> always receives value of last item in list
(3 answers)
Closed 7 years ago.
I'm using h selectOneMenu in a datatable and when user press the Set Fixture button i'm saving the value changed in the dropdown, for now i'm using a String variable to get the selected value but the issue is it have the selected value from only the last dropdown. My question is how to get list of all the dropdowns ?
<h:form id="chooseAlmFixtureForm">
<p:panel style="width:80%" header="Set Fixture for Alarms">
<p:dataTable id="tbsetFixtureTable" value="#{setAlmFixtures.alarms}" var="alarmvar" dynamic="false">
<p:column>
<p:commandLink value="View" update=":viewUnknownAlarm" immediate="true" oncomplete="viewDialog.show()">
<f:setPropertyActionListener target="#{currentalarms.viewAlarm}" value="#{alarmvar}"/>
</p:commandLink>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Alarm Time"/>
</f:facet>
<h:outputText value="#{alarmvar.recvTime}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Alarm Type"/>
</f:facet>
<h:outputText value="#{alarmvar.alarmType}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Controller Name"/>
</f:facet>
<h:outputText value="#{alarmvar.controllerName}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Controller Type"/>
</f:facet>
<h:outputText value="#{alarmvar.controllerType}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Choose Fixture"/>
</f:facet>
<h:selectOneMenu id="selectAlarmSite" value="#{setAlmFixtures.selectedFixture}">
<f:selectItems value="#{setAlmFixtures.fixtures}" />
</h:selectOneMenu>
</p:column>
</p:dataTable>
<p:commandButton value="Set Fixtures" actionListener="#{setAlmFixtures.setAlarmsFixtures}" action="#{horizontalmenu.actionCallAlarmsPage}" styleClass="dialogButton"/>
</td><td>
<p:commandButton value="Cancel" actionListener="#{setAlmFixtures.releaseAlarms}" action="#{horizontalmenu.actionCallAlarmsPage}" styleClass="dialogButton"/>
</p:panel>
</h:form>
Currently, your dropdown-value refers to a single variable in your bean (which seems to be selectedFixture of class SetAlmFixtures). How would a single variable represent a state (value) for multiple row (here: alarms)?
You need to link the selected value to the row (alarm) it refers to. To do so, you have several options, two approaches following:
Use the variable of your alarm-object, just the same way as you used them as outputvalues inside the other columns. This way, the alarm's fixture is set directly on value (form) processing. Currently, both of your buttons submit the form (type="submit" is default), depending on what your actionlisteners do, you might consider changing the Cancel-button's type to button.
Map the fixtures and alarms. You could use something like Map<Long, Fixture> fixturemap; mapping alarm-id's to their selected fixture, assuming all alarms have a non-null id. The map's value can be referred by setAlmFixtures.fixturemap['alarmvar.id']. Make sure you provide a getter for the map and the id. Also, you need to initialize the map with the initial fixture values for each alarm.

Masking numbers in PrimeFaces datatable

Related to the question Display formatted decimal numbers in Primefaces 4, how can I display - in a PrimeFaces datatable - a number masked like this:
1.987.654,32
The original data, which are read from a float column in SQLServer database table, is (e.g.):
1987654.32
I've tried the code below, but no success:
<p:column sortBy="#{item.value}" filterBy="#{item.value}">
<f:facet name="header">
<h:outputText value="#{epoBundle.ListUpbTitle_value}"/>
</f:facet>
<h:outputText value="#{item.value}">
<f:convertNumber pattern="#0.000" locale="pt_BR"/>
</h:outputText>
</p:column>
Thanks in advance.
The correct pattern for the <f:convertNumber .../> you want is: ###,###.000. You can read more about decimal formatting here: http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
Bonus: for different masks, you can use other locales: https://stackoverflow.com/a/11836387/1362049

Formatting money values with f:convertNumber

I had to customise a JSF XHTML template which has 2 different values and their sum displayed
<h:outputText value="#{Invoice.totalCharge/100 + Invoice.subscription/100}">
<f:convertNumber currencySymbol="£" groupingUsed="#{true}" maxFractionDigits="4" type="currency"></f:convertNumber>
</h:outputText>
<h:outputText value="#{Invoice.tax/100}">
<f:convertNumber currencySymbol="£" groupingUsed="#{true}" maxFractionDigits="4" type="currency"></f:convertNumber>
</h:outputText>
<h:outputText value="#{Invoice.grandTotal/100+Invoice.subscription/100}">
<f:convertNumber currencySymbol="£" groupingUsed="#{true}" maxFractionDigits="4" type="currency"></f:convertNumber>
</h:outputText>
With values displayed as
720.1252 +
144.025 =
864.1502
I set maxFractionDigits to 4 deliberately to confirm my suspicions. It has to be 2 in the end but in that case and thats where the problem is
With fraction digits = 2 you get
720.13 +
144.03 =
864.15
Which for a person looking at the printout is plain crap.
When and how should I do the math so that the result makes sense to the bean counters across the office and not techies like us?
I have no access to the source all I can change is this XHTML template.

Resources