欢迎光临
我们一直在努力

【JSF心得】JAVA的对象传递是引用传递-JSP教程,Java技巧及代码

建站超值云服务器,限时71元/月

基于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);// 这里是重新改变值的地方

}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 【JSF心得】JAVA的对象传递是引用传递-JSP教程,Java技巧及代码
分享到: 更多 (0)

相关推荐

  • 暂无文章