Submitting form elements in a JQuery Datatable to a servlet - java

There are check-boxes in a jquery datatable. I want to submit them to a servlet by using submit button. I have defined form tags inside the table but still after formatting all the hidden type elements are passed and checkboxes in the table are not passed to the servlet. It shows null for check-box name reference.
Could anybody please help me to pass those values to java servlet.

It seems the DataTable plugin does not use <input> tags for checkboxes. Have a look at this example in the documentation:
https://datatables.net/extensions/select/examples/initialisation/checkbox.html
It says there:
The checkbox is not an element, but rather a
CSS that uses the :before and :after pseudo elements of the cell to
draw a box and the tick.
So first make sure you understand what elements there really are in your table. Use your browser's "Inspect" tool.
Then, if you are sure what elements are there and if there are really checkboxes, be aware that your servlet will not receive a value of a checkbox that is unchecked. This is very unlucky, but it is the specification:
https://www.w3.org/TR/html401/interact/forms.html#checkbox
Therefore, your servlet must internally initialize its final checkbox value with false. Only it receives a value from the checkbox, the final checkbox value will become true. So it might be the right thing that you receive null - then the checkbox was simply not checked.

Related

Is there a way to retrieve the tab order of HTML elements in Java?

Right now we have an element on the page that is not allowing users to tab out of it. The element was created in Java as a GWT component, I don't really know too much about GWT so I can't really describe it further.
Anyways, I know where I need to tell the component to tab to the next element in the tab order, but I don't know what commands to use to do so. Is there a way to retrieve the tab order of HTML elements in Java? If there is, I can just pick the next element in the list and set it to be focussed.
Using GWT com.google.gwt.dom.client.Element you can access and set the tabIndex value of any GWT component (i.e. html element). If you're using a Widget class you can use myWidget.getElement().getTabIndex() and setTabIndex(1).
In HTML you cannot just pick the next element with the tab out of the box, you can however maintain the tab indexes order in the order you expect.

How to retrieve value from database on selecting value from dropdown using Ajax?

I have a java servlet application where the database is populated by selecting an entry from a dropdown list and entering the values. On another page I have the same dropdown list and also have a find button to display the values that were previously entered by selecting an entry from the dropdown list. I want to get rid of this find button and dynamically display the previously entered values on this page. I heard this can be done using ajax. Please help me out.
Since the code is too much to share I have uploaded the snapshots of both the pages.
https://www.dropbox.com/s/10qmpxzwm8sik8a/1.PNG?dl=0
Here I am entering the values in estimate by selecting the project
https://www.dropbox.com/s/w8macftnm3rez3a/2.PNG?dl=0
Here I want to get the values just by selecting the project from the drop-down without clicking the Find button
You need to be specific with your question.
If I got you right...
You can use a variable in javasceipt to hold the value that was enterd on the other page you got.
Then while using the dropdown on the other page you can retrieve the values that you store and use a simple ajax request with json data to your servelet.
Check here for examples: http://api.jquery.com/jquery.ajax/

How to verify if Tab on Web Page is selected using Selenium RC..?

How to verify if Tab on Web Page is selected using Selenium RC
I wanted to one very simple thing. Does anyone know using selenium RC Python Client how I can know if a Tab is selected on web page?
By tab I mean the following examples from the following link-
http://esdi.excelsystems.com/wsexmp/DIVTAB.pgm?wsnum=00096
I have used focus(), isSomethingSelected(), isVisible() but didn't get the solution.
I need to verify that the specific tab is selected by default after webpage opens. Isn't there a method like is_tab_selected(tab_locator)??
please provide the clear solution pls..
I have used focus(), isSomethingSelected(), isVisible() but didn't get
the solution.
These methods use the common HTML element terminology.
focus() is for elements that are focused, meant as when you click a focusable element, it has a focus on it. To see what I mean, you can loop through the focusable elements on your page via pressing the Tab key repeatedly. This changes focus.
is_something_selected() is for selecatble <option> elements (which are the children of a <select> element)
is_visible() tells you whether an element is actually visible on the page or whether it is hidden via CSS.
Anyway, there's no is_tab_selected(tab_locator) method, because there's no such thing as a tab. In your case, your "tabs" are just simple clickable <a> elements which have a class attribute tab-active or tab-disabled based on their state.
Therefore, if you wanted, for example, to know whether the second tab is active, you would do
is_element_present("css=#tab2.tab-active")
This will return either true or false based on whether the tab is selected or not.
Or the other way around, if you wanted to know which tab is currently active, you would do:
get_attribute("css=.tab-active#id")
This will return the id of the selected tab.
You have to find a unique tag in your webpage. You can do
driver.findElement(By.xpath(".//tagname"))
If the above line doesn't throw any exception, you can confirm that you are located in your webpage.

How do I prevent STRUTS from persisting selections?

I am using JAVA STRUTS. I have an html form with an ActionForm class associated with it and the controls are created using tags. As I understand it, STRUTS will persist selections on an html form even if the form is refreshed. I need to prevent this behavior and force it to rebind the values from the ActionForm object.
Basically, I have a form with a radio button group that allows the user to select A, B, or C. I have an ActionForm that has the property "selection = A" set when the form is loaded. If the user selects B and submits it, the form is correctly set to "selection = B" and all is good. However, when I refresh the page, the ActionForm gets reset to "selection = A" (confirmed through debugging), but the radio buttons have B selected!
Does anyone know why this is or how I can prevent it from happening?
Regarding to your post i thought it was belongs to struts2 so,
According to struts2 it is not possible means, you have to give the static value or you have to make in programmatic manner through JPA (or)your java code.
For JPA you refer this link it is helpful JPA way
This explanation is refer to static way
First in jsp page you have to import struts2 tags through taglib uri then it shows the available struts2 tags in those tags you have to select <s:radio></s:radio> tag
eg:
<s:radio label="Selections" name="your name" list="#{'A':'A','B':'B'}" value="2" />
in this code i typed the value as 2 so, it select B as a default if you remove the value it won't select any default values.
Basically what i am trying to say here is without value it won't select any radio buttons
you have to give value through static way or dynamic way.
For dynamic way you can refer this link dynamic radio button

struts 2 <if>tag for selecting checkbox

I want to implement some functionality--there are multiple rows with a checkbox at the starting in a jsp file in struts2.1 framework. If the checkbox is checked then at the same instant the color of that row should change, like it is selected. How should I implement this?
I recommend the jQuery plugin – tableRowCheckboxToggle (demo)
I agree with lschin; use a canned solution.
That said, you could also do it "manually" using jQuery or similar. Attach an onclick handler to each checkbox that sets a CSS style on its containing row.
Simplistically, use the checkbox's onclick attribute to provide a click handler and an ID that can be used to find the containing row.
Less obtrusively (and arguably better all around), find the row containing the checkbox by walking up the DOM (in jQuery, something like inside the attached click handler: $(this).parents("tr")[0]) and don't worry about throwing around a lot of IDs.

Categories