I have some page in JSF2.0 where I need to validate fields. This is cross-field validation, so I binded fields to UIComponents. All three fields are <h:inputText> so all are binded to HtmlInputText.
Validation method just reads values from all the HtmlInputTexts. It works pretty well when I run the app and use it by hand. Problem is it doesn't work when selenium inputs values. Part of selenium code is:
selenium.type("identifier=myForm:myTextField", "someText");
So it inputs text into the text field. It works and I can see text is really there. But when I debug validation method, which reads values from UIComponents, the value is null after clicking "Submit". It is not null when entered by hand, only when selenium enters it.
Why is that? Why selenium doesn't work? It does pretty the same I do by hand, yet it works by hand, doesn't work by selenium.
Note that JSF-generated IDs are usually not the ID you have assigned. For example myTextField in a form called myForm will have an ID myForm:myTextField
As JSF takes charge of ID's I prefer setting an 'unique id' in the styleClass attribute which is rendered as class. Then you select the input with that class.
You may have more than the 'unique id' on an element. Then I prefer to search for an element with a class that contains the 'unique id'. It lets you change styling without changing the test.
Related
A large form has several input fields so that they are grouped inside primefaces tabview tabs. Some of these fields are mandatory. When the user tries to submit, it gets the required message, but the user has to scroll through all the tabes to locate the fields missing fields. Is there any way to highlight tabs with missing values?
I would personally do this client-side.
I'd start with checking IF a validation failed in general or not like in the PrimeFaces solution in here:
How to find indication of a Validation error (required="true") while doing ajax command
In the javascript function that you can call, I'd find the surrounding form via jquery.
jQuery find parent form
And from that form down I'd find via jquery all inputs with a css class that indicate an error.
jquery find element by specific class when element has multiple classes
From each error I'd find the ancestor element that is the tab of the div (this might be where you need to be most creative, but it IS all plain jquery with wich many can help you if you make it a plain jquery question) and add a css class to this so you can style it 'in error'.
I'd find, again with jquery, the first tab that has errors and 'fake' a click on it.
find first occurrence of class in div
Simulate a click on 'a' element using javascript/jquery
You can do server-side validation. So if a validation error occurred you know the tab that the error is locate.
Then you can use the activetabindex of TabView and activate the tab that you want.
Then you can use Spotlite as #fuggerjak61 said to locate the missing/not valid fields.
I am submitting a form in prime faces with two text fields which are read only. I am setting value in them using JavaScript. But when I submit the form then in manage bean value of both text filed is null. If I however, remove read only, then it works fine. Please tell me the way out?
I am trying to check my check box in Geb.
I have tried following codes, but no luck
$('input', type:'checkbox', id: 'chkTermsConditions', tabindex: '-1').value('true')
$(".CheckBoxUI").value('true')
Following is the HTML
After mouse go over the check box additional text updated (marked in the screen shot)
You are attempting to check the box which has the attribute with value='true'
From the Geb manual:
The value of input, select and textarea elements can be retrieved and set with the value method. Calling value() with no arguments will return the String value of the first element in the Navigator. Calling value(value) will set the current value of all elements in the Navigator. The argument can be of any type and will be coerced to a String if necessary. The exceptions are that when setting a checkbox value the method expects a boolean (or, an existing checkbox value) and when setting a multiple select the method expects an array or Collection of values.
Try this:
$("#chkTermsConditions").value(true)
If you are using non standard HTML generated by some other platform. You may have to resort to clicking the element or using javascript.
The element that produces the desired click result could be one of the surrounding elements. If the widget is javascript controlled you may have to call a function that is embedded into the page for that widget. If its a javascript widget I cannot help you unless you can point me to a page which uses the same platform.
Try:
$('a[class=CheckRadioFocus]').click()
$('a[id=termLink]').click()
or any of the other surrounding elements.
I managed to check the check box with $(".CheckBoxStyle").click()
Only issue is still Submit button doesn't get enable. Following is the html code for before and after checking the check box in real situation.
I tried the to click on the submit button with following code. It doesn't give any error. But still doesn't move to next page as expected.May be because of Submit button disable issue.
$("#submitBtnMsg").click()
Edited :
It was turned out above was application related issue. We have to click on the address after selecting via address validation service. Then only Submit button get enable.
$(".RedColor").click()
I have a radio button group that gets it's values using an #Dblookup. In addition to the name to appear in the radio button group, the document also has a field to determine if another field on the xPage should be displayed or not.
If the field is displayed then it should be required.
I can do the conditional validation just fine in SSJS using an #DbLookup to lookup the document selected in the radio button group.
But I would like to be able to do it CS so it is faster and so it looks like my other validations. Is there anyway to do this?
If a field is not rendered then the node will not exist in the DOM. Your CS javascript would need to examine the DOM and look for the node, normally by looking for a specific ID. As Xpages changes the ID's sent to the browser your validation function would either need to be computed so it would know what ID to look for or you would need to look for it in some other unique way ( like add a css class name to just that field and then do a DOM search for nodes with that class name )
Once you can determine if the field has been rendered then you can run your usual CS validation routine against the other field.
If you're using client-side validation throughout your app, setting the required property on the field should achieve what you need.
If not, it may be worth looking at the Extension Library Dojo Validation Text Box. All the Extension Library Dojo control run client-side validation, even if validation is set as server-side at application level. Bear in mind that for the Dojo Validation Text Box, just setting the required property is not enough. You need to add more specific validation.
After that, the key is to ensure the partial refresh event on your radio group is set to skip validation. I haven't tried, but I believe that should achieve what you need.
I have a form which one of it's fields is a code and description, also a button for opening a popup window that contains a list of all of the available codes.
when the user double clickes a row from that table i want to set these values to the code and description. - how can this be done?
Another question, I want to create this popup and table to be initialized dynamically - by that i mean that if i have a few forms in my application, when ever i have a field which has a description i want to be able to open this popup and to see the available list for that field. (every field can be from a diffrent table). is it possible to create something like that? if so, how?
Any help will be appritiated,
Thank's In Advance.
Yes, it is possible. Even more, many component libraries have ready to use popup/dialog components, such as RichFaces with <rich:popupPanel> and PrimeFaces with <p:dialog>.
If you do not want to use a component library for some reason, you would need to create a custom component for this which generates basically an absolutely positioned HTML <div> element with a CSS overlay which get shown/hidden by JS on a particular click/action. The HTML/CSS/JS part should be relatively simple if you are familiar with those languages. The JSF part is somewhat hard if you have never created a custom component before, but it should be possible with a composite component as well, so you could also just create one with pure XHTML. The updating/refreshing can just take place by the usual <f:ajax> means.