In my JSF 2.2 application, when I create JSF form, the problem is that I can put spaces in the beginning of <h:inputText>
when I insert it from my form and it will return these spaces with my value that I inserted in it. So I should handle each value with mystring.tirm()
to void the spaces. Can I use any something else to return this value without spaces? I know about converter and JavaScript, so can you give me another option to use? I don't want to use any converter and JavaScript.
相关问题
- java.lang.NullPointerException at java.io.PrintWri
- h:selectOneMenu in p:dataTable doesn't submit
- PrimeFaces block UI does not work when the compone
- primefaces orderlist not getting updated with the
- JSF2 composite cc.attrs expression does not evalua
相关文章
- CSS white-space nowrap not working
- How to allow numbers only using f:validateRegex
- JSF 2.0: ajax request when press ENTER
- Formatting a double in JSF
- Removing trailing white space only for edited line
- f:convertNumber on Double: ClassCastException
- SeamPhaseListener - Could not start transaction -
- How do I access EJB bean when inside a custom Conv
There's no magic here. You have to write code to do the job. I gather that your concern is more that you don't want to repeat the same conversion job over every single input field.
In that case, just register a converter specifically on
String.class
via theforClass
attribute of the@FacesConverter
like below.This way you don't need to declare the converter in every single input field. It will get applied transparently on every
String
model value which doesn't already have an explicit converter registered.The JavaScript way is not recommended as it runs entirely at the client side and endusers can easily disable and manipulate JavaScript. The JSF converter runs at server side and its outcome is not manipulatable by the enduser.
I thing the real problem is in somewhere else. I faced with same thing in my forms (using postgresql and JSF 2.1)
When I created a field type "char(20)". In this case i got unnecessary spaces in h:inputText.
Then I changed the field type to "character varying(20)". In this case there were no spaces in h:inputText.
Here is the explanation for that; Postgresql doc