I want to make a BasicEditField that should accept only uppercase letters, lowercase letters and numeric values. It should not accept any other symbol. Is there any style bit available for BlackBerry BasicEditField that makes it work this way? If not, is there anything else I can do?
I use these methods: TextFilter#get and BasicEditField#setFilter
mEdit = new EditField();
mEdit.setFilter(TextFilter.get(TextFilter.NUMERIC));
or
// Numeric filter that also allows minus sign.
mEdit.setFilter(TextFilter.get(TextFilter.INTEGER));
I think creating your own filter by overriding TextFilter can solve more difficult filtering task.
Perhaps it is not possible to combine them like that then, I didn't try it. Whenever I have used filters in my code I have always done it the second way I mentioned above. It is a bit more complicated but gives you a lot more control over what the field can and cannot accept. Check out the API documentation on the TextFilter class. As I said above you would just have to implement the convert and validate methods. I think in your case you wouldn't have to do anything in convert. But in the validate method you would just have to check that the character is in the range a-z A-Z or 0-9. If it is return true, otherwise return false. This will stop all unwanted characters from appearing in the field.
With a BasicEditField this is not easily implementable; however, the right solution would change the BasicEditField with AutoTextEditField. When creating the AutoTextEditField, use the constructor where you can pass in parameters. This should do it for you.
new AutoTextEditField("My label:", "initial value", 1024, 50,
TextFilter.LOWERCASE | TextFilter.NUMERIC);
mEdit.setFilter(TextFilter.get(TextFilter.NUMERIC)); works fine, also, I think, it doesnt take the minus sign, as while testing 'm not able to insert "-" minus sign in the field.
There is a constructor that allows you to specify the style of the field. You can then OR together the styles you want, like FILTER_UPPERCASE | FILTER_LOWERCASE | FILTER_NUMERIC.
Alternatively you can call setFilter and create your own subclass of TextFilter, which allows you to specify the exact behaviour you want by overwriting the convert and validate methods. Convert allows you to force certain things like automatically make all text entered uppercase etc. Validate allows you to block certain things from being entered, e.g. special characters. Check out the API for more information.
Kumar I also faced the same issue, used the below code to fix it -
The below script will allow Uppercase, Lowercase, Numeric values only.
setFilter(new TextFilter() {
public boolean validate(char c) {
return (Character.isDigit(c) || Character.isLowerCase(c) || Character.isUpperCase(c));
}
public char convert(char c, int status) {
return c;
}}
Related
I need to make a filter in certain Module and get the filtered items and loop over them and do some kind of operation.
problem is filtering isn't done , something is wrong as follows :
Filter SwTest = includes(attribute "aVerificationStrategy" ,"SwTest")
Filter Implemented = (attribute "aObjectStatus" < "inReview")
Filter SwTestReqsCASTLE = SwTest && Implemented
Module m = srs_doc
set(m, SwTestReqsCASTLE, accepted , rejected)
filtering on OR ApplyFiltering(m) , i tried each as don't know difference !
so what is wrong ?
Before I answer your main question, first allow me to answer your implied question about the difference between "filtering on" and "ApplyFiltering(m)". The difference is that "filtering on" displays the current filter in the module window, meaning that objects are either shown or hidden depending on the filter. "ApplyFiltering(m)" applies the current filter settings to the module explorer (the area to the left of your objects that shows the hierarchy). "filtering on" shows and hides objects and "ApplyFiltering(m)" reflects the status of those objects in the module explorer.
As for why your filters are not being applied, there could be several reasons:
It is good practice to turn filtering off before you start setting filters. Add the line "filtering off" before the rest of your code.
Your "Implemented" filter is not defined properly. DOORS will see "inReview" as a string, and it will perform a direct comparison with the string value of your "aObjectStatus" attribute in order to determine if an object is accepted or rejected. Is this what you intended?
What type of variable is srs_doc? If it's a string then you need to
call read(), share(), or edit() in order to actually open the
module. If it is a module variable then that line is correct.
I am assuming that "accepted" and "rejected" are integers, but if they are not previously declared then they need to be.
Based on the first paragraph in my comment, your last line should read "filtering on"
Is the module you want to filter being displayed? I realize this is probably obvious, but I have made this mistake before so I thought I should mention it. A filter cannot be applied on a module that is not currently being displayed.
As a side note, you can compound your SwTest and Implemented filters without creating extra Filter variables as follows:
Filter SwTestReqsCASTLE = includes(attribute "aVerificationStrategy", "SwTest") && (attribute "aObjectStatus" < "inReview")
I hope some of that helps! Good luck, and let me know if none of the above solves your problem.
I am having some trouble with this.. I see that we are supposed to be using the property:
predicateForSelectionOfProperty
for determining which properties get 'selected', and I'm actually kind of bummed for there not being a
predicateForEnablingProperty
because I only want phone numbers, for my use case.
That said, nothing I use for predicateForSelectionOfProperty seems to do what I want. What I want is, when I select a contact's phone number, it should call the delegate callback.. but instead, right now, it is calling them!
Maybe I'm just completely missing something, because I would actually rather just have a list of my contacts, with phone numbers, and only show the phone numbers.. maybe I'm not even heading in the right direction with this.
Thanks for any help you can offer!
If you don't want it to call the number, you should:
specify the peoplePickerDelegate; and
implement peoplePickerNavigationController:didSelectPerson:property:identifier:
don't specify a predicateForSelectionOfProperty (or if you do, make sure it returns true, e.g. NSPredicate(value: true))
Obviously, if you don't even want it to show you unrelated information about contacts, specify the displayedProperties array, e.g.
controller.displayedProperties = [NSNumber(int: kABPersonPhoneProperty)]
Alternatively, if you wanted to customize this UI further, you could just use the AddressBook.framework to extract the phone numbers from the address book and present whatever UI you want.
I have the following lambda for a simple search page using MVC:
Name and PostedName are strings.
Results.where(a=>a.Name.Contains(PostedName)).ToList();
Thanks great when PostedName has a value (excellent filter), but when it is empty, I get bupkas (empty list).
I would ideally like my where clause to be ignored when empty string.
How can this be done?
Something ideally shorthand without ifs and elses and whatifs.
Thanks!
You can dynamically add the WHERE clause. Keep in mind that you're just building an expression tree with these clauses and it's not actually executed until, in this case, you call .ToList(). So you can do something like this:
var filteredResults = Results;
if (!string.IsNullOrWhitespace(PostedName))
filteredResults = filteredResults.Where(a => a.Contains(PostedName));
filteredResults = filteredResults.ToList();
Depending on the types you may need to explicitly declare a type for filteredResults in order for that to compile.
If you want something a little more in-line, this may do the trick:
Results.Where(a => string.IsNullOrWhitespace(PostedName) || a.Contains(PostedName)).ToList();
I think it's less clear on the intent, though. The benefit of the first example is also that you can add more filters following the same structure, basically dynamically adding more WHERE clauses for other filter fields as needed.
David's answer is correct, but if you want a shortcut you can create an extension method to simplify usage example (untested by me).
I would suggest:
Results.Where(a => a.Name.Contains((PostedName ?? "").Trim())).ToList();
"ThisIsAString".Contains("") returns true.
In the case PostedName is null, it will be changed to "".
If there is leading and/or trailing blanks characters in PostedName, then they will be removed.
I am trying to localize selectOptions on the Visual Force page.
Here is the .class code snippet:
List<SelectOption> options = new List<SelectOption>();
List<MyOption__c> dropDownValues = [SELECT Id, Display_Label_Name__c FROM MyOption__c];
for (MyOption__c val : dropDownValues) {
// Display_Label_Name__c field is the label from *.labels that needs to be translated
options.add(new SelectOption(val.Id, val.Display_Label_Name__c));
}
Here is the .page code snippet:
<apex:selectList value="{!myVal}">
<apex:selectOptions value="{!options}"/>
</apex:selectList>
Right now the dropdown displays the Display_Label_Name__c verbose. I am trying to see how I can display the translated version from the .labels file. Is it possible? If not, what's the work around?
Thank you for your responses!
All localisation of page text can be done with Custom Labels.
Enable the translation workbench with the languages you require.
Create labels for all the localisible text on the page.
Replace the page text with the labels.
Add a translation for each label.
Change your profile langauge to test.
But for your case you pull the select option text from a custom object. If the values of the select list are not expected to change frequently, less than once a week or so, then I would change to using custom labels.
Otherwise, you lose the value of Salesforce automatic language selection and have to implement something yourself.
I would recommend extending the custom object MyOption__c to have columns for all the supported languages. You could use an if/else block or dynamic apex to select the select option text.
Sample using Dynamic Apex
string language = ParseForSupportedLangauges(UserInfo.getLanguage()); // includes __c
list<sobject> dropDownValues = Database.query('SELECT Id, '+language+' FROM MyOption__c');
for (sobject val : dropDownValues) {
options.add(new SelectOption(val.get('Id'), val.get(language)));
}
ParseForSupportedLangauges() would be a custom method that checks for supported languages and assigns the default when necessary.
EDIT
Turns out there is a solution: Don't look for something until you need it, right?
Introduced in Spring '12 is the ability dynamicaly select the label to display suing array syntax. Also, the ability to create visualforce components from the controller was added but using the array syntax would be sufficient for your problem. This method would allow you to select the labels you want by using the query results from MyOption__c.
Using a repeat in visualforce to loop over the query results
<apex:repeat value="{!displayResultsValues}" var="labelName">
<apex:outputText value="{!$Label[labelName]}"/>
</apex:repeat>
Here is a good article to show the usage and syntax.
I have made a custom interceptor to display the error messages in my own format. It is successful to an extent.
But i would like to know can we get label of any textfield directly from invocation object?
Thanks in advance
If your field labels are localized, then yes, you can get the label text. Otherwise, no, since they would just be a string literal in the JSP.
Assuming you have a localized property:
field.firstName = First Name
You can get that from your interceptor using:
LocalizedTextUtil.findDefaultText(
"field.firstName",
invocation.getInvocationContext().getLocale()
);
However, if you provide more details on what you are trying to do, we may be able to offer better solutions.