Struts2 Form Fields are submitted as request attributes in action - struts2

Why Form fields for a model drive Struts2 action are added as request attributes? I am able to retrieve them both as request.getAttribute and request.getParameter in my action.

Related

How to make a symfony form with ajax added fields and DTO?

In my view, I have a form that'll allow users to build their own car models. I have a field to choose car-parts and another field to add a color for it. For example, a user can choose "tire"=>"yellow". And there's a button to add new entries to the form.
For generating a form in the controller, I have read many articles on not to bind the entity directly to the form, instead use a DTO (data transfer object) to take care of the validation on the $request first. After a success validation may then have the DTO data pass to the entities.
On submit, my form is going to pass field names like "model_name", "part01", "color01", "part02", "color02" to the controller. From the symfony documentation it shows you how to make it works with the use of the "allow_add" option in the form builder. But here's the problem, that was based on the assumption that you're binding your form with the entities, but how about DTO? How do I put all those data into a DTO and tie it to the form and still able to do the validation?

How to retrieve data-attr value of input?

I set a data-id="2" attribute on a HTML input tag. For example: <input data-id="2" value="test"/>. How do I retrieve this value in my action? I'm using dynamic text inputs where they can be sub inputs themselves.
The action can only access data which has been submitted to it (using POST or GET). If you want to be able to access the id, you'll need to grab that value using Javascript and send it with the other form data when the form is submitted.

How can I make a form the does not send empty parameters in MVC?

I'm using ASP.net MVC5 and I have just created a simple search form. Upon submitting, the controller is called with GET parameters.
The thing is that all parameters are sent regardless if the user has filled it resulting in an ugly & bigger URL that is needed.
So, what needs to be done in order that the form won't send null/empty fields?

Signal event completion asynchrounously after a POST request to a view page

I have a ASP.NET MVC application which has a view populated with a model which needs to retrieve some data from the user. Besides that, I also have a hidden div tag which contains more information but it should be visible only after the model was sent to the controller on a POST request and after it has processed the information from the model it should change the div tag to visible. Is some way to signal the view that the request was processed and render visible the div tag, remaining on the same page. I believe this is similar to a partial postback from ASP.NET.
Thanks,
Tamash
Yes that's possible via some AJAX functionality. I'm using jQuery in my example:
$.post('Controller/Action', $('#formId').serialize(), function() {
$('#yourDiv').show();
});
This uses jQuery to post the data contained in a form with the HTML id 'formId' to a URL 'Contoller/Action' and shows the div with id 'yourDiv' in case the AJAX request finished successfully. The call $('#formId').serialize encodes the form elements in HTML form with id formId for submission in the AJAX request.
More on jQuery and AJAX here

working with multiple forms in same action class in Struts2

How do we populate\retrieve information from\into multiple forms in same action class in Struts2 ? With ModelDriven approach, action is tied to one form. With ScopedModelDriven interceptor jsp becomes dirty as one has to write model.property to access form properties. Is there a better way of doing it?

Resources