Java Vaadin获取init外部字符串的值
我是否可以在init方法之外检索字符串“code”的值,并在其他方法中使用它 如果是,如何进行 谢谢你的帮助 编辑:字符串必须在init方法中 代码:Java Vaadin获取init外部字符串的值,java,vaadin,Java,Vaadin,我是否可以在init方法之外检索字符串“code”的值,并在其他方法中使用它 如果是,如何进行 谢谢你的帮助 编辑:字符串必须在init方法中 代码: 您可以将代码存储为实例变量: public class VaadinApplication { private String code = null; // <-- Instance variable protected void init(VaadinRequest request) { main();
您可以将代码存储为实例变量:
public class VaadinApplication {
private String code = null; // <-- Instance variable
protected void init(VaadinRequest request) {
main();
String code = request.getParameter("code");
if (code != null){
this.code = code; // <-- store code here
System.out.println("Code: " + code);
next();
}
protected void otherMethod() {
this.code; // <-- Get code here and use it
//...
}
}
公共类应用程序{
private String code=null;//您提供的代码是您自己的类吗?@JamesB是您创建新的Vaadin应用程序时默认编写的。但是类中的代码是我的。您可以向这个类添加代码吗?@JamesB是的,我可以。您有什么建议吗?
public class VaadinApplication {
private String code = null; // <-- Instance variable
protected void init(VaadinRequest request) {
main();
String code = request.getParameter("code");
if (code != null){
this.code = code; // <-- store code here
System.out.println("Code: " + code);
next();
}
protected void otherMethod() {
this.code; // <-- Get code here and use it
//...
}
}