Grails 프레임 워크에서 작동하지만 controller.My 응용 프로그램은 "단일 페이지 응용 프로그램"이 아닙니다. 서비스를 작성 했으므로 내 페이지를 다시로드하려고하지 않습니다. 즉 RegistrationService 아약스 전화로. 그래서 데이터 바인딩을위한 녹아웃을 사용하고 있습니다. 데이터베이스를 사용하는 postgresql입니다. 이메일 필드가있는보기 페이지가 있습니다. 중복 이메일 ID를 입력하고 저장 버튼을 클릭하면 유효성 검사 오류 (예 : "이미 이메일을 가져 왔습니다")가 표시 될 수 있지만 고유 ID를 작성하는 경우에도 동일한 유효성 검사 오류가 발생합니다.이 경우 modalModal.js 페이지에서 오류 상태가되기 때문에이 문제를 해결하는 방법을 알지 못합니다. 고유 ID를 입력하고 저장 버튼을 클릭하면 유효성 검사 오류가 표시되지 않습니다.보기 페이지에서 서버 쪽 유효성 검사 오류를 표시하는 방법
_newCostingpage.gsp (my view page)
<div id="light" class="white_content" style="color: black;">
<form action="#/cart" method="post">
<input type="hidden" name="url" value="${grailsApplication.config.serverURL}"/>
<p><label>first name: <input name="firstName"
class="formElement" data-bind='value: firstName'/></label></p>
<p><label>last name: <input name="lastName"
class="formElement" data-bind='value: lastName' /></label></p>
<p><label>organisation: <input name="organisation" class="formElement" data-
bind='value: organisation' /></label></p>
<p><label>email:
<input name="email" class="formElement" data-bind='value: email' /></label><label
id="errorDiv"></label></p>
<p><label>password: <input type="password" name="password"
class="formElement" data-bind='value: password' /></label></p>
<p><label style="margin-left: -37px;">confirm password:</label> <input
type="password" name="confirmPassword" class="formElement" data-bind='value:
confirmPassword' /></p>
<p><input type="submit" value="register"/></p>
</form>
<a href="javascript:void(0)"onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none';clearBox();">Close</a>
</div>
<div id="fade" class="black_overlay"></div>
</div>
Domain class :-\
class Registration {
String firstName
String lastName
String organization
String email
String password
String confirmPassword
static constraints = {
firstName(nullable:false)
lastName(nullable:true)
organization(blank:false)
email(nullable:false,email:true,unique:true)
password(blank:false)
confirmPassword(blank:false)
}
}
modalModal.js
var ratPack = $.sammy(function() {
this.post('#/cart', function() {
var firstname = this.params['firstName'];
var lastName = this.params['lastName'];
var organisation = this.params['organisation'];
var email = this.params['email'];
var password = this.params['password'];
var confirmPassword = this.params['confirmPassword'];
var baseurl = this.params['url'];
$.ajax({
type : 'POST',
url :'http://localhost:9191/guido-rest-
resource/api/registration/'+firstname+'/'+lastName+'/'+email,
success : function() {
alert("success:");
},
error:function(){
$('#errorDiv').text("Email has already been taken");
}
});
});
});
$(function() {
ratPack.run();
});
function clearBox(){
$('.formElement').val("");
}
RegistrationResource.groovy
package common.rest.resourcepl
import static org.grails.jaxrs.response.Responses.*
import javax.ws.rs.Consumes
import javax.ws.rs.GET
import javax.ws.rs.Produces
import javax.ws.rs.Path
import javax.ws.rs.PathParam
import javax.ws.rs.POST
import javax.ws.rs.core.Response
import common.servicepl.RegistrationService
@Path('/api/registration')
class RegistrationResource {
@GET
@Produces('text/plain')
String getRegistrationRepresentation() {
'Registration'
}
def registrationService;
@POST
@Path('/{firstname}/{lastName}/{email}')
Response create(@PathParam('firstname') String firstname,
@PathParam('lastName') String lastName,
@PathParam('email') String email) {
return
RegistrationService().createRegistration(firstname,lastName,email);
}
}
RegistrationService.groovy
package common.servicepl
import common.persistencepl.Registration
class RegistrationService {
def createRegistration(String firstName,String lastName,String email) {
println "Inside Registration Service"
def reg = new Registration();
reg.firstName = firstName;
reg.lastName = lastName;
reg.password = "asdf";
reg.confirmPassword = "asdf";
reg.email = email;
reg.organization = "fasdf";
if(reg.save([flush:true])){
return true
}
else
{
return false
}
}
}
당신이 동일한 응용 프로그램에서 서비스를 호출, HTTP'처럼 전체 경로를 speficy하지 않습니다 : // localhost를 .. .', 현재 페이지의 상대적인 위치를 지정하십시오.'/ api/registration ...' – BuddhiP