communicating between javascripts and struts2 action - javascript

I have the following scenarios:
User will input some value , and this values will be validated against the value from DB in the action class.
If if the value is invalid, want to show a confirm box to the user whether he still want to proceed with the invalid value.
Depend on user's answer YES or NO, which is brought back to the action class, the process of the action class will be different.
For the above scenarios, step 1 is OK.
But how do I achieve to bring the value from the action class to the javascripts and getting user's confirmation and bring back the value to the action class?

The second approach can be done by using Ajax. Struts 2 provides many ways to use Ajax:
Use the "stream" result type to send data back to your JS code.
Use the JSON plugin to get JSON back.
Consider the Struts 2 jQuery plugin.
A Google search will give you a lot of examples as how to use Ajax with Struts 2.

Related

Form element in the vueJS

I used to use PHP before and I get why forms are so common because it could literally make you submit a page and request a page from the server through a method that you would choose ( POST / GET ... ) . But when I made a transition to vue. I felt like using them wasn't the same since I already have Axios to get all the values from my APIs and I'm using an SPA so I wouldn't call an entire page from a server like PHP but just grab the components I need and modify the page according to my needs ( the page is dynamic ) I didn't get why I would use form since the action and method attributes aren't as useful as they used to be in PHP and I could just do all I need on a button with a type of button and get my info to the other components. And even if we were talking about a non-SPA app, it would use this.$router.push to get to the next page and you can even pass in the values in the link on a button click with a type of button and not type submit.
So my question to wrap it all up is how are forms used in Vue. Is it a common practice to use them ? The only thing I know is that it gives semantics.

HTML/Javascript: How to control refresh action without re-submit the form

We are trying to implement a web page that each time of page refreshing will not result in the form resubmit, how to achieve that? Is there any Javascript code or HTML can make it WITHOUT external javascript library(jquery, dojo or extJs)
The reason of such design is that the form is going to tie an unique relation to current data with means cannot do it twice but for security reason we have to use POST instead of GET, also after the action we still want to preserve user the right to do similar action on the same page to another relation. so how to avoid a consequence like that?
Thanks.
Suppose that the action to the form submits it to submit_form.php. That file can handle the data and do whatever it needs to do. Then in it's response, it can redirect the browser to a separate page (you'll have to look up the exact method of how to do this depending on what language you write your POST handler in). This separate page can show the results of the form submit using session variables or some other method.

JSF Post serialized form to JSF Method without binding value

I've got the following problem: I made a js that generates multiple hidden fields with the same name (in this case 'vak')
I want to be able to post all that data to a JSF method so I can write it to the database.
Thing is, I want to do this without binding the data to variables in the controller
in short, I have a save button that serializes a form(with js generated fields) on click
vak=0&vak=1&vak=2&vak=3
I want this to end up as an array(list) in the JSF controllers method "handleSave()"
EDIT: this can be closed. I ended up doing it the proper way by handling each change to the calendar as an ajax request and the js just be in charge of the rendering
You can get all parameter values by ExternalContext#getRequestParameterValuesMap().
String[] vak = externalContext.getRequestParameterValuesMap().get("vak");
You'll only need to write some boilerplate code yourself inside the action method in order to convert, validate and update the values (which is what JSF would basically already be Do for you when used the right way).

JavaScript: How to read browser's cache of POST data?

Effort
I've read this question, but I still think there has to be a way to do this client side.
Case
I'm submitting a form that has a few inputs. When the form is submitted, the primary key of those inputs is shown on a results page along w/ other data and a different form.
The effect I'm trying to do is if the input-pk is modified, I want it to reload the page (think window.location.reload()), only I want to update that PK parameter's value with the changed value.
window.location.reload takes one of two values (true/false), which distinguishes if it should use browser cache or not. Thus, it seems like it should be accessible, especially since the Firebug::Net plugin shows the param in the HTTP Header.
The form requires 'Post' submissions, which adds a little more complexity.
Alternative
The other thing I've considered is to store the values in a cookie right before submission, which I can retrieve on the next page and then submit another Post; however I'd like to refrain from exposing the data in Cookies.
AFAIK, Javascript does not have access to the POST body. Can't think of an API call for that! If you are using php/.net/ruby, you can encode the POST body as JSON that your JS can use when it's reloaded, can't you?

client side validation in mvc3 for dependent fields

Hi
I have an MVC3 appliocation and using client side validation and find it to be very usefull.
I am having 2 issues while using it.
-One is there any possiblity of Required filed dependency as it there for Compare
eg: If the value of a particular filed say status is="Test" then the value of other say status done field must be not blank otherwise it can be blank.
- I am having a dropdown say state .If its value is "Other" then need to make a textbox visible say "other state" .For know I am using javasript to make it visible.
I donot want to use javasript for that. Can this be performed without using javascript.
You need to write your own custom compare attribute or simply use javascript. Nothing is built in that will do this for you. The other option is to provide server side validation in your controller method where you check this situation and if it fails use ModelState.AddError to give a custom validation error.

Categories

Resources