I have an old JSP application for which I cannot use Jquery or Ajax.
I have the following code snippet
function func(val){
if(val=="true"){
<%
myBean.myMethod("ABC","DET",0);
%>
myfrm.submit();
}
}
and I am calling this from a button's onClick event.
What I would like to do is invoke my Java method only when button is clicked. If page is refreshed java method should not be invoked.
How can I achieve this?
This is not possible. The java code is only executed when you refresh/load the page. Once the page is rendered, only client-side code can be executed.
You could have the button post to x.jsp and then do a redirect y.jsp
Looks like you have called your method within the jsp lifecycle.
As the jsp is parsed your method will be executed.
The functionallity you want you will most likely have to create an event.
<input type="hidden" value="" id="executeThis" onclick="document.forms[0].submit();"/>
<button id="doWork" type="button" onclick="execTheClick('executeThis', 'methodName');"/>
function execTheClick(linkId, methodName)
{
var fireOnThis = document.getElementById(linkId);
fireOnThis.value = methodName;
if (document.createEvent)
{
var evObj = document.createEvent('MouseEvents');
evObj.initEvent( 'click', true, false );
fireOnThis.dispatchEvent(evObj);
}
else if (document.createEventObject)
{
var evObj = document.createEventObject();
fireOnThis.fireEvent('onclick',evObj);
}
}
Hope that helps
Related
i have jsp that call method in servlet. i tried to use System.out.println() to prove that my jsp success enter the servlet. The problem i face is i can't get the System.out.println() mean that my jsp can't go in the servlet. Please give some advice for this.
JSP:
<% SendPayment processPayment = new SendPayement();
success = processPayment.sendPayment( payMerInfoBean.getdbCon(), payOrderBean, payOrderParaBean, payMerInfoBean);%>
Servlet:
public boolean sendPayment(Connection con, B2cOrderBean payOrderBean,
B2cOrderParaBean payOrderParaBean, B2cMerInfoBean payMerInfoBean, B2cMcpOrderBean payMcpOrderBean, B2cEPayAlertBean ePayAlertBean) {
System.out.println("In SendPayment");
return false;
}
i would like to know if its possible to have a clickable link for a dynamic text.
I have tried by using the anchor tag with some wicket id and adding an onclick behavior to it, i could see the text with link on my screen but the onclick call of t he link was never triggered.
What could possibly be the issue?
i did something like this:
String someTextMessage = "Hey!!! <a wicket:id='printLink'>Click Here</a> now.";
Lable message = new Lable("messageLable", someTextMessage);
message.setEscapeModelStrings(true);
Link printLink = new Link("printLink") {
#Override
public void onClick() {
System.out.println("inside onClick");
}
};
this.add(printLink);
this.add(message);
i used this wicket id and added it to the page and attached an onclick behavior to this.
I have checked t he firebug console but there was no onclick call made for the link's click.
Thanks.
You want to use the Link.setAnchor(Component) method.
Don't forget to setOutputMarkupId to true for the component you want to jump to.
Label message = new Label("messageLable", "Anchor!");
message.setOutputMarkupId(true);
this.add(message);
Link printLink = new Link("printLink") {
#Override
public void onClick() {
System.out.println("inside onClick");
}
};
printLink.setAnchor(message);
this.add(printLink);
Don't try to add wicket components by appending html with "wicket:id" in some kind of component. It won't work.
First sorry for my english...
I was searching for all internet but I can't find the answer of my question. I tried everything, looked in documentation, tutorials, videos, etc...
I put two buttons in the top of my page for the user can change the language, but I can't catch the value on my controller, I did everything but never can handle. I'm new on play :( please help...!!
I have this on my view:
<`form method="GET" action="#{Application.language("value")}"/`>
<`input> name="language" type="submit" value="en" title="#Messages("button.en")" </`>
<`input> name="language" type="submit" value="es" title="#Messages("button.es")" </`>
<`/form`>
And this on my controller:
public static void language(String idiom) {
String key = null;
key = idiom;
if(key.isEmpty()){
} else {
Lang.apply(idiom);
}
}
But when I try to catch the value on my controller always I received this message:
[RuntimeException: Unrecognized language: value]
Your HTML looks a little suspect, can you clean it up and repost along with your controller and route?
In the meanwhile, this is roughly what I'd expect to see to make sure your parameters get passed in properly:
Routes:
GET /language #controllers.LanguageController.index(language: String)
Controller:
LanguageController {
...
public Result index(String language) {
if(language != null && !language.isEmpty()){
Lang.apply(idiom);
}
... return
}
}
To make the setting stick in Play 2, see this post
playframework 2.2 java: how to set language (i18n) from subdomain
I did it a little modification with your comment below and this is how I have now.
Route:
POST / #controllers.LanguageController.changeLanguage(language: String)
View:
<form method="POST" action="changeLanguage("value")"/>
<input name="language" type="submit" value="en" title="English" </>
<input name="language" type="submit" value="es" title="Spanish" </>
</form>
Controller:
public class LanguageController extends Controller{
public Result changeLanguage(String language)
{
if(language != null && !language.isEmpty())
{
Lang.apply("en");
}
else
{
String idiom = language;
Lang.apply(idiom);
}
return ok(index.render(""));
}
Now I have this message error:
For request 'POST /changeLanguage(value)'
And the page error shows the route of the LanguageController this:
POST/#controllers.LanguageController#.changeLanguage(language:String)
You have messages.{lang} ( like messages.es or messages.en) in conf folder right?
And in application.conf valid langs should exist like;
application.langs="en,es"
If you have these so in any class which extends Controller you can run this method;
changeLang("es");
But in your case it seems that value of the idiom in your function is "value"
So if it's fine for you just replace the form header as;
<form method="GET" action="/language"/>
(assuming that /language will route to your method)
and replace the names of the html inputs as "idiom"
so you will be passing the right value of the input.
In play 2.8, Http.Context was deprecated which lead to changes in the interaction with the response object.
To change the language you need to do the following:
Inject an instance of MessagesApi into your controller
Create an instance of Lang object with the language you intend to use
Use method .withLang(Locale locale, MessagesApi messagesApi) on your result object
Code to illustrate:
private final MessagesApi messagesApi;
#Inject
public LoginController(MessagesApi messagesApi) {
this.messagesApi = messagesApi;
}
// ... now in the method invoked by the router
Lang lang = Lang.apply("en"); //english language
return ok().withLang(lang.toLocale(), messagesApi);
This changes the language throughout the rest of the session, since play will store the language in the cookie PLAY_SESSION. If you want to change only for one particular request, you must change the request object instead of the result object.
Reference here
I am very much new to phonegap applications but i am an android developer.I am trying to call camera on a button click in my phonegap application.Following is my html where i am calling take_pic() method of camera.js api javascript.I have included camera.js in body after seeing api example only.
<body>
<label for="hello">Hello World</label>
<br><input type="submit" id="submit" value="Call Camera" onclick="take_pic();">
<script type="text/javascript" charset="utf-8" src="apis/camera.js"></script>
</body>
following is the method of camera.js which is triggered but it throws "Can not read propery 'DATA_URL' of undefined type at file:///android_asset/www/apis/camera.js:45" error .Please guys help me out.let me know if more details are required
function take_pic() {
navigator.camera.getPicture(onPhotoDataSuccess, function(ex) {
alert("Camera Error!");
}, { quality : 30, destinationType: destinationType.DATA_URL });
}
Did you try the next code? it is in the PhoneGap API examples: PhoneGap example
var pictureSource; // picture source
var destinationType; // sets the format of returned value
// Wait for device API libraries to load
//
document.addEventListener("deviceready",onDeviceReady,false);
// device APIs are available
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function take_pic() {
navigator.camera.getPicture(onPhotoDataSuccess, function(ex) {
alert("Camera Error!");
}, { quality : 30, destinationType: destinationType.DATA_URL });
}
I think your problem is that the variable "destinationType" is undefined. Did you initialized it properly?
There is a page in which there are multiple rows with a 'Change Status' button[a 'submit' button] at the end of each row. There are more than ten status present. When I click on the 'Change Status' button, the control goes the action class and the page reloads with the changed status.
I have id's associated with each row. how do I identify in which row I have clicked the 'Change Status' button when the page reloads ? Should I pass the id through java-script to the action class ? Is there a simpler way than this ?
Well you can take advantage of Struts2 multiple submit button functionality.Like you can set submit button value based on your ID and collect that in your action to use it in your way something like
<button type="submit" value="Submit" name="buttonName">
<button type="submit" value="Clear" name="buttonName">
class MyAction extends ActionSupport {
private String buttonName;
public void setButtonName(String buttonName) {
this.buttonName = buttonName;
}
public String execute() {
if ("Submit".equals(buttonName)) {
doSubmit();
return "submitResult";
}
if ("Clear".equals(buttonName)) {
doClear();
return "clearResult";
}
return super.execute();
}
}
So in short value can be what is the uniqque id and you can use it in action as per your choice
for details
multiple-submit-buttons
You can add the id to be part of your form and that way you will receive the id as a parameter when you submit. No need for javascript.
You can do a different form for each row.
Every form can have a
<s:hidden />
with the id of the row.
In this way you always know which is the submit clicked.