I have a real problem but simple,really , i have an edit form that edits a record of a table, i have a value in it that it has to be unique ex:username,i using jquery validation plugin to validate, so i use the remote method like so:-
companyName: {
required: $("input#companyRequired").val(),
remote: "validator/checkCompanyName"
}
and it enters a method from the server that checks the value from the database,here's the method to check:-
#RequestMapping(value = "/checkCompanyName", params = "companyName")
public #ResponseBody
String checkCompanyName(#RequestParam String companyName) {
logger.debug("checking company : " + companyName);
if(leadService.checkCompany(companyName)==true){
return "false";
}
else{
return "true";
}
}
the problem is that i want to use remote only if the user has changed the input,so what should i do?,any help would appreciated,i'am using spring mvc as a server side
If you want to trigger validation only when user changes input value try that approach:
$("input#companyRequired").change(function(){
$("input#companyRequired").validate(
// rules here
)
});
If you want to validate several elements add class "remote-check" (or come up with your name) to that fields:
$("input.remote-check").change(function(){
$(this).validate(
// rules here
)
});
Related
I am using angular 6 as front end. Using front end input I want to know the status of tracking id 3,5,6. How to process this. Below is my code:
Angular service code:
getConsignmentByTrackingid(trackingid): Observable<any> {
console.log(trackingid);
//tracking ids are : 3,5,6
return this.http.get(`${this.baseUrl}/trackingid/${trackingid}`);
}
Spring boot controller code:
#GetMapping(value = "/tracking_history/trackingid/{trackingid}")
public ResponseEntity<List<Tracking>> findByTrackingId(#PathVariable String trackingid){
try{
List<Tracking> trackings = trackingRepository.findByTrackingId(trackingid);
if (trackings.isEmpty())
{
return new ResponseEntity<List<Tracking>>(HttpStatus.NO_CONTENT);
//return new ResponseEntity<>(trackings, HttpStatus.NO_CONTENT);
}
//System.out.println(trackings);
//output of system.out.println is : 3,5,6.
//How can I return these numbers one by one
return new ResponseEntity<>(trackings, HttpStatus.OK);
}
}
IMO if you need to send data in the form of array or object then you should not use query parmas or params in the HTTP.
In this case Request type should be POST/PUT and you should pass the data in the body part like below -
http.post(url, {body: setOfIds})
I'm using the Azure SDK, which uses Gson to serialize and deserialize objects to upload to their Mobile Services API. I've had success doing this with a customs class of primitives only, as in the examples given in the Gson User Guide. I'd like to do this with a custom class that contains an ArrayList. I'd even settle for a List or an Array, I'm not too picky. Here's my class:
public class clsUser {
private int UserID;
private String UserName;
private String UserStatus;
public ArrayList<String> UserEmails;
Gson appears to serialize the class when sending to the server this way:
{ UserEmails: [ 'myEmail#gmail.com', 'myEmail2#yahoo.com' ],
UserStatus: 'A',
UserName: 'Scott',
UserID: 1 }
On the server, I'm storing it all in a relational SQLServer database, so I'm keeping UserEmails as a String in there, and trying to bring it back out as an array.
However back on my Android/Gson/Client side, I'm getting an error:
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING
I suspect that the problem is that SQLServer is returning UserEmails with surrounding quotes. I'm not sure how to fix this. Complicating matters is that the Gson implementation is inside the Azure SDK, so I don't think I could even write a custom deserializer if I wanted to. Any suggestions on fixing this? Thanks in advance!
Konrad's comment helped me past this stumbling block. If the problem is that the server is returning this field as a String, then all I needed to do was insert a step to convert it to an Array before returning the data to my client. (Yay for dynamic types in Javascript!) My updated server script is below:
function lookup(request, response) {
var UserID = request.query.UserID;
if (UserID == null || isNaN(parseFloat(UserID))) {
response.send(400, "Invalid Parameters (" + UserID + ")");
} else {
request.service.mssql.query("select ID UserID, Full_Name UserName, Email_Addresses UserEmails, Status UserStatus from User_List where ID=?;", [UserID], {
success: function (results) {
if (results.length > 0) {
//*** Added this line below to convert String back to Array ***//
results[0].UserEmails = results[0].UserEmails.split(',')
response.send(200, results[0]);
} else {
response.send(200, []);
}
}, error: function (err) {
response.send(500, {"Message" : "Lookup error = " + err});
}
});
}
}
I have integrated BIRT in web application.I am using Eclipse Luna,JDK 1.8, BIRT Report Engine 4.1.1 and Data source I am using is Excel Data Source(not JDBC and all that). From my JSP page I am passing two parameters in the URL using Javascript AJAX like:`
var reporturl ="/Reporting/loadReport?ReportName="+reportName+"&ReportFormat=html&Supplier=Supplier4&Metal=Gold&Metal=Tin";
$("#reportData").html("Loading...<br><img src='/Reporting/resources/images/loading.gif' align='middle' >");
$('#reportData').load(reporturl ,function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error getting details ! ";
$("#reportData").html(msg + xhr.status + " " + xhr.statusText);
}
});
For report parameter "Metal" I have selected Display type : List Box, Data Type : String and have selected Dynamic Values and then have checked "Allow Multiple Values" checkbox. Then in the Property Editor of table, in Filters tab I have given the expressions as follows:
row["Supplier Name"] Equal to params["Supplier"].value
row["Metal"] In params["Metal"].value
After this switching to JavaEE perspective in my ReportRenderer.java , I have the following code to get multiple values associated with the "Metal" parameter(which are passed from the URL), I have merged those values as a comma(,) seperated list in a single String variable like :
public static String getParameter( HttpServletRequest request,
String parameterName )
{
if ( request.getCharacterEncoding( ) == null )
{
try
{
request.setCharacterEncoding( UTF_8_ENCODE );
}
catch ( UnsupportedEncodingException e )
{
}
}
String[] values = request.getParameterValues(parameterName);
String temp="";
if(values.length>1)
{
int i=0;
for(i=0;i<values.length-1;i++)
{
temp=temp+values[i]+",";
}
temp=temp+values[i];
}
else
{
temp = values[0];
}
return temp;
}
In a HashMap I am getting all parameters and it's respective values successfully and have set that Map like:
HashMap<String,Object> tempMap = new HashMap<String,Object>();
tempMap = discoverAndSetParameters( runnable, request );
for(String str : tempMap.keySet())
{
System.out.println("Key : "+str);
System.out.println("Value : "+tempMap.get(str));
}
iRunTask.setParameterValues(tempMap);
Here runnable is the object of IReportRunnable and request is the object of HttpServletRequest.
Now when I am running the web application, after clicking on the hyperlink named "Reports" I am getting following exception on console and no output on web page.
org.eclipse.birt.report.engine.api.impl.ParameterValidationException: The type of parameter "Metal" is expected as "Object[]", not "java.lang.String".
at org.eclipse.birt.report.engine.api.impl.EngineTask.validateAbstractScalarParameter(EngineTask.java:857)
at org.eclipse.birt.report.engine.api.impl.EngineTask.access$0(EngineTask.java:789)
at org.eclipse.birt.report.engine.api.impl.EngineTask$ParameterValidationVisitor.visitScalarParameter(EngineTask.java:706)
at org.eclipse.birt.report.engine.api.impl.EngineTask$ParameterVisitor.visit(EngineTask.java:1531)
at org.eclipse.birt.report.engine.api.impl.EngineTask.doValidateParameters(EngineTask.java:692)
at org.eclipse.birt.report.engine.api.impl.RunTask.doRun(RunTask.java:214)
at org.eclipse.birt.report.engine.api.impl.RunTask.run(RunTask.java:86)
Please help me how to resolve this problem and again I am specifying I am using Excel Data Source not JDBC or Scripted and all that. I have already gone through many blogs where questions are related to JDBC data source and that didn't helped me.
When a listbox parameter is declared as "Allow multiple values", the BIRT engine is expecting an array of values, but in your case you send a String.
Therefore when you detect a multi-value parameter, instead of building a comma-separated String you should build a java array of values and pass this array to the parameter map. This way it will work.
Take care elements of this array should have the datatype expected by BIRT: if "Metal" parameter is set as "String" type in your report-design then you shoud be able to use "values" array as it is from getParameter function, otherwise it would be necessary to build a fresh array.
I'm currently trying to save search criteria attributes to the session between two pages: search page and edit page. The goal is to save the three variables: sYear, submission, collectionPeriod. I'm adding these to the session here below in the Search screen controller:
request.getSession().setAttribute("sYearSave", sYear);
request.getSession().setAttribute("submissionSave", submission);
request.getSession().setAttribute("collectionPeriodSave", collectionPeriod);
In the edit screen controller, I set a BooleanisFromEditScreen to true. This is so I know that I'm coming from the edit screen. I do print out the variables and I do get the values correctly here in the edit controller screen.
request.getSession().setAttribute("isFromEditScreen", new Boolean(true));
sYearSave = (String)request.getSession().getAttribute("sYearSave");
collectionPeriodSave = (String)request.getSession().getAttribute("collectionPeriodSave");
submissionSave = (String)request.getSession().getAttribute("submissionSave");
But the problem is when I use a back button to go back to the Search screen, the search criteria sYearSave, collectionPeriodSave, and submissionSave values return NULL. For some reason, the isFromEditScreen boolean works just fine and returns true. It actually enters the statement but the search criteria return null. The Search controller code is below:
if (isFromEditScreen != null && isFromEditScreen == true) {
System.out.println("Inside isFromEditScreen ==== true");
sYear = (String)request.getSession().getAttribute("sYearSave");
collectionPeriod = (String)request.getSession().getAttribute("collectionPeriodSave");
submission = (String)request.getSession().getAttribute("submissionSave");
sYearSave = (String)request.getSession().getAttribute("sYearSave");
collectionPeriodSave = (String)request.getSession().getAttribute("collectionPeriodSave");
submissionSave = (String)request.getSession().getAttribute("submissionSave");
System.out.println("sYearSave ==== " + sYearSave);
System.out.println("submissionSave ==== " + submissionSave);
System.out.println("collectionPeriodSave ==== " + collectionPeriodSave);
System.out.println("isFromEditScreen set in else ==== " + isFromEditScreen);
}
Any help would be greatly appreciated!
If you are using Spring MVC (as the question tag suggests), why not try using SessionAttributes annotaion and use the ModelAndView API from Spring? Also make sure the attribute name is unique across the application.
#RequestMapping("view-name")
#SessionAttributes( { "isFromEditScreen" })
public class YourController {
...
#RequestMapping
public ModelAndView display() {
ModelAndView modelAndView = new ModelAndView("view-name");
modelAndView.addObject("isFromEditScreen", new Boolean(true));
return modelAndView;
}
...
}
My session attributes were being overwritten. Overlooked mistake.
I want to use a custom authentication module conforming to JSR 196 in GlassFish 3. The interface javax.security.auth.message.ServerAuth has the method:
AuthStatus validateRequest(
MessageInfo messageInfo,
javax.security.auth.Subject clientSubject,
javax.security.auth.Subject serviceSubject
)
AuthStatus can be one of several constants like FAILURE or SUCCESS.
The question is: How can I get the roles from a "role datebase" with JSR 196?
Example: The server receives a request with a SSO token (CAS token for example), checks whether the token is valid, populates the remote user object with roles fetches from a database via JDBC or from REST service via http.
Is the role fetching in the scope of JSR 196? How could that be implemented?
Do I have to use JSR 196 together with JSR 115 to use custom authentication and a custom role source?
This is a code example from my JSR-196OpenID Implementation.
The method set the roles stored in a String Array for the current CallerPrincipal:
private boolean setCallerPrincipal(String caller, Subject clientSubject) {
boolean rvalue = true;
boolean assignGroups = true;
// create CallerPrincipalCallback
CallerPrincipalCallback cPCB = new CallerPrincipalCallback(
clientSubject, caller);
if (cPCB.getName() == null && cPCB.getPrincipal() == null) {
assignGroups = false;
}
try {
handler.handle((assignGroups ? new Callback[] {
cPCB,
new GroupPrincipalCallback(cPCB.getSubject(),
assignedGroups) } : new Callback[] { cPCB }));
logInfo(DEBUG_JMAC, "jmac.caller_principal:" + cPCB.getName() + " "
+ cPCB.getPrincipal());
} catch (Exception e) {
// should not happen
logger.log(Level.WARNING, "jmac.failed_to_set_caller", e);
rvalue = false;
}
return rvalue;
}
I call this method during the validateRequest() method.
You can see the complete code here:
http://code.google.com/p/openid4java-jsr196/source/browse/trunk/src/main/java/org/imixs/openid/openid4java/OpenID4JavaAuthModule.java
Also this page will be helpfull :
http://code.google.com/p/openid4java-jsr196/
Here's how I map users to roles:
I have 3 roles in my web.xml and also I have 3 role-to-group mappings in my sun-web.xml which map those roles several groups. Then I have a database with table Users that has a column called "group". That group corresponds to the group that is mapped to a role. I also use JSR 196-based custom auth module with OpenID. So basically whenever a user is logged in their group is read from the db and then my app assigns them the corresponding role. This is all done using the standard declarative security model of J2EE.
For my custom auth module I use a library called AuthenticRoast which makes things quite a bit simpler.
Here's also a related post...
Hope this helps.