I have a j2ee application running on weblogic. I was confused with my multibox.
What I know of multibox is that the checked items will be passed as an array of strings on submit.
I don`t know why in my application it works fine when i uncheck a checkbox or more, as long as a single box remains checked but when I uncheck everything, the submitted array is the array of the previously checked multiboxes when it was supposed to be empty.
Can you help me please?
Are you familiar with the reset() method on the ActionForm class?
The purpose in life for this method is to reset checkboxes. If you have a checked checkbox in your form and you submit it, that checkbox will be on the request. If the checkbox is unchecked nothing will be sent on the request for it (a GET submit is a simple way to observe this behavior).
When Struts performs the request bind, it matches by name the parameters from the request to the parameters in the form. That is, if there is something to match.
Now consider these steps:
I have a boolean field on the ActionForm;
I also have a matching checkbox in the form;
I submit the form => Struts binds the request, so now my property is true in the ActionForm;
I uncheck the checkbox in the form and submit again => nothing is sent on the request for the checkbox => Struts has nothing to bind = > your field remains true on the ActionForm;
The above applies for multi checkboxes, but you get an array instead of just one value.
Enter the reset() method. This is called by Struts before binding the request. Here you can set your field value to false. If it arrives in the request Struts will replace it with true => OK. If it does not arrive on the request (because it's unchecked) the value will remain false = > OK again.
The same goes for multiboxes. You have to reset the list of values from the ActionForm by reducing the array to zero length (but not null).
If your ActionForm has a request scope, it usualy does not matter because the object is recreated at each request. But for a session scoped ActionForm with checkboxes, reset() is a must.
Related
I am trying to verify a page based on who logs in. Certain users have more security and will see more items on the page. When a user with lower security logs in, they will not see options. I need to verify those options are not present on the page.
I have a page object for the option that displays based on user security
testObject {$("#test")}
I have tried using isDisplayed()
boolean hidden = testObject.isDisplayed()
assert !hidden
But I keep getting an error that says
geb.error.RequiredPageContentNotPresent: The required page content
geb.navigator.EmptyNavigator' is not present
The error message is what I want to verify. The object is not present, and I need to verify that is true and pass the test.
You want to use the required option for your content element.
If the page is dynamic, maybe you also want to wait for a while before you let Geb decide that the element is empty. Checks for non-existence of elements can be tricky, because they could just pass because a dynamic element has not finished loading yet.
testObject(required: false, wait: 2) { $("#test") }
In your Geb test you just do this (no helper method needed):
given:
def page = to MyPage
expect:
page.testObject.empty
I'm using a CMultiFileUpload control in one of my forms like this:
$this->widget('CMultiFileUpload', array(
'name' => 'neueAnhaenge',
));
When input validation for some other form element fails and the input form is rendered again, a previous selection in this control is gone (as expected).
How do I repopulate this control, what do I have to do in my controller, is there a way to prepopulate this?
Thanks in advance.
For file fields it is rather impossible to reset the values assigned to it after it has been sent to the server.
One way to solve this would be to get the uploaded files, store them temporarily on the server and modify the form so it sends a reference to the file on the server.
A much better way would be to use Ajax or Client side validation of form fields to ensure no validation error occures when form has been sent. You can enable these options for CActiveForm: $enableClientValidation and $enableAjaxValidation.
I have a very simple issue. Below is my JSP code , where I display multiple check boxes in rows. By default all checkbox are checked, and if user wants to ignore certain row, he unchecks that row's checkbox.
My issue is, if a row's checkbox is unchecked and because of some other fields, if Struts throws a form validation error on screen, the unselected checkbox is displaying back as checked. Am I missing something? If no struts validtion, then everything looks correct.
<c:forEach var="map" items="${form.displayList}" varStatus="index">
<html-el:checkbox styleId="someCheckbox_${index.index}" property="someCheckboxes[${index.index}]" />
<td> .....</td>
<td> .....</td>
<td> .....</td>
</c:forEach>
When you submit data to Struts the following things happen:
Struts has a front controller and all request are going through this controller. This is the ActionServlet class which then based on what was configured in struts-config.xml passes the request to the appropriate Action class.
before that happens, an ActionForm instance is constructed or reused if it's a session saved form;
reset() is called on the ActionForm. This is where you reset checkbox properties to false. This is needed because unchecked HTML checkboxes are not sent on the request when you submit, so Struts does no request data binding for them (if they were checked when you loaded the page they remain checked even if the user unchecked them on submit);
the ActionForm is populated with the request data (any checked checkboxes are now checked, the ones who were not sent on the submit remain unchecked because of the previous reset);
the ActionForm's validate() method is called if so specified in struts-config.xml;
if validation fails, the control is returned to the input JSP if so specified in struts-config.xml (the submitted data is what the page will display because it's on the ActionForm);
if instead validation is successful, the execute() method on the Action class is called;
Action class does it's job and forwards to some JSP.
Is this how you are using Struts? My guess is you are doing some populating/resetting/validations in the Action class and when validation fails you reload the ActionForm with the default data.
Check your ActionForm for the reset() and validate() code and your Action class for execute() and see where the data is getting checked back.
I have JQGrid loading data from WCF OperationContract with paging and sorting working fine. I am using "multiselect: true" so that I get the checkbox column and ability to select multiple rows. I've implemented gridComplete:, onSelectAll: and onSelectRow: to capture when checkboxes are checked/unchecked and to maintain checked state upon pagination. I am able to save the checkbox state to the DB via another WCF method call.
What I cannot figure out how to do is load the saved checkbox state for each row along with the other fields specified in colModel:.
Any ideas? I realize I can make a separate WCF service call to get the values, loop through them and set state manually, but that seems like a huge waste and overly clunky.
Thanks in advance.
The simplest way, which I imagine me immediately after reading of your question, is to have additional hidden column (hidden: true property in the colModel for the column) and the checkboxes inside. You can load the selection state from the database an fill the hidden checkboxes. Inside of loadComplete or gridComplete you can use the information to select the rows.
If you would use loadComplete instead of gridComplete you can even eliminate the need to hold hidden row. The callback method loadComplete has data parameter which are initialized with the data originated from the ajax call. So if your server response contain more information as jqGrid need the data will be ignored by jqGrid, but you can see the data in the loadComplete and use the information to set row selection.
I'm using MonoRail and was wondering how it decides when to use client-side vs. server-side validation? In my model class I have [ValidateNonEmpty] on two properties, one is a textbox, the other is a dropdown. The textbox triggers client-side validation on form submission, if I leave the dropdown empty though it posts back to the server and returns back the validation error from server-side. Is there a way to get the dropdown to trigger client-side validation? Also it's odd because after the postback, it clears what I had entered in the dropdown but maintains the state of the textbox (viewstate anyone??)
Thanks,
Justin
It viewed source and I saw that it was using jQuery for the client-side validation. It had:
"business.businesstype.id":{ required: "This is a required field" },
for the dropdown, which wasn't working. I noticed that it was using 0 as the default dropdown value so I manually put in firstoptionvalue and that got it working:
$FormHelper.Select("business.businesstype.parent.id", $businessTypes, "%{value='id', text='name', firstoption='Select a Business Type', firstoptionvalue=''}")