<f:convertNumber> inside <h:outputText> doesn't work - jsf

I want to do output text with value of currency:
<h:form rendered="#{not empty cartBean.cartMap}">
<h:outputText escape="false" styleClass="cart-text"
value="Your shopping cart: <b>
#{cartBean.cartDishesCount}</b> items,
total= <b>#{cartBean.updateTotalPrice()}</b>">
<f:convertNumber currencyCode="USD" type="currency"/> <!-- doesn't work -->
</h:outputText>
</h:form>
but <f:converNumber> is ignoring and page output still looks like this:
Your shopping cart: 9 items, total= 46.800000000000004

Try to have only the value in the value as in
<h:outputText value="#{cartBean.updateTotalPrice}" >
<f:convertNumber currencyCode="USD" type="currency" />
</h:outputText>
The convert number expects a number, since the value of the outputText is a string, it does not recognize it.
Anything that is not the number would be displayed separately.
If you want to explicitly specify the location then this is an option
<f:convertNumber type="currency" currencySymbol="$" locale="en_US" />

Related

Primefaces datatable Identify if the current column is of date type

I am trying to make a common datatable using primefaces.
I want to check if the current column of datatable is of Date type. If it is a Date I want to add DatetimeConverter -
Here is my code -
<ui:component>
<p:dataTable id="#{tableId}" value="#{data}" var="row" styleClass="stdTable vertLines fndTable vertLinesRightBorder"
style="table-layout:fixed; border-color: #dddddd;">
<p:columns value="#{tableColumns}" var="column" sortBy="#{row[column.property]}">
<f:facet name="header">
#{column.header}
</f:facet>
#{row[column.property]}
</p:columns>
</p:dataTable>
</ui:component>
I am calling the above xhtml as follows-
<ui:include src="table.xhtml">
<mbcpos:param name="tableId" value="#{me.id}hTabel1" />
<mbcpos:param name="data" value="#{taskListBean.receivedOwnerTasks}" />
<mbcpos:param name="tableColumns"
value="#{me.columns}" />
</ui:include>
Can we identify the column datatype :
e.g., #{row[column.property]} equals Date
If the column is a date I want to format the date.
Your column model should be where you put the data type it holds and other data type presentation related things like masks, currency, alignment etc.
On the page, for each data type (according to your needs), inside the p:columns
you should do something like this:
<h:outputText rendered="#{column.dateType}" value="#{row[column.property]}">
<f:convertDateTime pattern="dd/MM/yyyy"/>
</h:outputText>

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

p:selectOneMenu, custom content and editable=true

I have the following usage of the p:selectOneMenu:
<p:selectOneMenu id="selectField"
value="#{someBean.someField}"
converter="#{selectItemConverter}" var="x" editable="true">
<f:selectItems
value="#{selectItemsBean.getSelectItems(tab, field)}" var="si"
itemLabel="#{si.label}" itemValue="#{si}" />
<p:column>
<h:outputText value="#{si.label}" />
</p:column>
<p:column>
<h:graphicImage library="images" name="noway_16x16.png"
title="#{si.disabledReason}" rendered="#{si.disabled}" />
</p:column>
<p:ajax event="change" update="#form" partialSubmit="true" process="selectField" />
</p:selectOneMenu>
As you can see, I use custom content in combination with editable=true. When I submit the form, the Converter gets the label of a selected item as the value, not the actual value. In the HTML page, the values are correct, e.g. <option value="C">C-style mounting</option>. With editable=false, the correct value (e.g. C is sent to the converter, with editable=true the converter retrieves C-style mounting.
What I want is that the user can either select one of the pre-defined items in the list and the server submits that value of the item OR the user enters something and that is submitted as value. But the current behavior is a bit strange - or am I just wanting too much?

How to reuse the jsf component parameters?

I have code
<p:column id="columnLastComment" headerText="LAST COMM" width="80"
styleClass="long-field" filterStyleClass="flt-hidden"
style="#{alarmTable.getDisplayStatus('columnLastComment')}"
sortBy="#{alarm.lastComment}" filterBy="#{alarm.lastComment}">
<h:outputText value="#{alarm.lastComment}" />
<f:facet name="header">
<h:outputText value="LAST COMM" title="Last Comment"
styleClass="tableHeader-fontSize" />
</f:facet>
</p:column>
How i can use id of column in style value? example -
style="#{alarmTable.getDisplayStatus('[id of this column]')}"
Theoretically, you could get away with the implicit EL variable #{component} to get the current component, like so:
<h:outputText id="foo" styleClass="#{bean.styleClass(component.id)}" />
But, unfortunately, the UIColumn component has a special treatment. The #{component} refers the parent UIData component instead, which would in your case be the <p:dataTable>.
So, you've really to repeat it (like as you're already doing for the phrase "lastComment". You could maybe make it less painful by using a property of #{alarm}.

Value is not populated in <p:inputMask> in jsf

when i put attribut mask="" in p:inputMask tag,it populate value properly like this::
<h:outputLabel for="lblPostalCode" value="#{label.postalCode}:" style="font-weight:bold" />
<p:inputMask id="lblPostalCode" style="width: 80px" value="#{certHolderDetail.selectAdd.postalCode}" mask="" />
But when i used default mask for that field like mask="99999-9999" like this
<h:outputLabel for="lblPostalCode" value="#{label.postalCode}:" style="font-weight:bold" />
<p:inputMask id="lblPostalCode" style="width: 80px" value="#{certHolderDetail.selectAdd.postalCode}" mask="99999-9999" />
it does not populate the value......:(
Please look this.
My guess would be that the value (#{certHolderDetail.selectAdd.postalCode}) does not actually conform to the pattern. Eg, perhaps it is a 5 digit address, instead of the expected 5+4?

Resources