Number alignment in JSF - jsf

I am developing an ADF based project. The code below is a part of my View. I want to show a NUMBER value in the input text field which can be changed anyway. All I want is that value to be right aligned in the field. I have read that contentStyle="text-align:right; does the job, but the requirement is not to use it. I am wondering myself if the value is of type number and convertNumber is used in the code, should the value be right aligned automatically?
I will appreciate any help you give me!
<af:inputText value="#{row.bindings.B.inputValue}"
styleClass="class" simple="true"
required="#{bindings.A.hints.B.mandatory}"
maximumLength="#{bindings.A.hints.B.precision}"
shortDesc="#{bindings.A.hints.B.tooltip}"
id="bb" autoSubmit="true"
disabled="#{viewScope.aBean.getSmth('abc')}"
valueChangeListener="#{viewScope.aBean.onBChange}">
<f:validator binding="#{row.bindings.B.validator}"/>
<af:convertNumber groupingUsed="false"
pattern="#{bindings.AA.hints.B.format}"/>

Use AFFieldNumberMarker in styleClass property of af:inputText, It will right align your value

Related

Pagination not working in jsf rich:datascroller

how to make work rich:datascoller with nested components.
Data table iteration works fine but pagination is not working.
does rich:datascroller works with nested component?
<a4j:repeat >
<rich:datatable id="test">
......
</rich:datatable>
<rich:datascroller for="test"></rich:datascroller>
</a4j:repeat >
any help will be greatly appreciated
Firstly please answer the my question asked in comment section.
About your issue i do not know why you did not add at lease full code of Datatable .
If you read the documentation of the component(Rich_Datascroller) its mentioned below thing
The component should be placed into the footer of the parent table or be bound to it with the "for" attribute. Note, that "for" is
evaluated on view build, not on view render, that is why it will
ignore JSTL tags.
The table should also have the defined "rows" attribute limiting the quantity of inputted table rows.
The scroller could limit the maximum quantity of rendered links on the table pages with the help of the "maxPages" attribute.
So according to above points its look like you missed
The table should also have the defined "rows" attribute limiting the
quantity of inputted table rows.
As per documentation its a mandatory. point to remember . Apart from your issue its good practice before asking in stackoverflow create a simple example and try it out of the box.
About my question I am more interested to know how your code will be work without generating dynamic id as per your code your component id is Static . It should throw the exception because <a4j:repeat> nothing but a for loop.

required fields skip reactions to user input

If there are empty required fields in the form, they prevent me both from setting the values via code and hide/show other fields depending on current user input.
I broke down my problem to a tiny example:
<h:inputText label="Name" value="#{req.test}" required="true"/>
<h:inputText label="Details" value="#{req.tests2}" readonly="true" required="true"/>
<h:selectBooleanCheckbox label="Hide field" value="#{req.bool1}"/>
<ui:fragment rendered="#{not req.bool1}">
<h:inputText label="Hidden" value="#{req.test3}" required="true"/>
</ui:fragment>
I have required fields in my form, but if the user chooses to first set the checkbox, I want the hidden field to appear even if the validation failed. And I want the fields to be marked as invalid, so I cannot use immediate.
The problem is that while processing validation, renderResponse is called in the jsf lifecycle. So the update model values phase is skipped and I cannot react to the user input.
In addition to that: If I fill all required fields with the checkbox checked (the form would be valid) and uncheck the checkbox (a required field "Hidden" appears), I cannot just make "Hidden" to disappear again by checking the checkbox, because "Hidden" cannot be empty as required field. Even if I say required="#{not req.bool1}" it does not work, as the checkbox value never reaches my model because the update model value phase is skipped.
What we did now is wrap the faces context to prevent a call to renderResponse() during the validation phase from setting the flag. (Yes, dangerous, yes, I do need a better way to do that.) Now finally the model is up to date, BUT:
The required fields still remain empty, because for some reason jsf decided required fields do not need to get their value from my model as long as they are empty/invalid.
How can I make my model values to appear in the required fields?
Is there a simple and proper way to solve my ignore-invalid-state-and-continue-with-phases-properly problem, other than basically preventing renderResponse() from happening?
So the answer to the first question is: reset the value and THEN update, then I get my values to show in the required fields. Thanks Vasil!
As for the second question: I wonder how it's possible no one ran into the problem before. Is it just me? Well, I guess I'm not getting the point and am using the life cycle wrong or something. But I was really thinking the view should respond to user input, even it some fields are still empty. The user is still inserting data after all, and we're not moving on, yet. The fields are allowed to be empty in that state.
I guess that's the point and my "required" means something else than the jsf "required". I still don't get the standard validation process in that regard...
But I have a dirty workaround for my problem, so I'll mark the question as answered.

Unable to paste the context in Primefaces Extension pe:inputNumber using mouse

We've been using Primefaces (v 3.5) and Primefaces Extensions (v 0.7.0) in our project and it's been great, cheers for the developers and community!
The inputNumber component takes care of pretty much all of our needs when dealing with decimal fields.
The one thing that isn't working is when the user paste a value into the field using the mouse right button then paste option.
When that happens, it seems these values aren't processed, since when I submit the form they are cleared, no matter it's a valid or unvalid value.
The user can even paste a text into the pe:inputNumber. The control c + control v works as expected, no problem at all.
The code we are using is like this:
<pe:inputNumber id="AmtInTxt" value="#{myController.amtField}" symbol="$ "/>
Any ideas of how can we make the context menu paste works like the control c + control v?
Community Post
Was this ever solved? For future viewers - this looks like an issue with not posting the data to the bean when using the mouse. Try putting an ajax event handler in your input field.
<pe:inputNumber ...>
<p:ajax event="blur"/>
</pe:inputNumber>
I've encountered same problem. At first I thought it happens only when using browser's autocomplete feature. From this post I've learned that it is strictly connected with just changing value via mouse. I am using <p:ajax event="blur" process="#this" /> and it doesn't change anything. More specifically, the value is empty within the InputNumberRenderer.getConvertedValue method and since then it passes null value to setter/listener.
EDIT: Also tried putting onstart="$(event.target).keypress()" within the ajax to simulate user's keypress. Sadly doesn't work.

Highlight an inputText in JSF when a validation error occurs

I have a form with a lot of inputText, what I want is to highlight those who are not being filled with correct data.
I tried to use 'component.valid' but it always return that the field is invalid (i.e. fields are always red).
this is the code :
<h:inputText value="#{creerPersonne1.nom}" id="nom"
style="#{not nom.valid ? 'border-color:red;' : 'border-color:black;'}">
<f:validateRegex pattern="^[a-zA-Z]+$"></f:validateRegex>
</h:inputText>
this is the result :
note that the field is also highlighted when the page is loaded for the first time.
You should use component.valid instead of nom.valid.
component is an implicit EL object for the current input component. And component.valid calls the isValid() method of the server side component. The id argument cannot be used this way.
So you should change your code as follows:
style="#{ component.valid ? 'border-color:black;' : 'border-color:red;'}"
(Not related but you should better use style classes instead of hard coded styles. The valid check works for the styleClass attribute as well).

JSF 2.0: Limit value of h:outputtext to a specific number of characters

I'm using an h:outputText to display a value. I would like to limit the value displayed such that when it's greater than 50 characters in length, it's truncated to 50 characters and an ellipsis is appended to the truncated value. For example:
This is some text that has been trun...
I know I can achieve this in the backing bean but I was wondering if anyone knew of any tags that can achieve this without adding code to the managed been. Seems like a common use case.
Thanks.
You can use JSF EL.. for example
<h:outputText value="#{bean.string.length() gt 50 ? bean.string.substring(0,47).concat('...') : bean.string}" />
As BalusC mentioned, OmniFace's of:abbreviate() could be a good solution for your problem:
<p>Abbreviate a long string: #{of:abbreviate(string1, 20)}</p>
Use Custom JSF Converters as explained in "JSF for nonbelievers". Here's an example of text truncation converter.

Resources