Primefaces SelectOneMenu, selection on filter - jsf

A user of one of my applications has observed a strange behaviour of the selectOneMenu of Primefaces when using filters.
I have a mask with some fields, some of them are selectOneMenues. I deliver values via a map of Strings and use a filter on them, so the user can search for specific values, in this case currencies.
I have set a default value for this field (as the value in the object behind this field).
So, imagine the following case:
User opens the mask - default value is set on the selectOneMenues
User klicks the arrow on the field and opens the list of available values
he types in some characters and a result is returned (he finds various values with it)
when this happens, in the field, the first value from the result list is set automatically
when the user now selects a random entry, it is set and everything is fine
if the user instead decides he want's the default value back he could either click somewhere on the mask and the value is resetted -> works fine
or he could decide to click on the original value, which was set as default before, in this case the selected value doesn't change but stays the first result from the filter
when now saving the entity behind the form, the original default value is saved
I assume that this happens because when the first result from the filter is set, it just set in the frontend and not in the entity behind the form/ the backend.
Is this a known bug? Do you have any idea how to fix it with a reasonable amount of effort?
I will try to convince my customer to accept this behavior, but I think it's a bit strange, although I admit this is a scenario that's not likely to happen, often. Nevertheless, they found it =)
I am using Primefaces version 5.3.11 (elite version or something like that)

Related

Conditionally Enable Custom Converter based on a Users Input

I would like to conditionally run a custom converter. I have an XPages that handles editing and new data on the same page. The user selected a radio button to edit or create a new item.
The input fields are shared between these two functions. Upon page load I do not know what the user will do so I cannot use the "Loaded" property of the converter.
I need to format the data in this format '$900,000'. Note that there is no cents in my required format.
The built in converter for numbers or currency fails me because no matter what I do, it always add the cents. I assume that this is a bug in XPages. It doesn't matter if I say "Integer Only" or set the Maximum Fraction Digits to zero. The cents do not go away.
I have a custom converter that works fine for me, but only works when it is recalculated once, and fails when recalculated. I have tried setting the partial refresh updates to "Do not validate or update data" and this works, but breaks other parts of the page where I needs the updates to be enabled.
This application is soon to be deployed and it is too late for me to re-engineer the whole page structure to solve this issue -- too many moving parts. All I need to do to please the testers it to get rid of the cents (xxxx.00) that are added to the value, and still have everything else work.
My problem is singular, but my questions are tri-fold. How can I:
Get the built-in currency converter to remove cents the way it should? Or
Get the custom converter to be enabled ONLY based on a user-entered value? Or
Help me think of a different approach to solving this issue?
Steve, I have really fought a battle with converters as another problem is that they are all run prior to validation - and as such error messages are not necessarily shown in sequential order.
Therefore, I ended up using validators (also for the work of the converters). And on top of that I use "binding" of the components (not the values) to easily access other fields on the same page. This allows for conditional checks/logic. If you have not tried component binding, then there is a great introduction by Tim Tripcony.
/John
A couple ways to do this, One would be to do the conditionally checking of user in the custom converter. Another approach would be to use a PhaseListener and in RenderResponse Phase get the Component and set the Converter on the component to null when you don't need it on the component. I typically don't use converter though if its just the display of the number, just if I actually need the value converted. I would use something like a display Mask I've recently used a jquery plugin called maskMoney that worked well for a similar problem.
I assume your converter is on an editable field, because otherwise it won't fail on submitting data.
The problem sounds to be timing. The converter has to run during page load, in order to convert the Number value stored in the database to a String value required by the browser. So some default needs to be set, which presumably is to connect it.
If you're then wanting to change the display option based on input, you've got to do a partial refresh after the input, in order to recalculated whether cents should appear.
Once the inputted value is passed back from the browser to the underlying component tree, you can calculate accordingly - providing your converter knows what to interact with. The process dugint he partial refresh is to restore the component tree, apply the request values (store the String value from the browser into the submittedValue property of each component), process any converters or validators, then update the component tree. So when the converter runs, the radio button's value property isn't set, so it works on the last refresh's setting - the default.
By choosing "Do not validate or update data" then you're saying don't bother writing back any inputted entries from the browser into the component tree. So I'm sure you can that means the converter will know nothing about what's been input.
John's suggestion on binding is a good one, but remember you'll be needing the submittedValue property of the relevant component. For a radio button, I'm not 100% sure what that will be, but you should be able to print it out.
The mask approach may work. Someone else used that recently to make integers work right.
The other option is to look at the Extension Library's Dojo Number Validation Text Box, which has a javaType property and a more flexible set of converters. That may well allow you to avoid cents. If it does and you don't want the Dojo look and feel, it's converter should give some ideas on what your converter needs to do to remove cents.
I could not get any of the answers above to work, so I cloned the text box. I made one show up for "Edit", and one show up for "New". I kept everything the same, but only added the custom converter to the one that shows for "Edit".
Thanks again for all your help. The XPages community rocks!

why are field values being erased with an xPage full update (on another field)?

I have an xPage that is behaving very oddly. (if xPages get corrupt, I think this one might be) Tell me what you think:
I have editable fields with onChange events that take the value of the field (a company name) and looks into the database to see if the company already exists. If it does not, a field called "isNew" is set to "y". BUT the next time a Full Update is performed, from another field or button, my "isNew" field (or all of them) are erased! Why on earth would a full update erase a totally different field?
Do I need to just recreate this xPage?
============================================================================
Ok, here's the onChange event on the editable field that sets the flag:
var c = currentDocument.getItemValueString("company");
var id = #DbLookup("","AD",tc,11); // this view column gets the doc ID
if (id==null || id==""){
#SetField("isNew","y")
}
This field is being set properly - I use a computed field to display it. But the next full update (button, field, whatever) will erase the "isNew" field.
I think your problem is caused by the data sources you have on your page and how you save them.
Maybe you have data sources that gets binded from the url that should not be.
Are you using data sources within a repeat or view panel? If so, make sure you are only saving the correct data source
JSF (and thus XPages) works best when keeping MVC in mind. So you never manipulate a component, but keep that component bound to a model, like a data source or a scope. This way code doesn't get into each other's way.
A refresh of a page computes the whole tree, not just the updated field, so you need to design your calls carefully.
Work directly with your data source so do this instead of #SetField():
currentDocument.setValue("isNew", "y")

UIA - AutomationElement doesn't return correct name when list view changes

I'm trying to read the contents of a "list view" using automation. The first time I navigate to it, I'm able to go from item to item, getting the correct text for each list item. However, when I display a different screen (which is apparently reusing this display object), the text on the screen is different, but automation gets the same text as the first set. From then on I can only get the text for the first view I looked at. It's like the text is being cached and I'm only able to look at the cached view. UISpy, however, seems to grab the right values every time, and if I use it while my automation is paused, I end up getting the right values.
In my automation, I use Find to grab the header, and walk the tree to the List View and get the text for each element. I thought if you used the Current property, you got the live data. Apparently I was mistaken. How do I either refresh the tree or get the REAL data?
Yes, the Current property on a certain AutomationElement will return its current, 'live', value. UIA will not cache anything automatically, you'll have to declare it yourself and explicitly access the Cached properties.
What's probably happening is that the new tree items you're seeing after selecting a different screen, are actually re-created (and that actually makes sense, UI-wise), not just updated. You could easily determine if this is the problem by selecting the first screen and writing down the tree items' RuntimeId property (you can see it in UI Spy). Then, select the second screen and check if the RuntimeId has changed. If it has, then it's just not the same object instance.
If this is the case, all you need to do is get the items again. It'll be easier to do this using AutomationElement.FindAll with a ClassName property condition.

Problem getting value from "Checkbox group value prompt"

I've value prompt with ui:checkbox group
parameter: p_IsLastMonth
Name: Prompt_IsLastMonth
ItemCount: 1; UseValue:Yes, DisplayValue: LastMonth?
and two Date Prompts.
Whenever the checkbox is checked, the UseValue 'Yes' is passed to the parameter 'p_IsLastMonth'. But whenever the checkbox is left as it is, it results in an error.
Element 'selectOptions' is not valid for content model: 'All(style,defaultSelections,conditionalStyles,conditionalRender,XMLAttributes)'
I also tried giving a default value. But the default value has to be in the collection. But i want only one checkbox to be displayed.
I tried with html checkbox. But i'm not able to send the value 'either yes or no' to the parameter through javascript because however the finish button overrides the value.
Any help?
There are 2 ways you can use Parameters:
Evaluate Parameter value
Evaluate expression against Parameter value.
Either way your Parameter has some value, and no value is a kind of value. And you need to cater for empty value in some way. Eg:
If (?Parameter? <>'') then ([Selection Criteria] = 'True') Else (1=1)
OR
([Selection Criteria] = ?Parameter?) OR ?Parameter? = ''
There other ways of using parameters too. You should choose one that better suits situation and coding practices you are following.
You can use optional checkbox or text item. In Cognos 10 I get "Deselect" option under checkbox group.
Unfortunately, I don't think you can accomplish what you want to do with only one checkbox. The only way you can leave a value prompt unselected and still submit the prompt page is to make it "optional", which means no value will be passed. An option is to use two check boxes and make them "required" so that either "yes" or "no" must be selected (but this can result in both being selected, which isn't good), or preferably use a radio list with two values and "yes" as the default. There may be a javascript answer to this, but I try to avoid that as much as possible since it sometimes leaves you open to version upgrade issues. Using a radio list is your easiest option.
Well here is something that will work. I've done advanced scorecarding and dashboarding for years with Cognos and Javascript will work:
Create a real cognos parameter that has both choices you need Yes/No with no being the default. Put them perhaps in a html table somewhere off the main real-estate of the report/param canvas. Once you have the param configed you can make the size as small as you want and then make the table/checkbox invisible by turning the visible property to no. Basically the users won't see these params. Don't do box-type = non or the parameter won't even get generated. You could also wait on hidding them until we get step 3 working(Make it easier to troubleshoot).
Then create a HTML parameter that the user will use to interact with in the style that you want the users to see, and use javascript onchange events to manipulate the real hidden parameter by finding it via DOM model. You can make finding it easier by perhaps surrounding the hidden params with an HTML tag that has a unique name/ID and referencing the child items from there.
Since your cognos parameter is invisible you may not even need to use a check box... you could simply use a hidden text box that has stores Yes/No. This will make your coding simplified on the javascript until you get used to it.
Also When programming with javascript on Cognos i find using alert to echo a object's innerhtml to screen while troubleshooting to be very handy.
* One other less impressive approach if i remember right as well..
1. Leave your original cognos style checkbox alone and create another cognos prompt that is always defaulted to "-NO-" and hidden on the canvas.
2. In the expressions used to evaluate the parameters the would evaulate the concatenation values of both params and you could take logical action based on those values. So if the concatted results were "-No-" then you know the original paramater was not selected and to use "No". etc... I believe there could be a nuance to getting this to evaluate correctly in the expression editors but i have got this owrking before as well. * So i your case if the concatted results first 3 characters = "Yes" the "Yes" otherwise no.

Enable/disable editing of a form field from code

I'm not a Notes programmer, however, for my sins, have been working on some Notes features for an in-house project recently. I need to enable/disable editing of a field depending on circumstances. It seems to me to be a fairly standard feature, I need, but I can't find any information on how to do this anywhere.
In form setup (and other field's onchange) code, something like the following:
if some requirement = true then
textField.enable = true
else
textField.enable = false
end if
I've seen other places where there's a workaround of conditionally hiding paragraphs based on some code, having 2 paragraphs with opposite hiding conditions, one with an editable field, the other with a computed field. However, I don't know enough about Notes to see how this is implemented (I can see it done on other forms, but there seem to be some 'magic' steps within Notes which I either can't see or don't get).
[EDIT]
The reply from Kerr seems to be what I'm looking for, but I still can't find out where the InputEnabled property is located. Should have said in the initial question, I'm using Notes 7.0.3.
In fairness, it doesn't matter what the circumstances are for when to enable/disable the field, it's just some boolean condition that is set, in my case only on form loading so I don't even have to worry about this changing dynamically while the form is displayed.
I've got a few issues with Notes, my largest bugbear being that it's so tied so tightly to the Designer UI, which is utter shite. I can do this sort of thing programmatically in most GUI languages (C#, Java, Delphi, even VB), but I need to open property boxes in Notes and set them correctly.
This would be OK as an optional method, but forcing you to go this way means you can only work as well as the IDE lets you in this case, and the IDE here seems to actively work against you. You can't open multiple functions/scripts, you can't swap from one script to another without going back to the menus on the left, you can't easily search the codebase for occurrences of variables/fields (and believe me, this is a major failing for me because either Notes or the internal codebase in my case seems to make a lot of use of global variables!), you can only work with fields through the property boxes that get displayed, you can't edit code in Designer while debugging through the main Notes client.
While the Java side of the coding is better than LotusScript, it's still fairly crappy (why can't you debug INTO Java code?? Why do you need to re-import JAR files for each Java class, does each class have a different CLASSPATH???). Possibly this was improved in Notes 8, I hear it's based on Eclipse. Does anyone know whether this is true or not?
It would help to hear more specifics about the 'circumstances', but the most common way to handle this is to use a hide when formula on the field you want to enable/disable.
Technically you are not enabling or disabling the field, just hiding it, but usually that works just as well.
Since there are few events to work with in Notes, developers commonly use the document refresh as the 'event' to cause the field to hide or show.
Let's assume you have two fields called TriggerField and Subject. Say also you want to disable the Subject based on a value in the TriggerField. The easiest way to do so is to set the TriggerField as a Dialog List type and check the "Refresh fields on keyword change" option. This means when the value of the dialog list changes, the entire document will get refreshed.
Then in your hide when formula for the Subject field, you specify your criteria for when to show or hide that field. Anytime field values change, followed by a refresh of the document (i.e. form), that hide when formula will be re-evaluated.
There are other ways, depending on your circumstances, to solve this problem. If you want to let the user refresh the form themselves, put a button on the form that calls the #Command([ViewRefreshFields]) command. You can add any other formulas to that button before the refresh command if you want to make other changes to the form at the same time.
Another option is to make a certain field display-only. Then create a button that runs LotusScript to allow users to change that display-only field. In the script you can propmt the user for a value, set the display-only field, and then call for a document refresh.
In ND7 and up if you want to just disable the field for input, write an appropriate formula in the InputEnabled section of the field you want to disable.
So I have two fields one called Trigger, a checkbox with the value "On" and another Subject that is a text field. When Trigger is checked I want the value Subject to be enabled.
I simply put the following formula in the Input Enabled element of the field Subject:
Trigger = "On"
I also want this to be recalculated whenever the value of Trigger changes so I select the "Refresh fields on keyword change" option on the Trigger field.
If you're stuck in an older version you need to to hide paragraphs appropriately.

Resources