converter

How to customize JSF conversion message 'must be a number consisting of one or more digits'?

百般思念 提交于 2019-11-28 04:12:01
问题 I have an input text that is mapped to a Long property. private Long length; <h:inputText value="#{bean.length}" /> When I enter non-digits in that input text, I get the following conversion error: myForm:myField: 'someText' must be a number consisting of one or more digits. I was wondering how to customize this message to: length must be a number greater than zero. 回答1: Either use the input component's converterMessage attribute: <h:inputText converterMessage="length must be a number greater

Convert an integer to binary without using the built-in bin function

扶醉桌前 提交于 2019-11-28 01:49:56
This function receives as a parameter an integer and should return a list representing the same value expressed in binary as a list of bits, where the first element in the list is the most significant (leftmost) bit. My function currently outputs '1011' for the number 11, I need [1,0,1,1] instead. For example, >>> convert_to_binary(11) [1,0,1,1] def trans(x): if x == 0: return [0] bit = [] while x: bit.append(x % 2) x >>= 1 return bit[::-1] Just for fun - the solution as a recursive one-liner: def tobin(x): return tobin(x/2) + [x%2] if x > 1 else [x] may I propose this: def tobin(x,s): return

JSF 2 - f:selectItems with a Date keyed Map

青春壹個敷衍的年華 提交于 2019-11-28 01:37:33
The below selectItems is fed from a Session Scoped Map. When the user clicks the Submit button, it is supposed to set a date field in the Request Scoped backing bean and display it on the page. <h:selectOneMenu value="#{dropDown.selectedDate}"> <f:selectItems value="#{mapValues.dateMap.entrySet()}" var="entry" itemLabel="#{entry.value}" itemValue="#{entry.key}" /> </h:selectOneMenu> <h:commandButton value="Submit" /> You selected Date #{dropDown.selectedDate} However, the following conversion error is received: Conversion Error setting value 'Wed Dec 26 15:09:32 EST 2012' for 'null Converter'.

Avoid extra DB reads in the getAsObject method of converter class by caching data client side?

北慕城南 提交于 2019-11-28 01:12:50
问题 I'm showing a list of suggested items in an autocomplete input element. For that I need to implement a converter to convert the entity<entityName, entityId> to entityName & vice versa. However while implementing that I realized that I had to read the DB more than 1 time to find the corresponding entityId for the chosen entityName(while getAsObject() ), I am wondering why isn't this stored somewhere client side so that the entityId could be passed when the entityname is selected. Is there any

Converting XML to JSON in Groovy

你离开我真会死。 提交于 2019-11-28 00:32:03
问题 I wish to convert xml to JSON using groovy. I understand the specifics of conversion is dependent on my preferences, but could someone please recommend which libraries and methods I should be using and provide me with a little information on why/how to use them? I am using groovy as I have been told it is a very effective parser, so I am looking for libraries that will take advantage of this Thanks! 回答1: You can do it all with basic Groovy: // Given an XML string def xml = '''<root> | <node

Bind h:selectBooleanCheckbox value to int/Integer instead of boolean/Boolean

别等时光非礼了梦想. 提交于 2019-11-27 23:44:41
问题 I have a <h:selectBooleanCheckbox value="#{someBean.prop}"> where prop is a property of type int . Is it really not working straight away? Do I have to implement a custom converter to convert Boolean to int ? Does anyone happen to have converter code for that at stock? I read that there is some bug in JSF 2.0 that prevents converters for <h:selectBooleanCheckbox> to be processed. Can anyone confirm that? I use MyFaces 2, Tomahawk and Tomcat 6. 回答1: The <h:selectBooleanCheckbox> should, as its

How to Implement a BoolToVisibilityConverter

橙三吉。 提交于 2019-11-27 23:38:01
In my app I would like to toggle the visibility of an item in a StackPanel. My Stackpanel contains an Image and a TextBlock. How would I properly use a BoolToVisibilityConverter to toggle the visibility of the TextBlock, and save this setting for the users benefit? Currently what I have is as follows, although I am getting a few errors. Important note, I need to use an ApplicationBar menu item as the click event that drives the toggling of the TextBox visibility. EDIT Error no longer occurring although the visibility of the TextBlock is not changing. XAML xmlns:common="clr-namespace:TestApp

Decimal to Hexadecimal Converter in Java

本秂侑毒 提交于 2019-11-27 22:49:23
I have a homework assignment where I need to do three-way conversion between decimal, binary and hexadecimal. The function I need help with is converting a decimal into a hexadecimal. I have nearly no understanding of hexadecimal, nonetheless how to convert a decimal into hex. I need a function that takes in an int dec and returns a String hex . Unfortunately I don't have any draft of this function, I'm completely lost. All I have is this. public static String decToHex(int dec) { String hex = ""; return hex; } Also I can't use those premade functions like Integer.toHexString() or anything, I

Displaying a number in 2 point decimal format in jsf

允我心安 提交于 2019-11-27 22:12:13
I am using JSF 2 and RichFaces 3. Here in the picture shown below, numbers are being displayed as what they are in the database. But I want to display them as 6749395.20 if fraction part is there and 5095138.00 if no fraction part is there. As of now I have tried something like this. <rich:column> <f:facet name="header"> <h:outputText value="Total Amount"/> </f:facet> <h:outputText value="#{rr[2]}"> <f:convertNumber type="number" groupingUsed="true" minFractionDigits="2" pattern="#0.00"/> </h:outputText> </rich:column> Actually I am showing all of them together, but I have tried with all of

Primefaces Picklist Converter

风格不统一 提交于 2019-11-27 21:52:21
问题 I am using Primefaces 4.0 and JSF 2.2. I used a picklist with a converter. The problem is that I don't get the correct arg2 in my converter. It always says 0 . My expectation is that this is the id of the element and I could parse it out of source/target lists. Any Ideas? My Converter is inspired by How to write a custom converter for <p:pickList>. My Picklist declaration is as follows: <p:pickList value="#{loadingPlaceGroups.pickList}" style="margin:0" var="loadingPlace" converter=