【JSF心得】JAVA的对象传递是引用传递
2008-01-03 12:35
453 查看
基于jsf-component的portlet的构建通常需要了解一下几点
1. 所有的jsf-component都是单一实例的,也就是说在每一个session周期内,一个UI组件只存在一个实例
2 对于UI组件中的变量,对于不属于UI组件的对象(FTPClient),在UI对象构建初期通过构造函数传递,之后,无论这些对象在其他地方发生任何变化,UI中引用的仍然是该对象的实例。对于UI组件自己的对象(UIStringInput),如果用setXX方法对其赋值了,UI对象在encode的时候,引用的也是该对象的当前值。
public class UIFileForm extends UISimpleForm {
static final public String SAVE_ACTION = "save";
static final public String CANCEL_ACTION = "cancel";
private FTPFile ftpFile_;
private FTPClient ftpClient_;
private UIStringInput nameInput_;
private String fileName_;
public UIFileForm(FTPClient ftp,ResourceBundle res) throws Exception {
super("fileForm", "post", null);
setId("UIFileForm");
setClazz("UIFileForm");
ftpClient_ = ftp; //引用外部对象
int idx = ftpFile_.getName().lastIndexOf("/");
String fileName = ftpFile_.getName().substring(idx++);
nameInput_ = new UIStringInput("name", fileName);
add(
new HeaderRow().add(
new Cell(res.getString("header.edit-file")).addColspan("2")));
add(
new Row().add(new LabelCell(res.getString("label.file-name"))).add(
new ComponentCell(this, nameInput_))); //尽管这里是在构造函数里面,但是nameInput是对象,所有即使它的值变化了,encode的时候仍然得到的是变化后的值
add(
new Row().add(
new ListComponentCell()
.add(
new FormButton(
res.getString("button.save"),
SAVE_ACTION))
.add(
new FormButton(
res.getString("button.cancel"),
CANCEL_ACTION))
.addColspan("2")
.addAlign("center")));
addActionListener(SaveActionListener.class, SAVE_ACTION);
addActionListener(CancelActionListener.class, CANCEL_ACTION);
}
public void setFileName(String s) {
fileName_ = s;
int idx = ftpFile_.getName().lastIndexOf("/");
String fileName = ftpFile_.getName().substring(idx++);
nameInput_.setText(fileName);// 这里是重新改变值的地方
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=186408
1. 所有的jsf-component都是单一实例的,也就是说在每一个session周期内,一个UI组件只存在一个实例
2 对于UI组件中的变量,对于不属于UI组件的对象(FTPClient),在UI对象构建初期通过构造函数传递,之后,无论这些对象在其他地方发生任何变化,UI中引用的仍然是该对象的实例。对于UI组件自己的对象(UIStringInput),如果用setXX方法对其赋值了,UI对象在encode的时候,引用的也是该对象的当前值。
public class UIFileForm extends UISimpleForm {
static final public String SAVE_ACTION = "save";
static final public String CANCEL_ACTION = "cancel";
private FTPFile ftpFile_;
private FTPClient ftpClient_;
private UIStringInput nameInput_;
private String fileName_;
public UIFileForm(FTPClient ftp,ResourceBundle res) throws Exception {
super("fileForm", "post", null);
setId("UIFileForm");
setClazz("UIFileForm");
ftpClient_ = ftp; //引用外部对象
int idx = ftpFile_.getName().lastIndexOf("/");
String fileName = ftpFile_.getName().substring(idx++);
nameInput_ = new UIStringInput("name", fileName);
add(
new HeaderRow().add(
new Cell(res.getString("header.edit-file")).addColspan("2")));
add(
new Row().add(new LabelCell(res.getString("label.file-name"))).add(
new ComponentCell(this, nameInput_))); //尽管这里是在构造函数里面,但是nameInput是对象,所有即使它的值变化了,encode的时候仍然得到的是变化后的值
add(
new Row().add(
new ListComponentCell()
.add(
new FormButton(
res.getString("button.save"),
SAVE_ACTION))
.add(
new FormButton(
res.getString("button.cancel"),
CANCEL_ACTION))
.addColspan("2")
.addAlign("center")));
addActionListener(SaveActionListener.class, SAVE_ACTION);
addActionListener(CancelActionListener.class, CANCEL_ACTION);
}
public void setFileName(String s) {
fileName_ = s;
int idx = ftpFile_.getName().lastIndexOf("/");
String fileName = ftpFile_.getName().substring(idx++);
nameInput_.setText(fileName);// 这里是重新改变值的地方
}
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=186408
相关文章推荐
- 【JSF心得】JAVA的对象传递是引用传递
- 【JSF心得】JAVA的对象传递是引用传递
- 【JSF心得】JAVA的对象传递是引用传递
- 【JSF心得】JAVA的对象传递是引用传递
- 【JSF心得】JAVA的对象传递是引用传递
- java传递是引用的拷贝,既不是引用本身,更不是对象
- Java - 当一个对象被当作参数传递到一个方法后,此方法可改变这个对象的属性,并可返回变化后的结果,那么这里到底是值传递还是引用传递?
- 在Java中方法参数的传递,对象是传递引用
- 【JAVA】34、对象引用传递
- Java面向对象-方法的值传递和引用传递
- java中基本变量、对象、对象引用等在堆与栈中存储、按值传递机制、栈中对象共享机制
- 小example说明java的值传递和引用传递,基础变量和对象在内存里的区别,堆栈
- Java对象内存存储,引用传递,值传递详细图解
- java对象引用传递和值传递的一些总结
- Java中对象、对象引用、堆、栈、值传递以及引用传递的详解
- Java对象、对象引用关系及参数传递讨论
- Java学习笔记---6.面向对象编程01-类对象的构建及对象的引用传递
- java 对象的引用传递
- java对象引用传递和值传递的一些总结
- Java String对象以“引用”方式被传递