打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
MyEclipse下开发JSF(2)
点击完成以后,发现在Outline View中新增加了一个UserBean.
Figure 4.5: UserBean now shown in the Outline View
UserBean.java的源代码也出现在 java编辑器中。
Figure 4.6: UserBean Java source opened up in an editor
Username 和password的setters和getters方法已经为我们产生了,接下来就是要在这个类中增加一个方法loginUser来处理用户登录的操作。
代码如下所示:
UserBean.java
public String loginUser() ...{
if("myeclipse".equals(getUserName()) && "myeclipse".equals(getPassword()))
return "success";
FacesContext facesContext = FacesContext.getCurrentInstance();
FacesMessage facesMessage = new FacesMessage(
"You have entered an invalid user name and/or password");
facesContext.addMessage("loginForm", facesMessage);
return "failure";
}
我们注意到,UserBean类没有继承任何JSF的类或接口,它只是一个简单的JavaBean包括额外逻辑来执行操作。他包括了类似Struts中的Struts Form 和 Struts Action的功能,将二者集成到一个类中.
另外,这些方法并没有返回到指定的类,像Struts中的ActionForward那样.
五.创建JSP页面
在这部分我们将创建两个jsp页面,一个是用户登录的页面,另一个是表明登录成功的页面.这两个页面各自为loginUser.jsp和 loginUserSuccess.jsp,为了使应用程序简单,如果登录出现异常,我们将返回loginUser.jsp页面,并没有增加任何验证.我们可以通过faces-config.xml文件来创建jsp页面.点击如图所示的JSP按钮来创建userLogin.jsp页面,出现JSP建立向导.
Figure 5.1: Creating userLogin.jsp using the faces-config.xml editor
以同样的方式来创建userLoginSuccess.jsp页面
Figure 5.2: Creating userLoginSuccess.jsp using the faces-config.xml editor
接下来编辑userLogin.jsp页面
Figure 5.3: Begin editing the userLogin.jsp page
MyEclipse JSP Designer可以采用Source 方式, Design 方式, Design/Source 方式来编辑JSP文件.在这个Demo中采用Design/Source方式,如图:
Figure 5.4: Switched to Design/Source mode and expanded JSF palettes
接下来我们需要在页面中添加如下代码:
为用户名增加h:inputText组件
为密码增加h:inputSecret组件
增加用户名输入框h:outputLabel
增加密码输入框h:outputLabel
同时页面要使用我们自己的MessageBundle.
Figure 5.5: Remove template text and add our MessageBundle to the JSP page
接下来,我们创建HTML form元素,用来包括登录控件,如图:
Figure 5.5a: Create the new form
现在来创建username 的组件h:inputText,如图:
Figure 5.6: Adding new inputText component
Figure 5.7: Adding new inputText component continued
1
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
struts2—MyEclipse?8.6中基本使用
JSF学习笔记
worklog in summer holiday 2006
blogjava - hexuzhong-利用myeclipse快速开发struts应用程序
[翻译]MyEclipse Struts 快速上手
MyEclipse10 开发 SSH2
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服