Spring Tags Form Input - forms

i have some probelm in spring tag form input..
if i use <form:input>..there will be error displayed
java.io.IOException: JspException when evaluating the body but if i used html tag, it's can't connect to database.
<form:form method="POST" action="/sampling/insert"
modelAttribute="sampling">
<div class="form-row control-group row-fluid">
<label class="control-label span3" name="populasi" for="normal-field">Population</label>
<div class="controls span9">
<form:input path="populasi" type="text" id="normal-field"
class="row-fluid" />
</div>
</div>
<div class="form-row control-group row-fluid">
<label class="control-label span3" for="normal-field">Error
Rate</label>
<div class="controls span9">
<form:input path="tKesalahan" name="tKesalahan" type="text"
id="normal-field" class="row-fluid" />
</div>
</div>
<input type="submit" class="btn btn-success" rel="tooltip"
data-placement="top" value="Submit" />
</form:form>

Try this:
name, type are not valid attributes
change the tag attributes:
<form:input path="tKesalahan" id="normal-field" cssClass="row-fluid" />
Reference: spring input tag attributes

Related

How to set a Razor Html.BeginForm within another Html.BeginForm

Description
I want to have two buttons to edit and delete an identity role. The edit button works but if I want to delete a role the site is reloading but nothing happens.
The post function will not be called. Is there another way to have a post form in another post form?
Code
<div class="row mb-3">
<div class="col-12">
<div class="card">
<div class="card-body">
<h4 class="card-title">Rollennamen bearbeiten</h4>
#using(Html.BeginForm("EditRole", "Administration", FormMethod.Post)) {
<div class="form-group row">
<label asp-for="EditRole.RoleName" class="col-sm-12 col-md-3"></label>
<div class="col-sm-12 col-md-9">
<input asp-for="EditRole.Id" type="hidden" value="#roles.Id" />
<input asp-for="EditRole.RoleName" class="form-control" value="#roles.Name" />
<span asp-validation-for="EditRole.RoleName" class="text-danger"></span>
</div>
</div>
<div class="d-flex flex-row-reverse">
<button type="submit" class="btn btn-success">Rolle bearbeiten</button>
#using(Html.BeginForm("DeleteRole", "Administration", FormMethod.Post)) {
<input name="id" type="hidden" value="#roles.Id" />
<button type="submit" class="btn btn-danger mr-2">Rolle löschen</button>
}
</div>
}
</div>
</div>
</div>
</div>
You could handle multiple submit in one form use asp-action like
#using (Html.BeginForm(FormMethod.Post))
{
<div class="d-flex flex-row-reverse">
<input type="submit" value="Save" class="btn btn-success" asp-controller="Administration" asp-action="EditRole" />
<input type="submit" value="Delete" class="btn btn-danger" asp-controller="Administration" asp-action="DeleteRole" />
</div>
}

How to access to RESTController through a controller?

I am using Spring.
The method in my RESTController is this,
http://localhost:8080/delivery-api/training/submit. It is able to save hard code values into database.
This is part of my html form, it can be open up using this URL: http://localhost:8080/delivery-web/training/apply.
<form th:object="${applyForm}" class="form-horizontal" role="form" method="post" action="http://localhost:8080/delivery-api/training/submit" >
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1" > Country </label>
<div class="col-sm-9">
<input type="text" id="form-field-1" placeholder="Country"
class="col-xs-10 col-sm-7" th:field="*{country}" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1"> Fee </label>
<div class="col-sm-9">
<input type="text" id="form-field-1" th:field="*{Fee}" class="col-xs-10 col-sm-7" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1"> Start Date </label>
<div class="col-sm-9">
<input type="date" id="form-field-1" th:field="*{startDate}"
class="col-xs-10 col-sm-7" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1">End Date </label>
<div class="col-sm-9">
<input type="date" id="form-field-1" th:field="*{endDate}"
class="col-xs-10 col-sm-7" />
</div>
</div>
<br> <br>
<button class="btn btn-info" type="submit">
<i class="ace-icon fa fa-check bigger-110"></i> Submit
</button>
</div>
</div>
</form>
When I click on submit, it can be directed to http://localhost:8080/delivery-api/training/submit and insert the hard coded values into database, but it did not direct to my application-form.html page after that.
My controller
#PostMapping(value = "/apply")
public String apply(#Valid #ModelAttribute("applyForm") DeliveryApplicationForm applyForm, BindingResult errors, Model model) {
model.addAttribute("applyForm", applyForm);
return VIEW_PATH + "application-form";
}
I would like to render html page and also pass data from my form to RESTController method through a controller after I click on the submit button in my html page.
May I know how I can do it?

HTML form not sending parameters

I wrote a login panel for my website and everything looks fine but when I click on submit page refreshes and no parameters are being sent. I checked both get andpost methods but it's not working. here is my code:
<form id="login_form" action="index.php?task=login" method="post">
<div class="control-group">
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input class="span2" id="username" type="text" value="Username" onblur="if(this.value=='') this.value='Username'" onfocus="if(this.value=='Username') this.value='';">
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-cog"></i></span>
<input class="span2" id="password" type="password" value="Password" onblur="if(this.value=='') this.value='Password'" onfocus="if(this.value=='Password') this.value='';" />
</div>
</div>
</div>
<div class="clear"></div>
<div class="separator"></div>
<button type="submit" class="btn">Login</button>
</form>
Can anyone tell me what is wrong with my code?
Your input tags don't have the name attribute which is required to post the value.
<input type="text" name="username" />

Pre-populating a Spring MVC form

I am looking for a way to pre-populate a Spring MVC form from values stored in a session-scoped bean. (using this namespace: http://www.springframework.org/tags/form).
For example, say I have added a queryInfo object to the uiModel.
How do I display the name instance variable from the queryInfo object?
<form:input path="queryInfo.name" />
Is this possible? If so how?
In your request mapping, add the bean to the model:
model.addAttribute("queryInfo", queryInfo);
Then use modelAttribute in the form tag to bind it to the form:
<form:form id="some-form" modelAttribute="queryInfo">
...
Now name will display (provided there is a getter in your object appropriately named) when you do this:
<form:input path="name" />
Keep in mind form:input is a child tag of form:form. It is not meant to be used on its own.
#skel625's solution for form:input is perfect, but in the case of the form:select, with different option how do I set attributes? because in this way only works for the form:input
My form:select is like this:
<form:select path="dolorefastidio">
<option value="1"><spring:message code="questionnaire.compile.label.paindiscomfort.one"/></option>
<option value="2"><spring:message code="questionnaire.compile.label.paindiscomfort.two"/></option>
<option value="3"><spring:message code="questionnaire.compile.label.paindiscomfort.three"/></option>
<option value="4"><spring:message code="questionnaire.compile.label.paindiscomfort.four"/></option>
<option value="5"><spring:message code="questionnaire.compile.label.paindiscomfort.five"/></option>
</form:select>
the solution is put in a value attribute the bean attribute like this
Exam Register Form
<div class="form-group has-success">
<label for="code" class="col-lg-3 control-label">Exam Code</label>
<div class="col-lg-9">
<form:input type="text" class="form-control" path="cod" placeholder="code" value="${editExam.cod}"/>
<form:errors path="cod" cssClass="error" />
</div>
</div>
<div class="form-group has-success">
<label for="name" class="col-lg-3 control-label">Exam Name</label>
<div class="col-lg-9">
<form:input type="text" class="form-control" path="name" placeholder="name" value="${editExam.name}"/>
<form:errors path="name" cssClass="error" />
</div>
</div>
<div class="form-group has-success">
<label for="teachNme" class="col-lg-3 control-label">Teacher Name</label>
<div class="col-lg-9">
<form:input type="text" class="form-control" path="teachName"
placeholder="Teacher Name" value="${exams.teachName}" />
<form:errors path="teachName" cssClass="error" />
</div>
</div>
<div class="form-group has-success">
<label for="vote" class="col-lg-3 control-label">Final Grade</label>
<div class="col-lg-9">
<form:input type="text" class="form-control" path="vote"
placeholder="Vote" value="${exams.vote}" />
<form:errors path="vote" cssClass="error" />
</div>
</div>
<div class="form-group has-success">
<label for="cfu" class="col-lg-3 control-label">Credits (CFU)</label>
<div class="col-lg-9">
<form:input type="text" class="form-control" path="cfu"
placeholder="Credits" value="${editExam.cfu}" />
<form:errors path="cfu" cssClass="error" />
</div>
</div>
<input type="submit" value="Save"
class="btn btn-primary pull-right">
</fieldset>
</form:form>

Need to change smarty file into zend file

HI here i have smarty file and i need to convert into zend..
How can i change smarty to zend? its tpl file
<div id="add-user-form" class="form">
<form action="/account/login" method="post">
{{input_text type="hidden" name="redirect_url" value=$smarty.server.REDIRECT_URL|default:"/"}}
<div class="contain">
<div class="fieldgrp">
<label> </label>
<div class="field"><p><h3>Enter User Credentials</h3></p></div>
</div>
<div class="fieldgrp">
<label for="login_name">Username </label>
<div class="field">{{input_text name="login" id="login_name" class="longfield" maxlength="100"}}</div>
</div>
<div class="fieldgrp">
<label for="login_password">Password </label>
<div class="field">{{input_text type="password" name="password" id="login_password" class="longfield" maxlength="100"}}</div>
</div>
<div class="fieldgrp">
<label> </label>
<div class="field"><input type="submit" value="Login" /></div>
</div>
</div>
</form>
You can replace the Smarty code with the HTML it generates....
eg.
{{input_text name="login" id="login_name" class="longfield" maxlength="100"}}
becomes
<input type="text" name="login" id="login_name" class="longfield" maxlength="100">
But past that, this question doesn't really make a lot of sense.