jsf第一步 办公用品管理系统示例 学习笔记

1.登陆页面的全局错误提示
<h:messages globalOnly="true"></h:messages>
error_password对应你输入的密码有错!

 //声明一个没有登录成功的消息
                FacesMessage msg=MessageFactory.getMessage
                             (facesContext,"error_password","");  //第二个是消息的内容,第三个是设置参数             
                //为了与原来例子保持一致,这里设置了消息的严重等级
                msg.setSeverity(FacesMessage.SEVERITY_WARN);
                //将消息保存在facesContext中,供其他过程使用
                facesContext.addMessage(null,msg);
                //返回loginAction方法的结果,
                //该结果是一个字符串,用于与导航规则比较,
                //导航到登录失败后的页面
                return "failure";

???第二种设置消息的方法:使用异常类
            //捕获UserNotExistException异常,其余参见上面else处的注释
            FacesMessage msg=MessageFactory.getMessage(facesContext,
                          ue.getMessage(),new Object[]{ue.getUsername()});
            msg.setSeverity(FacesMessage.SEVERITY_WARN);
            facesContext.addMessage(null,msg);
            //在日志中记录尝试登录的用户ID
            log.warn(userName + ": want log in!");           
            return "failure";
UserNotExistException..
private String username;
 public UserNotExistException(String newUsername) {
                //super("Username " + newUsername + " does not exist");
                /
                super("error_usernotexist");
                this.username = newUsername;
        }
 public String getUsername() {
                return this.username;
        }

error_usernotexist对应用户名:{0} 找不到!
  

2.
需求分析
分析人员用统一建模语言(UML)的用例(use Case)来描述
需求。
用例一般用用例图配合文档来表示。
用例文档的书写。
用例文档一般包含下列内容;
用例文档,页面说明文档和业务规则说明和其他
要求等文件,综合起来,最终形成所谓的规则说明书。

3.myfaces的上传组件

 <h:form id="form1" name="form1" enctype="multipart/form-data" >
<t:inputFileUpload id="fileupload"
                               accept="image/*"
                               value="#{newArticle.upFile}"
                               storage="file"
                               styleClass="fileUploadInput"
                               required="true"/>
newArticle的upFile方法
  FacesContext facesContext =
                  FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest)
                     facesContext.getExternalContext().getRequest();
        //取得应用程序的在服务器上的真实目录,进而得到文件上传的目标目录       
        String filePath=request.getSession().getServletContext()
                     .getRealPath("/")+"image//";
        //得到上传源文件的文件名      
        String srcFileName=uploadFile.getName();
        //找到源文件扩展名前的“.”号在文件名字符串中的位置
        int i=srcFileName.lastIndexOf(".");
        //得到源文件的扩展名
        String extName=srcFileName.substring(i);
   //计算上传目标文件的路径以及文件名和扩展名
   String targetFile=filePath+randomID+extName;
   //取得上传文件的字节
         byte[] bytes=uploadFile.getBytes();
         //调用业务服务的上传文件方法
         articleService.uploadFile(targetFile, bytes);

articleService的uploadFile方法。就是二进制流。
  ?限制文件的类型和上传的大小。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值