Action object Form Object Command Object - forms

Can someone explain in the context of a Web application what do these mean? I am reading up on Spring MVC reference and see these terms thrown around.

These are referring to a bean that is the the target for the data in the form fields. I.e if you have a Person bean with username, address, email etc etc then you might have a registration.jsp with a form that your users enter all these various details, with an attribute path set in the form tag, e.g. path="username" etc. Once they post the form all the information that they have entered will be matched up from the path attributes and mapped to the corresponding appropriate fields in your Person class.
Example jsp:
<form:form ... commandName="person">
<input type="text" ... path="username">
Person class
Private String username;
Spring docs here: http://docs.spring.io/autorepo/docs/spring/3.2.x/spring-framework-reference/html/view.html

Related

How can i save the campaign name from responsys on a form

I'm trying to get the name of the campaign where the person opened the form and save it in the supplemental table of the form.
I saw that it has the campaignname() function but I didn't know how to use it.
the form call in the body of the email:
$personalizedform('test_form', 'EMAIL_ADDRESS_',concat(CAMPAIGN_NAME=campaignname()))$
and the hidden field in the form:
<input type="hidden" name="CAMPAIGN_NAME" value="$CAMPAIGN_NAME$">
i managed to figure out how to do this and it was really dumb of me not to notice it but i can just use campaign.name in the form call
Based on what the limited information, I'd think that you'd want to write your form input to a supplemental table using the form rules, and have the input name/id match a column in your supplemental table.
The freemarker/RPL code to pass campaign name to a form would look something like this: ${form('test_form','EMAIL_ADDRESS_','CAMPAIGN_NAME='+campaign.name())}
Sources:
Responsys Form Method
Responsys Namespace Reference

ASP.NET MVC4 - validation based on model generated by entityFramework of multiple forms

in my very first asp.net mvc4 project,i'm trying to apply some validation tests on my four forms in the same page.Each form allows me to create a different type of project in my table(dataBase),so i'm using the same model generated by entity framework and for validation i used a partial class having the same name of my generated model and i've inserted data annotation such as required with error messages.My problem is when i submit one form leaving a required field empty,the appropriate validation error message is shown for all my forms and not only the one i submitted.Please can someone tell me how can i solve this problem?
If you have a RequiredAttribute on (say) property Name and its null on postback, a validation error is added for that property. If you inspect the html generated for the form, you will see something like this (assuming your using #Html.ValidationMessageFor(m => m.Name)) which acts as a placeholder for any validation error message associated with Name
<span class="field-validation-valid" data-valmsg-for="Name" data-valmsg-replace="true"></span>
Note the ..data-valmsg-for="Name"... Since your rendering 4 identical forms using the same model which generates 4 inputs for property Name, there will be 4 corresponding validation errors.
Your approach in rendering 4 identical forms does not make sense since you can only post one back. I suggest you consider using a view model that includes a property for ProjectType and render a DropDownList so the user can select the project type. Then only one form is required, and when submitting, get the selected ProjectType and use this to make whatever decisions you need to save the data.
Just structure your View in this way :-
#using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { #Id = "Form1" }))
{
..........
..........
<button type="submit">Update this stuff</button>
}
#using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { #Id = "Form2" }))
{
..........
..........
<button type="submit">Update this stuff</button>
}
In above example when you submit "Form1" model validations associated with "Form1" will fire and same case for "Form2".

ZF2 form not binding properly to Doctrine entity

I'm trying to switch over from building forms with annotations to just writing them myself. I have an entity and a form that you can see here.
The code in my controller is pretty straightforward: get an instance of the user form and an empty user entity, bind the entity to the form, validate, blah blah blah.
For the most part, this is working. When I dump the user entity after validating the form, the first name, last name, and email address are all filled with the correct values. The sex, however, is still null. Yet when I check the post data, the value for sex is in there.
Is there something I'm missing in either my form or my entity? I have a getSex method in my user entity. Just for kicks and giggles, I even tried echoing output from all of the setters to see what was going on. When the form was validated, I could see the output from all the setters, except for getSex.
OK, I figured out what happened. For the binding to work properly, the form has to have an input filter for each item; anything without one gets ignored. Once I added an input filter to the sex element, everything was just fine.

Can a lift form accept attributes for multiple models?

In Rails I can use accepts_nested_attributes_for to allow a single form to create two different but related objects. Now, I'm working on a Scala Lift project and I want to do something similar. I have a User model and an Address model. I want to have a single form that creates the User and their Address. How does this work in Lift?
In general, Lift approaches form processing by binding a handler function to each input which is called on form submission. In each of those functions, you would define the logic you need to set the appropriate fields in your model.
Using something like the example below you can instantiate your classes and then perform the appropriate action on submission. You will see this creates a User and an Address class and then sets a field on each of them. The function bound to the submit button will take care of persisting them both. Since the actions happen in a function, you can include as much logic as necessary to make your application work (data transformation, setting multiple fields, etc...). For example, in the submit logic I associate the id of the Address with the User to define how they are related.
In your Snippet
val user = new User()
val address = new Address()
".nameField" #> SHtml.input(user.name, (txt) => {
user.name = txt
}) &
".addressField" #> SHtml.input(address.address1, (txt) => {
address.address1 = txt
}) &
".submit" #> SHtml.submit("Save", () => {
//persist address
user.addressId = address.id
//persist user
})
In your HTML
<form data-lift="form">
<input class="nameField"></input>
<input type="submit" class="submit"></input>
</form>
In general, that is how you would accomplish what you are looking to do. In addition to handling everything yourself, Lift includes Mapper which is pretty much a database ORM. I believe that can automate a lot of the relation mapping and make the creation of some forms easier. I don't really use it myself, so I can't give you a more concrete example. But, if you decide to check that out, you can find more information on Mapper here and here.

Set request parameter in Orbeon

I am very new to Orbeon and XForms.
I have created a form with input field "BaseId"
<xf:input id="control-3-control" bind="control-3-bind">
<xf:label ref="$form-resources/control-3/label"/>
<xf:hint ref="$form-resources/control-3/hint"/>
<xf:help ref="$form-resources/control-3/help"/>
<xf:alert ref="$fr-resources/detail/labels/alert"/>
</xf:input>
and i want when i summit this form, in crud.xpl
method PUT i cant get value of BaseId through
<sql:param type="xs:string" select="/request/baseid"/>
Help me,please
Sorry for my bad English
The value of controls are passed to the persistence layer REST API in an XML document, as the body of the HTTP request. So in crud.xpl (say the one for eXist), this will be a document under /request/body. The exact path depends on your section and control name. For instance, if the section is named address and the field city, the value will be under /request/body/form/address/city.