cannot have space when exceding three integer with f:converternumber jsf2 - jsf-2

I want to see all number like that : 123 456.67 : a space when I exceeded 3 integer and always two fractions number
I tested that :
<f:view contentType="text/html" locale="en" encoding="UTF-8">
and that on each inputText :
<p:column headerText="Ajust Prix">
<h:inputText value="#{car2.ajustPrix}" >
<f:convertNumber pattern="#0.00" maxFractionDigits="2" />
</h:inputText>
</p:column>
but I don't have the space when exceeding three integer,
how can I resolve this

The pattern attribute of <f:convertNumber> uses the java formatting patterns that can be found in javadocs for DecimalFormat. With the pattern you may specify the so-called 'grouping separator', which is what you're after. Also, it's worth reading some tutorials on the subject, like Oracle's one.
All in all, you need to use the following pattern: #,##0.00. It can be used like this:
<f:convertNumber pattern="#,##0.00" />

Related

Does not work properly id generation on ui:repeat My faces 2.2.9 + prime faces 5.3

Actually I'm working with Myfaces version 2.2.9 and I've the following structure to generate any panel according with a specific number selected by the user.
...
<ui:repeat value="#{garajes}" var="garaje" varStatus="loop">
<p:panelGrid >
<h:outputLabel value="Numero de garaje #{loop.index+1}: " />
<h:outputLabel value="Matricula #{loop.index+1}: " />
<p:inputText value="#{garaje.numeroGaraje}" maxlength="5" >
</p:inputText>
<p:inputText id="matriculaInmobiliariaGaraje-#{loop.index+1}" value="#{garaje.matriculaInmobiliaria}"
maxlength="20">
</p:inputText>
...
</p:panelGrid>
</ui:repeat>
....
So, when is rendered the above code the identifiers are weird, has another things like the following image:
So I don't know how to remove this weird things inside of id
Note: I need a specific id to update another component inside of the loop.
What can I do to get a right identifiers inside of ui:repeat?
As to the concrete problem, just give all NamingContainer components a fixed ID. This includes the <ui:repeat> itself.
<ui:repeat id="garajes" ...>
As to the concrete requirement, you're overcomplicating things. A NamingContainer will all by itself worry about uniqueness of IDs of children. Your attempt in id="matriculaInmobiliariaGaraje-#{loop.index+1}" won't work at all as #{loop} variable isn't available during view build time, when the component is being instantiated with id. Get rid of it. You can inside a NamingContainer just use a relative ID to reference another component in the same NamingContainer.
<ui:repeat ...>
<p:inputText id="foo" />
<p:inputText ...><p:ajax ... update="foo" /></p:inputText>
</ui:repeat>
This will work just fine.
See also:
How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
How to use EL with <ui:repeat var> in id attribute of a JSF component

How to use fn:replace() to replace one doublequote by two doublequotes

In my JSF application I am trying to use fn:replace() to replace " by "". I tried the following:
<h:outputText value="#{fn:replace(str, '\"', '\"\"')}" />
However, it causes a XML parsing exception:
javax.faces.view.facelets.FaceletException: Error Parsing /test.xhtml: Error Traced[line: 20] Element type "h:outputText" must be followed by either attribute specifications, ">" or "/>".
The same code is working for other charecters like the below one:
<h:outputText value="#{fn:replace(str, 'a', 'b')}" />
How can I replace a doublequote by two doublequotes using fn:replace()?
Indeed, this is nasty. The " has special treatment in XML. It represents the start and end of an attribute value. Your best bet is to parameterize it into another variable with help of <c:set>.
<c:set var="doublequote" value='"' />
<c:set var="twodoublequotes" value='""' />
<h:outputText value="#{fn:replace(bean.string, doublequote, twodoublequotes)}" />

double reference in EL expression

I'm trying to make a "rich:dataTable" with a dynamic number of columns. I have a bean with a List of columns (with attributes headerName and fieldName) and a list of items to be represented in the table so I have next code:
<rich:dataTable id="data_table" value="#{bean.list}" var="item">
<c:forEach items="#{bean.columnList}" var="col">
<rich:column>
<f:facet name="header">
<h:outputText value="#{col['headerName']}" />
</f:facet>
<h:outputText value="??" />
</rich:column>
</c:forEach>
</rich:dataTable>
The problem is that I don't know how to put the value="??" to represent what I want. I want something like:
value="#{item.#{col.fieldName}}"
but I don't know how can I represent it with the correct Expression Language.
I'm using JSF2.1 and Richfaces 4.3.2
Con somebody help me with this issue?
Use the brace notation #{bean[property]}. It allows you to use variables instead of constants as property names.
value="#{item[col.fieldName]}"

<rich:dataTable> from listOfMaps

I have a SessionScoped bean which has a list of maps. I am attempting to get a <rich:dataTable> produced using <a4j:repeat>.
The list of maps is being populated correctly, although there is no dataTable output. From reading articles on stack-overflow, I think my problem may be occuring due to the life-cycle problems or my novice understanding of jsf with richfaces.
Using: Tomcat 7, JSF 2.1x - Mojarra, Richfaces 4.x
Here is what I have so far;
<rich:dataTable value="#{myBean.myMap}" var="map">
<a4j:repeat value="#{myBean.myMap[0].keySet().toArray()}" var="key">
#{map[key]}
</a4j:repeat>
</rich:dataTable>
If someone could point my in the correct direction, the help would be greatly appreciated!
Answer:
As stated below the solution is to instead use <c:forEach> and use <rich:columns>.
Solution:
<rich:dataTable value="#{queryBean.test}" var="map">
<c:forEach items="#{queryBean.test[0].keySet().toArray()}" var="key">
<rich:column style="text-align:left; width:auto;">
<f:facet name="header">
<h:outputText value="#{key}" />
</f:facet>
<h:outputText value="#{map[key]}" />
</rich:column>
</c:forEach>
</rich:dataTable>
First of all <rich:dataTable> has to contain columns - <rich:column>
Assuming you want to have dynamic table (the number of columns based on the length of the map) you will have to use <c:forEach> instead of <a4j:repeat>. I have answered a question about this a while ago, take a look.

Primefaces crop converter error

I am using the following code and try to crop an image which takes its value from a bean :
<p:panelGrid columns="2">
<p:row>
<p:column>
<p:imageCropper id="imageCropperId" value="#{imageCropperBean.croppedImage}"
image="#{imageCropperBean.newImageName}">
</p:imageCropper>
</p:column>
<p:column>Bild innerhalb des Rahmens positionieren</p:column>
<p:column>
<p:graphicImage id="localCroppedImage" value="#{imageCropperBean.newImageName}" />
</p:column>
</p:row>
<p:row>
<p:column colspan="3">
<p:commandButton value="Crop" actionListener="#{imageCropperBean.crop}"
update=":growl imageCropperId localCroppedImage" />
</p:column>
</p:row>
</p:panelGrid>
I am always getting the error : {0}: Conversion error occurred. inside growl, due to :
value="#{imageCropperBean.croppedImage}"
The converter attribute from declaration says :
An el expression or a literal text that defines a converter for the
component. When it's an EL expression, it's resolved to a converter
instance. In case it's a static text, it must refer to a converter id.
but the EL expression is evaluated at String. What should I do? It works if I put a normal String pointing to an existing image.
I have managed to fix this error.
For the ones which will have the same problem, basically this occurs when
Either errors are being thrown during cropping phase (e.g. files not found or if the cropped image is not relative to the original one)
Either the value which is evaluated from EL image="#{imageCropperBean.newImageName}" is evaluated to null, while trying to skip the cropping (I couldn't suceed with required="true" so I used rendering="someCondition")

Resources