JSF Post serialized form to JSF Method without binding value - javascript

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).

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.

Populating form components from database using innerHTML

I need to populate form components(either select,checkbox) from database. The fields of the form depend on each other, i.e I need to populate a component based on user selection on the previous component. To do that, I am using onchange method, from which I raise a AJAX request for the data that need to populate the next tag. Right now, I am returning the string(HTML data) from the controller in backend and setting the corresponding id's innerHTML to these string. I am curious, whether the approach is correct way or should I take the json as the output from AJAX call and generate the HTML in js and then set the innerHTML value to the corresponding id. I am using JSP as View.
i think building the json and building up the components in the page side is safer becuse it makes your business login separate from the view. If it is required to construct a dynamic table without a POJO then there is no other go you have to use the html string data as the output of ajax

communicating between javascripts and struts2 action

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.

How do you call a Django view with parameters from JavaScript?

I'm looking to capture and save the state of a page (Django template + backend) after the user makes some modifications (through JQuery) to the appearance of the page. Now that I've gotten hold of the innerHTML using a JS variable, I need to send it over to the Django view that will do the saving. How do I call this Django view and pass it the JS variable?
P.S: First ever question on stackoverflow, please let me know if the question isn't clear or is improperly formatted.
Handiest way to get started is to first make a proper form and a django view that reacts to it ("request.post"). The form should have fields for whatever you're changing in the page.
Next up, submit that form's variables from your page with jquery.ajax.
So the idea is to isolate the various problems:
What should be the form parameters?
Get a view running that makes the actual changes.
Get the javascript working.

Sending parameters with the autogenerated post submit/create button in MVC 3 razor

I read online about how to send a variable from javascript with ajax but I am not sure that solution fit my needs.
What I am trying to do is this:
I have an automated form for creating a row at my DB.
What I Want to do is run a javascript code that will create a variable with logic based on the user input and than send this variable along with all the other fields that are automatically being sent because of the automated creation and binding of the model.
Basically what I want is to add another array to the automated post call that I didn't wrote because it is being generated automatically by mvc. and than I can retrieve this variable (array at my case) at the create method on the controller
Do you have a solution for this?
Thank you very much
You could add some hidden fields to the form and use Javascript to fill their values in the submit event.

Categories

Resources