prevent multiple submission of forms in struts - struts

i am developing a application in struts 1.3 in struts i have a requirement that when click on the submit button of the form then the button gets disabled so as the user cannot submit the form multiple times for that i am using this code
<input value="Save" class="btnbg" type="submit" name="method"
onclick="this.disabled=true;" />
in this code on click of the button it gets disabled now it is getting disabled but i am facing a peculiar problem that action in the action class is not executing i am using DispatchAction class for execution of my action it code works fine if i remove onclick="this.disabled=true; the action gets executed but i am getting exception
javax.servlet.ServletException: Request[/AddFloor] does not contain handler parameter named 'method'. This may be caused by whitespace in the label text.
org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:197)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:245)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:170)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
com.asset.filter.CheckSession.doFilter(CheckSession.java:72)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
i am not understanding whats happening

Related

Is there a way to add a tooltip to the p:fileUpload "delete file button"?

I'm using PrimeFaces' p:fileUpload with attribute mode="advanced" so there are 3 buttons (Choose, Upload, Cancel) for uploading files. Below those buttons there is a field in which the chosen files appear after using the choose button. If a file with a correct data type is chosen, the file's name, size, a process bar for the upload and a button to delete the file appear.
First question: Is there a way to add a tooltip to this button?
Also, if a file with an incorrect data type is chosen, an error message appears in the field below the 3 buttons. This error message also has a button to remove the message. Neither the message itself nor its button are focusable by the tab key which makes it inaccessible for non-mouse users.
Second question: Is there a way to make the error message focusable by the tab key?
<p:fileUpload id="fileUpload"
fileUploadListener="#{ShowcaseHandler.handleFileUpload}"
mode="advanced"
multiple="true"
auto="false"
dragDropSupport="false"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" chooseButtonTitle="Test"/>
Tooltip: See https://www.primefaces.org/showcase/ui/file/upload/tooltips.xhtml for examples using PFv10. Also look at the PrimeFaces documentation for p:tooltip.
It appears tooltips were only supported natively in fileUpload from PrimeFaces v10 and I suspect from the question that you're using PF7 or earlier, in which case please see this PrimeFaces issue log for a potential workaround: https://github.com/primefaces/primefaces/issues/5831. Unfortunately the example does not cover the second delete file button that you mentioned, which is an element of a repeating row. You may need to submit an enhancement request to get this added to PrimeFaces natively.

Apex buttons in Interactive Reports break when built-in search filter used

In Apex 5.0.2. I have created a copy-to-clipboard function in my interactive report. The user can copy the value of a hidden column by clicking on this button that is set in a column and is repeating in every row (see image below).
The copy column is edited with an HTML Expression which does the following:
<button class="copytoclipboard
t-Button
t-Button--noLabel
t-Button--icon
t-Button--stretch" customid="#COPY#" type="button">
<span class="t-Icon fa fa-copy" aria-hidden="true">
</span>
</button>
My Dynamic Action with the event 'click', jQuery selector .copytoclipboard has 2 true actions. 1 sets the value of a page item (text_field) by getting the customid from that row with:
this.triggeringElement.getAttribute("customid")
The second one then copies this value to the clipboard.
This works fine and when I inspect the button element, I see the correct HTML output, with the correct value. However, as soon as I use the built-in search filter in the Interactive Report, my button breaks and clicking this button does not trigger my dynamic actions anymore, however, inspecting the element still returns the expected HTML output.
Can somebody please clarify why this is happening, and how this could be avoided?
Thank you in advance.
I found the solution. I had to put the Event Scope of the Dynamic Action to Dynamic, which is set to Static by default. Using the built-in page filter does a PPR of the report, thus when static, the event handler is longer bound to the triggering element.
Static (default) - Binds the event handler to the triggering elements
for the lifetime of the current page, but will no longer be bound if
the triggering elements are updated via Partial Page Refresh (PPR).
Dynamic - Binds the event handler to the triggering elements for the
lifetime of the current page, including any triggering elements that
are recreated via Partial Page Refresh (PPR).
Once - Binds the event
handler to the triggering elements for a once only event.

Reconnecting multiple Ajax.BeginForms when dynamically loading the forms

I have a long form made up of multiple sections, each with its own questions. Each section can be saved independently with an <input type="submit" value="Save" /> button.
Each section is loaded dynamically into the page (and there are a variable number of sections).
Each form is authored separately as an Ajax.Begin() ajax form, but with dynamic loading of the forms it appears UnobstrusiveJavaScript will not bind the submit buttons and they perform a standard postback.
What is the simplest way to reconnect the ajax functionality of the submit buttons?
After checking the source of UnobstrusiveJavaScript (which is quite small) it leaves permanent event handlers using .on('submit') so it should just work with dynamically loaded pages.
Turns out the master form was missing the inclusion of UnobstrusiveJavaScript:
#Scripts.Render("~/bundles/jqueryval")
Worth checking fiddler when this sort of thing occurs :)

Capybara and formaction

I have a simple form with a single 'email' field and two submit buttons.
The first button 'Next' triggers the forms default action: '/login'.
The second button 'Reset Password' has a 'formaction' element that redirect the form to a new destination: '/reset_password'.
<button type="submit" name="login_button">Next</button>
<button class="secondary_button" type="submit" name="reset_button" formaction="/reset_password">Reset Password</button>
The form works perfectly well, however when testing with Capybara:
click_button "Reset Password"
it triggers the form's default action and not the correct action. I've confirmed the default action is being triggered with:
save_and_show_page
It's definitely triggering the correct button but seems to be ignoring the 'formaction'.
Any ideas?
as you probably know, that's an HTML5 attribute, since Capybara uses RackTtest by default as its driver/browser (which is a very barebones, no JS support driver), it might just not be seeing it at all. I would assume you need a setup with a headless browser like PhantomJS (http://phantomjs.org/index.html). Which supports HTML5 attributes.

disabling a submit button till validation

Is there a way using dojo/dijit to disable the submit button till all the fields in a form are valid. Kind of like having a dojo > method > onChange inside the form? So the submit button only becomes enabled when all the form elements have meet their criteria?
Are you using a dijit.form.Form widget as your form? If you are, I would suggest connecting to the Form's onValidStateChange event. The docs for this event specifically state your use case:
onValidStateChange
Defined by dijit.form._FormMixin
Stub function to connect to if you want to do something (like disable/enable a submit button) when the valid state changes on the form as a whole. Deprecated. Will be removed in 2.0. Use watch("state", ...) instead.
The best way to see what events are available for a given widget is to look at the API Documentation for the widget you are interested in under the "Event Summary" heading. The dojocampus reference documentation often leaves out examples for references to some of the more obscure features of the widgets.
I would suggest to have a hidden button which will submit the form. When you click visbile button run a javascript function that validates all the input and then clicks on the hidden button to submit the form. Please find the pseudo code below
<form action="register">
<input dojoType="dijit.validation.TextBox"/>
<button onClick="validateall()">submit</button>
<button id="submitForm" type="submit" hidden="true"/>
</form>
function validateAll(){
if(AllOk){
clearErrorMessage();
dojo.byId('submitForm').click();
}else{
showErrorMessage();
}