I have two problems:
I have no idea how to call a java class function in a html page using angularJS.
I need my button to be disabled after it is used.
My address is this: http://localhost:8080/CreditCardWEB/rest/cc/init
I have this in my class:
CardBean.java
#GET
#Path("/init")
public void init() {
Student s = new Student(1, "Pera", "Peric");
em.persist(s);
s = new Student(2, "Pera2", "Peric2");
em.persist(s);
s = new Student(3, "Pera3", "Peric3");
em.persist(s);
}
In my indexStud.html page, I have a button:
<button ng-click="initStud()">Init Student</button>
In my controllers.js I have the problem, but I have no idea how to do it:
$scope.initStud = function() {
//call the function from Cardbean.java
//disable the button after he is used
}
Ok i found the answer to question number 1....and here is it
$scope.initStud = function() {
$http.post('http://localhost:8080/CreditCardWEB/rest/cc/init').success(
function(data) {
});
}
thats needed in the controllers.js file
and the #GET in the 1st line in the Cardbean.java file has to be changed to #POST
Related
I am currently making a friend request module. The user clicks "Approve" the program adds the friend to the _User class on Parse Server. I believed the code below would do it, and it does, but the problem is that is changes the current user to the new friend that has been added. So if the current user is "Bob", and Bob adds "Mike" the new current user is Mike.
I've been experimenting with signUp(), signUpInBackground(), but neither seem to work.
ParseUser newFriend = new ParseUser();
newFriend.setUsername(friendRequestFrom); //friendRequestFrom is a String that carries a name
newFriend.setPassword("12345");
newFriend.signUpInBackground(new SignUpCallback() {
#Override
public void done(ParseException e) {
if(e == null){
Log.i("Parse Result","Succesful!");
Log.i("Current User",ParseUser.getCurrentUser().getUsername());
}
else{
Log.i("Parse Result","Failed " + e.toString());
}
}
});
In order to create a new Parse user in Parse using client side code, you have to use a cloud code function hosted in your app backend.
In fact, for security reasons, client librararies are not permitted to directly add users.
In your server side, create a file (main.js) containing the following code:
Parse.Cloud.define("createNewUser", function(request, response) {
var User = Parse.Object.extend("User");
var us = new User();
us.set("username", request.params.username);
us.set("name", request.params.name);
us.set("email", request.params.email);
us.set("password", request.params.password);
us.save(null, {
useMasterKey: true,
success: function(obj) {
response.success("user added");
},
error:function(err){
response.error(err);
}
});
});
Then, you can test this function in your javascript client code as following:
var params = { username: "userEmailAddress#yahoo.fr",
email: "userEmailAddress#yahoo.fr",
name:"Here write the user name",
password:"TheUserPasswordHere"};
Parse.Cloud.run("createNewUser", params).then(function(response){console.log("response: "+response);}).catch(function (err) {
console.log("error: "+err);
});
I'm trying to do a thing in php that I've learnt in Java.
When a user logs in a website a Controller page saves in a private $userLogged var user infos and redirects him in index.php. Now, if he clicks on "profile" I would like that Controller page had in $userLogged his infos still. How I can do it? I've done this:
controller.php
class ECommerce
{
private $checker;
private $errorManager;
private $userLogged;
[...]
function userLogIn($data) {
$user = new User();
$this->userLogged = $user->getByEmail($data["email"]);
if($this->userLogged) {
if($this->userLogged->checkPassword($data["password"])) {
$_SESSION["ec_code"] = $this->userLogged->getCode();
$_SESSION["ec_name"] = $this->userLogged->getName();
$_SESSION["ec_surname"] = $this->userLogged->getSurname();
$_SESSION["ec_email"] = $this->userLogged->getEmail();
$this->redirect("e-commerce/index.php", null);
}
else {
$data["error_message"] = $this->errorManager->getErrorUserLogIn();
$this->redirect("e-commerce/accedi.php?err=1", $data);
}
}
else {
$data["error_message"] = $this->errorManager->getErrorUserLogIn();
$this->redirect("e-commerce/accedi.php?err=1", $data);
}
}
function seeUserProfile() {
$data["try"] = $this->userLogged->getName();
$this->redirect("e-commerce/profilo_utente.php", $data);
}
user_profile.php
<?php
session_start();
session_regenerate_id();
echo $_SESSION["data"]["try"];
what's wrong?
Thank you before!
Uh this is the error message I receive:
Fatal error: Call to a member function getName() on a non-object in /home/mhd-01/HOST_NAME/htdocs/e-commerce/controller/ECommerce.php on line 110
In user_profile.php you need to include the ECommerce class like Liquidchrome mentioned like so:
require('Controller.php');
and then you'll need to create an instance of your ECommerce Class
if you want to pass the same data to user_profile.php page you'll need to instantiate the user_profileclass and pass the instance of the ECommerce class you were using to it.
I am developing a RESTFul web service project which has a POJO as below:
#XmlRootElement
public class Input {
//variable declarations
public Input(){
//default constructor
}
//constructor no 1
public Input(String LR, double ECH,double CSH,String APP) {
this.LR = LR;
this.ECH = ECH;
this.CSH = CSH;
this.APP = APP;
}
//constructor no 2
public Input(String LR, double ECH,double CSH,String APP,...) {
this.LR = LR;
this.ECH = ECH;
this.CSH = CSH;
this.APP = APP;
//constructor of all other parameters including these
}
//getters and setters method below.
}
My ajax is getting called on this button:
<button type="submit" onClick='functionname();' class="btn btn-primary" ><span class="glyphicon glyphicon-lock"></span>Function</button>
The Controller class I have is as follows:
#Path("/input")
public class InputResponse {
InputService inputservice = new InputService();
#PUT
#Path("/approve")
#Produces(MediaType.APPLICATION_JSON)
public void approveInputRecord(Input obj) throws Exception{
String LR = obj.getLR();
double CSH = obj.getCSH();
double ECH = obj.getECH();
String APP = obj.getAPP();
Input input = new Input(LR,CSH,ECH,APP);
input = inputservice.approveTransaction(input);
}
}
The Service Class for the same is as below:
public class InputService {
CallableStatement stmt;
Statement commitStmt;
public InputService(){
//database connection
}
public Input approveTransaction(Input input) throws SQLException {
commitStmt = dcc.con.createStatement();
stmt=dcc.con.prepareCall("BEGIN APPROVRTRANSACTION(?,?,?,?); END;");
stmt.setString(1, input.getLR());
stmt.setDouble(2, input.getECH());
stmt.setDouble(3, input.getCSH());
stmt.setString(4, input.getAPP());
stmt.execute();
commitStmt.executeQuery("COMMIT");
return input;
}
}
Inside my JAVA Script my ajax call to above is:
var obj = {
LogReference : logreference,
EuroclearHoldings:euroclearholdings,
ClearstreamHoldings:clearstreamholdings,
Approver : loginXPID
}
var jsonobj = JSON.stringify(obj);
$.ajax({
url:'./webapi/input/approve',
type: 'PUT',
data:jsonobj,
cache:false,
contentType: 'application/json',
dataType:'json',
success:function(data)
{
alert('success');
},
error:function(xhr,textstatus,errorthrown){
alert(xhr.responseText);
alert(textstatus);
alert(errorthrown);
}
},'json');
Having this as my code my application is working fine on Google Chrome but sometimes works and sometimes not on Internet Explorer 11. This is the strange behavior. And the other thing which I am unable to get is even if it works on Chrome the ajax call always getting the alerts in error. Can anybody please explain why is it so? And how do I solve it? Any help much appreciated.
Update
Here is the output on network --> Response tab on chrome when error is thrown. But despite that I still get the output.
Many Thanks
As I can see your Button type="submit". If it is inside the form tag then call the ajax request in action of the file. As I can see from above comments this might be the issue. As you are submitting something this changes to a POST request and not GET request so its giving the error method not allowed. And looking at the solution just change the Button type='button' or call the ajax on the action of form tag. It should work.
I'm trying to update an HTML5 table in real-time with some data from the database. Here is my code:
HTML page:
<script type="text/javascript">
//check for browser support
if(typeof(EventSource)!=="undefined") {
//create an object, passing it the name and location of the server side script
var eSource = new EventSource("[some address]/api/sse");
//detect message receipt
eSource.onmessage = function(event) {
//write the received data to the page
document.getElementById("placeholder").innerHTML=table;
};
}
else {
[erro message]
}
</script>
And my Java Restful service:
#Path("/sse")
public class SSEResource {
#Context
private UriInfo context;
public SSEResource() {
}
#GET
#Produces(SseFeature.SERVER_SENT_EVENTS)
public String getServerSentEvents() throws Exception {
SomeObject o = new SomeObject();
final String myString = o.someQuery().getEntity().toString();
return "data: " + myString + "\n\n";
}
}
This someQuery() method queries from database and returns what I want to put on my table. Everythings looks great. But I want to know if it's right or wrong, because if I put some log on someQuery() method, I see that every 3 seconds the query is executed. This may cause heavy duty, right? Is this normal or is my code wrong?
Is it possible to nest forms in Wicket that are independent of each other? I want to have a form with a submit button and a cancel button. Both buttons should direct the user to the same page (let's call it Foo). The submit button should send some info to the server first; the cancel button should do nothing.
Here's a really simplified version of my existing code:
Form form = new Form() {
public void onSubmit()
{
PageParameters params = new PageParameters();
params.put("DocumentID", docID);
setResponsePage(Foo.class, params);
}
};
DropDownChoice<String> ddc = new DropDownChoice<String>("name", new PropertyModel<String>(this, "nameSelection"), names);
ddc.setRequired(true);
final Button submitButton = new Button("Submit") {
public void onSubmit() { doSubmitStuff(true); }
};
final Button cancelButton = new Button("Cancel") {
public void onSubmit() { doSubmitStuff(false); }
};
form.add(ddc);
form.add(submitButton);
form.add(cancelButton);
form.add(new FeedbackPanel("validationMessages"));
The problem is, I just added a validator, and it fires even if I press the cancel button, since the cancel button is attached to the same form as everything else. This could be avoided if the cancel button were in a separate form. As far as I know, I can't create a separate form because — due to the structure of the HTML — the separate form would be under the existing form in the component hierarchy.
Can I make the forms separate somehow in spite of the hierarchy? Or is there some other solution I can use?
EDIT:
In response to Don Roby's comment, this is a bit closer to what my code looked like back when I was trying setDefaultFormProcessing():
Form<Object> theForm = new Form<Object>("theForm") {
public void onSubmit()
{
PageParameters params = new PageParameters();
params.put("DocumentID", docID);
setResponsePage(Foo.class, params);
}
};
final CheckBox checkbox = new CheckBox("checkbox", new PropertyModel<Boolean>(this, "something"));
checkbox.add(new PermissionsValidator());
theForm.add(checkbox);
final Button saveButton = new Button("Save") {
public void onSubmit()
{ someMethod(true); }
};
final Button cancelButton = new Button("Cancel") {
public void onSubmit()
{ someMethod(false); }
};
cancelButton.setDefaultFormProcessing(false);
theForm.add(saveButton);
theForm.add(cancelButton);
theForm.add(new FeedbackPanel("validationMessages"));
There is an even simpler solution: call the setDefaultFormProcessing method on the cancel button with false as a parameter:
cancelButton.setDefaultFormProcessing(false);
This way, clicking the cancel button will bypass the form validation (and model updating), directly calling the onSubmit function.
It is possible to "nest" forms in wicket.
See this wiki entry
for some notes on how it works and this wiki entry for how it interacts with validation.
But for what you're after, the answer from Jawher should have worked and is much simpler.
Look at this example code for hints on getting that working.
I'm wondering if you've simplified your code too far in this posting. Can you produce a sample small enough to post that definitely has the problem?