`
djob2008
  • 浏览: 132882 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

core javaserver faces 笔记1

    博客分类:
  • JSF
阅读更多

编辑推荐
本书由著名畅销书作者、JSF 1.0专家组成员David Geary主笔,是JSF编程图书中的“头号指南”。作为升级版,本书内容全面覆盖JSF 1.2,囊括了各种增强特性、强大的Ajax开发技术,以及使JSF更有价值的开源创新内容。作者David Geary和Cay Horstmann在本书中深入讲解了JSF 1.2开发的各个方面,为创建高性能应用程序提供了系统级的最佳实用方案。他们利用自身对Java平台内部知识的透彻理解,为读者提供了大量解决方案、技巧、提示和编写优秀JSF 1.2产品代码的方法。即使读者是JSF或servlet新手,本书也能提供很大的帮助。
本版新增的内容包括:JSF 1.2与Java EE 5平台的更好结合;增强的JSF API;使用Shale控制Web流;使用Facelets将JSP替换为XHTML标签。此外,本版还涵盖了通过JSF进行Ajax开发的主题——从实时验证、DWR,到在JSF组件中包装Ajax和使用流行的Ajax4j sf框架。
  自动化低层细节,消除服务器端开发中不必要的复杂性从有效的UI设计和样式表到国际化,发现JSF最佳实践使用JSF和Tiles构建一致、可重用的用户界面利用外部服务,如数据库、LDAP目录、认证/授权,以及Web服务使用JBoss Seam大大简化数据库后端应用程序的开发实现自定义组件、转换器和验证器掌握JSF 1.2标签库和使用额外的标签库扩展JSF。

 内容简介
本书由著名畅销书作家、JSF 1.0专家组成员David Geary主笔,是JSF编程图书中的绝对“头号指南”,自第一版出版以来,一直是广大JSF学习者的首选教程。
本书全面深入地讲解了JSF 1.2编程的各个方面,包括JSF的各种增强特性、强大的Ajax开发技术,以及使JSF更具价值的开源创新内容,为创建高性能的应用程序提供系统级的最佳实用方案。两位传奇作者利用自身对Java平台的透彻理解,为读者提供了大量解决方案、技巧、提示和编写优秀JSF 1.2产品代码的方法,无论读者是JSF或者servlet方面的新手还是老手,都将大受裨益。

 作者简介
David Geary,从1994年到1997年在Sun Microsystems公司工作,曾任JSF 1.0专家组成员。目前,他担任Clarity Training Inc.公司的董事长,该公司是一家从事服务器端Java技术的培训咨询机构。David还是8本Java技术书籍的作者,其中包括最畅销的Graphic,Java 2系列、AdvancedJavaServer Pages和Google Web Toolkit Solutions。此外,David也是JSTL专家组成员、Apache Struts项目的执行委员,他还曾为Sun的Web Developer Certification Exam编写试题。作为一名演讲者,David在全球四大Java研讨会之一的No Fluff Just Stuff tour上经常作例行演讲。2005年,David和CraigMcClanahan合作的Shale Presentation,获得了JavaOne Rock Star的称号。

 

下面为本人读书笔记整理:

 目录
第1章 入门
1.1 为什么要选择JavaServer Faces
1.2 软件安装
1.3 一个简单的例子
1.3.1 组成部分
1.3.2 目录结构
1.3.3 构建说明
1.4 示例应用程序分析
1.4.1 Beans
1.4.2 JSF页面
1.4.3 导航
1.4.4 Servlet配置
1.4.5 欢迎文件
1.5 JSF开发环境
1.5.1 集成开发环境
1.5.2 可视构建器工具
1.5.3 使用Ant构建自动化
1.6 JSF框架服务
1.7 内幕
1.7.1 呈现页面
1.7.2 解码请求
1.7.3 生命周期
第2章 受管理Bean
2.1 Bean的定义
2.1.1 Bean属性
2.1.2 值表达式
2.2 消息包
2.2.1 具有可变部分的消息
2.2.2 设置应用程序的本地化
2.3 示例应用程序
2.4 支撑Bean
2.5 Bean作用域
2.5.1 会话作用域
2.5.2 应用程序作用域
2.5.3 请求作用域
2.5.4 生命周期说明
public class MyBean {
   @PostConstruct
   public void initialize() {
      // initialization code
   }
   @PreDestroy
   public void shutdown() {
      // shutdown code
   }
   // other bean methods
}
2.6 配置Bean
//(分成几个配置文件)
<web-app>
   <context-param>
      <param-name>javax.faces.CONFIG_FILES</param-name>
       <param-value>/WEB-INF/navigation.xml,/WEB-INF/beans.xml</param-value>
   </context-param>
   ...
</web-app>
//A bean is defined with a managed-bean element inside the top-level faces-config
//element. Minimally, you must specify the name, class, and scope of the bean.
   <faces-config>
      <managed-bean>
         <managed-bean-name>user</managed-bean-name>
         <managed-bean-class>com.corejsf.UserBean</managed-bean-class>
         <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>
   </faces-config>
//The scope can be request, session, application, or none. The none scope denotes an

2.6.1 设置属性值
<managed-bean>
   <managed-bean-name>user</managed-bean-name>
   <managed-bean-class>com.corejsf.UserBean</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
   <managed-property>
      <property-name>name</property-name>
      <value>me</value>
   </managed-property>
   <managed-property>
      <property-name>password</property-name>
      <value>secret</value>
   </managed-property>
</managed-bean>
//To initialize a property with null, use a null-value element. For example,
   <managed-property>
      <property-name>password</property-name>
      <null-value/>
   </managed-property>
   
2.6.2 初始化列表和映射(list & map)
//<value-class>可选的
<list-entries>
   <value-class>java.lang.Integer</value.class>
   <value>3</value>
   <value>1</value>
   <value>4</value>
   <value>1</value>
   <value>5</value>
</list-entries>

//<value>默认是字符串类型的
<map-entries>
   <key-class>java.lang.Integer</key-class>
   <map-entry>
      <key>1</key>
      <value>George Washington</value>
   </map-entry>
   <map-entry>
      <key>3</key>
      <value>Thomas Jefferson</value>
   </map-entry>
   <map-entry>
      <key>16</key>
      <value>Abraham Lincoln</value>
   </map-entry>
   <map-entry>
      <key>26</key>
      <value>Theodore Roosevelt</value>
   </map-entry>
</map-entries>

2.6.3 链接Bean定义
//The quiz contains a collection of problems, represented as the write-only
//problems property. You can configure it with the following instructions:
<managed-bean>
   <managed-bean-name>quiz</managed-bean-name>
   <managed-bean-class>com.corejsf.QuizBean</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
   <managed-property>
      <property-name>problems</property-name>
      <list-entries>
         <value-class>com.corejsf.ProblemBean</value-class>
         <value>#{problem1}</value>
         <value>#{problem2}</value>
         <value>#{problem3}</value>
         <value>#{problem4}</value>
         <value>#{problem5}</value>
      </list-entries>
   </managed-property>
</managed-bean>
//Of course, now we must define beans with names problem1 through problem5, like
//this:
   <managed-bean>
      <managed-bean-name>problem1</managed-bean-name>
      <managed-bean-class>
         com.corejsf.ProblemBean
      </managed-bean-class>
      <managed-bean-scope>none</managed-bean-scope>
         <managed-property>
            <property-name>sequence</property-name>
            <list-entries>
               <value-class>java.lang.Integer</value-class>
               <value>3</value>
               <value>1</value>
               <value>4</value>
               <value>1</value>
               <value>5</value>
            </list-entries>
         </managed-property>
		       <managed-property>
         <property-name>solution</property-name>
         <value>9</value>
      </managed-property>
</managed-bean>
2.6.4 字符串转换
2.7 值表达式的语法
2.7.1 使用方括号
2.7.2 映射和列表表达式
2.7.3 解析初始术语
2.7.4 复合表达式
2.7.5 方法表达式
第3章 导航
3.1 静态导航
//You give each button an action attribute—for example,
  <h:commandButton label="Login" action="login"/>
//The action must match an outcome in a navigation rule:
<navigation-rule>
   <from-view-id>/index.jsp</from-view-id>
   <navigation-case>
      <from-outcome>login</from-outcome>
      <to-view-id>/welcome.jsp</to-view-id>
   </navigation-case>
   <navigation-case>
      <from-outcome>signup</from-outcome>
      <to-view-id>/newuser.jsp</to-view-id>
   </navigation-case>
</navigation-rule>

3.2 动态导航
<h:commandButton label="Login" action="#{loginController.verifyUser}"/>
//Here is an example of an action method:
  String verifyUser() {
     if (...)
        return "success";
     else
        return "failure";
  }
   <p>
       <h:commandButton value="#{msgs.startOverButton}"
          action="#{quiz.startOverAction}"/>
   </p>
</h:form>
//done.jsp部分代码p103
 <h:form>
   <p>
       <h:outputText value="#{msgs.thankYou}"/>
       <h:outputFormat value="#{msgs.score}">
          <f:param value="#{quiz.score}"/>//参看Msg.properties: score=Your score is {0}.
       </h:outputFormat>
   </p>
   <p>
       <h:commandButton value="#{msgs.startOverButton}"
          action="#{quiz.startOverAction}"/>
   </p>
</h:form>

3.3 高级导航问题
3.3.1 重定向
Redirecting the page is slower than forwarding because another round trip to
the browser is involved. However, the redirection gives the browser a chance to
update its address field.
CAUTION: Without the redirect element, the navigation handler forwards
the current request to the next page, and all name/value pairs stored in the
request scope are carried over to the new page. However, with the redirect
element, the request scope data is lost.
3.3.2 通配符
You can use wildcards in the from-view-id element of a navigation rule, for
example:
/*
  <navigation-rule>
     <from-view-id>/secure/*</from-view-id>
     <navigation-case>
        ...
     </navigation-case>
  </navigation-rule>
*/
NOTE: Instead of leaving out a from-view-id element, you can also use one
of the following to specify a rule that applies to all pages:
/*
<from-view-id>/*</from-view-id>
or
<from-view-id>*</from-view-id>
*/
3.3.3 使用from-action
<navigation-case>
   <from-action>#{quiz.answerAction}</from-action>
   <from-outcome>again</from-outcome>
   <to-view-id>/again.jsp</to-view-id>
</navigation-case>
<navigation-case>
   <from-action>#{quiz.startOverAction}</from-action>
   <from-outcome>again</from-outcome>
   <to-view-id>/index.jsp</to-view-id>
</navigation-case>

NOTE: The navigation handler does not invoke the method inside the #{...}
delimiters. The method has been invoked before the navigation handler
kicks in. The navigation handler merely uses the from-action string as a key
to find a matching navigation case.
3.3.4 导航算法
第4章 标准JSP标签
4.1 JSF核心标签概述
4.2 JSF HTML标签概述
4.3 表单
<html>
   <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
   <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
   <f:view>
       <head>
          <title>
              <h:outputText value="#{msgs.windowTitle}"/>
          </title>
       </head>
       <body>
          <h:form id="registerForm">
              <table>
                 <tr>
                    <td>
                       <h:outputText value="#{msgs.namePrompt}"/>
                    </td>
                    <td>
                       <h:inputText/>
                    </td>
                 </tr>
                 <tr>
                    <td>
                       <h:outputText value="#{msgs.passwordPrompt}"/>
                    </td>
                    <td>
                       <h:inputSecret id="password"/>
                    </td>
                </tr>
				             <tr>
                <td>
                   <h:outputText value="#{msgs.confirmPasswordPrompt}"/>
                </td>
                <td>
                   <h:inputSecret id="passwordConfirm"/>
                </td>
             </tr>
          </table>
          <h:commandButton type="button" value="Submit Form"
             onclick="checkPassword(this.form)"/>
      </h:form>
   </body>
   <script type="text/javascript">
   <!--
      function checkPassword(form) {
          var password = form["registerForm:password"].value;
          var passwordConfirm = form["registerForm:passwordConfirm"].value;
          if(password == passwordConfirm)
             form.submit();
          else
             alert("Password and password confirm fields don't match");
      }
   -->
   </script>
</f:view>
</html>

//javascript/src/java/com/corejsf/messages.properties
//Listing 4–2
    windowTitle=Accessing Form Elements with JavaScript
    namePrompt=Name:
    passwordPrompt=Password:
    confirmPasswordPrompt=Confirm Password:
	
4.4 文本字段和文本区域
h:inputText
h:inputSecret
h:inputTextarea
<h:inputText value="#{form.testString}" readonly="true"/>
<h:inputSecret value="#{form.passwd}" redisplay="true"/>
//The h:inputSecret examples illustrate the use of the redisplay attribute. If that
//the value is redisplayed when the page reloads. If redisplay is false, the value is
//discarded and is not redisplayed.
<h:inputSecret value="#{form.passwd}" redisplay="false"/>
<h:inputText value="inputText" style="color: Yellow; background: Teal;"/>
<h:inputText value="1234567" size="5"/>
<h:inputText value="1234567890" maxlength="6" size="10"/>
<h:inputTextarea rows="5"/>
<h:inputTextarea cols="5"/>
<h:inputTextarea value="123456789012345"rows="3" cols="10"/>
<h:inputTextarea value="#{form.dataInRows}"rows="2" cols="15"/>
4.4.1 隐藏字殷
4.4.2 使用文本字段和文本区域
4.4.3 显示文本和图片
h:outputText
h:outputFormat
h:graphicImage
<h:outputText value="#{form.testString}"/>
<h:outputText value="Number #{form.number}"/>
<h:outputText value="<input type='text' value='hello'/>"/>
<h:outputText escape="true" value='<input type="text" value="hello"/>'/>
<h:graphicImage value="/tjefferson.jpg"/>
<h:graphicImage value="/tjefferson.jpg"style="border: thin solid black"/>
4.5 按钮和链接
h:commandButton
h:commandLink
h:outputLink
4.5.1 使用命令按钮
<h:commandButton value="submit" type="submit"/>
<h:commandButton value="reset" type="reset"/>
<h:commandButton value="click this button..." onclick="alert('button clicked')" type="button"/>
<h:commandButton value="disabled" disabled="#{not form.buttonEnabled}"/>
<h:commandButton value="#{form.buttonText}" type="reset"/>

<h:commandLink>
   <h:outputText value="register"/>
</h:commandLink>
<h:commandLink style="font-style: italic">
   <h:outputText value="#{msgs.linkText}"/>
</h:commandLink>
<h:commandLink>
   <h:outputText value="#{msgs.linkText}"/>
   <h:graphicImage value="/registration.jpg"/>
</h:commandLink>
<h:commandLink value="welcome"
   actionListener="#{form.useLinkValue}"
   action="#{form.followLink}">
<h:commandLink>
   <h:outputText value="welcome"/>
   <f:param name="outcome" value="welcome"/>
</h:commandLink>
//p144~145
<h:outputLink value="http://java.net">
   <h:graphicImage value="java-dot-net.jpg"/>
   <h:outputText value="java.net"/>
</h:outputLink>
<h:outputLink value="#{form.welcomeURL}">
   <h:outputText value="#{form.welcomeLinkText}"/>
</h:outputLink>
<h:outputLink value="#introduction">
   <h:outputText value="Introduction"
      style="font-style: italic"/>
</h:outputLink>
<h:outputLink value="#conclusion"
      title="Go to the conclusion">
   <h:outputText value="Conclusion"/>
</h:outputLink>
<h:outputLink value="#toc"
      title="Go to the table of contents">
   <h2>Table of Contents</h2>
</h:outputLink>
4.5.2 使用命令链接
//example:
//ChangeLocaleBean.java
package djob2008;
/**
 * @author 邓惠敏
 * @time Jun 6, 20098:48:16 PM
 */
import java.util.Locale;
import javax.faces.context.FacesContext;
public class ChangeLocaleBean {
   public String germanAction() {
      FacesContext context = FacesContext.getCurrentInstance();
      context.getViewRoot().setLocale(Locale.CHINA);
      return null;
   }
   public String englishAction() {
      FacesContext context = FacesContext.getCurrentInstance();
      context.getViewRoot().setLocale(Locale.ENGLISH);
      return null;
   }
}
//User.java
package djob2008;
/**
 * @author 邓惠敏
 * @time 2009-5-26下午06:32:00
 */
public class User {
private String name;
private String description;
private String password;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}
}
//msg_zh.properties
indexWindowTitle=国际化
indexPageTitle=选择语言
namePrompt=姓名
passwordPrompt=密码
tellUsPrompt=关于你自己
submitPrompt=提交
//msg_en.properties
indexWindowTitle=county
indexPageTitle=please select your language
namePrompt=name
passwordPrompt=password
tellUsPrompt=about youself
submitPrompt=submit
//
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
	version="1.2">	
		<application>
		<locale-config>
			<default-locale>en</default-locale>
			<supported-locale>zh</supported-locale>
		</locale-config>
	</application>
	<navigation-rule>
		<from-view-id>/index.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/welcome.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	<navigation-rule>
		<from-view-id>/welcome.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/index.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	<navigation-rule>
		<from-view-id>gzh.jsp</from-view-id>
		<navigation-case>
			<from-outcome>thankyou</from-outcome>
			<to-view-id>/thankYou.jspjsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	<application>
		<resource-bundle>
			<base-name>msg</base-name>
			<var>msg</var>
		</resource-bundle>
	</application>
	<managed-bean>
		<managed-bean-name>user</managed-bean-name>
		<managed-bean-class>djob2008.User</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
	</managed-bean>
	<managed-bean>
   <managed-bean-name>localeChanger</managed-bean-name>
   <managed-bean-class>djob2008.ChangeLocaleBean</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
</managed-bean>	
</faces-config>
//gzh.jsp
<%@ page language="java" pageEncoding="GB18030"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
	<body>
		<f:view>
				<h:form>
					<table>
						<tr>
							<td>
								<h:commandLink immediate="true"
									action="#{localeChanger.germanAction}">
									<h:graphicImage value="images/logowiki.jpg" style="border: 0px" />
								</h:commandLink>
							</td>
							<td>
								<h:commandLink immediate="true"
									action="#{localeChanger.englishAction}">
									<h:graphicImage value="images/logowiki.jpg" style="border: 0px" />
								</h:commandLink>
							</td>
						</tr>
					</table>
					<p>
						<h:outputText value="#{msg.indexPageTitle}"
							style="font-style: italic; font-size: 1.3em" />
					</p>
					<table>
						<tr>
							<td>
								<h:outputText value="#{msg.namePrompt}" />
							</td>
							<td>
								<h:inputText value="#{user.name}" />
							</td>
						</tr>
						<tr>
							<td>
								<h:outputText value="#{msgs.passwordPrompt}" />
							</td>
							<td>
								<h:inputSecret value="#{user.password}" />
							</td>
						</tr>
						<tr>
							<td style="vertical-align: top">
								<h:outputText value="#{msg.tellUsPrompt}" />
							</td>
							<td>
								<h:inputTextarea value="#{user.description}"
									rows="5" cols="35"/>
							</td>
						</tr>
						<tr>
							<td>
								<h:commandButton value="#{msg.submitPrompt}" action="thankyou" />
							</td>
						</tr>
					</table>
				</h:form>
		</f:view>
	</body>
</html>
//thankYou.jsp
<%@ page language="java" pageEncoding="GB18030"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<body>
	<f:view>
	<h:outputText value="#{user.name}"/><p>
	<h:outputText value="#{user.password}"/><p>
	<pre><h:outputText value="#{user.description}"/></pre>
	</f:view>
</body>
</html>
4.6 选择标签
h:selectBooleanCheckbox
h:selectManyCheckbox
h:selectOneRadio
h:selectOneListbox
h:selectManyListbox
h:selectOneMenu
h:selectManyMenu
h:selectBooleanCheckbox <input type="checkbox">
h:selectManyCheckbox    
<table>
                           ...
                           <label>
                             <input type="checkbox"/>
                           </label>
                           ...
                        </table>
h:selectOneRadio      
  <table>
                           ...
                           <label>
                               <input type="radio"/>
                           </label>
                           ...
                        </table>
h:selectOneListbox      
<select>
                           <option value="Cheese">
                               Cheese
                           </option>
                           ...
                        </select>
h:selectManyListbox 
<select multiple>
                       <option value="Cheese">
                           Cheese
                       </option>
                       ...
                    </select>
h:selectOneMenu     
<select size="1">
                       <option value="Cheese">
                           Cheese
                       </option>
                       ...
                    </select>
h:selectManyMenu 
  <select multiple size="1">
                       <option value="Sunday">
                           Sunday
                       </option>
                       ...
                    </select>
4.6.1 复选框和单选按钮
h:selectBooleanCheckbox
h:selectManyCheckbox
<h:selectBooleanCheckbox value="#{form.contactMe}"/>
//The h:selectManyCheckbox tag looks like this:
  <h:selectManyCheckbox value="#{form.colors}">
     <f:selectItem itemValue="Red" itemLabel="Red"/>
     <f:selectItem itemValue="Blue" itemLabel="Blue"/>
     <f:selectItem itemValue="Yellow" itemLabel="Yellow"/>
     <f:selectItem itemValue="Green" itemLabel="Green"/>
     <f:selectItem itemValue="Orange" itemLabel="Orange"/>
  </h:selectManyCheckbox>
//h:selectOneRadio
  <h:selectOneRadio value="#{form.education}">
   <f:selectItem itemValue="High School" itemLabel="High School"/>
   <f:selectItem itemValue="Bachelor's" itemLabel="Bachelor's"/>
   <f:selectItem itemValue="Master's" itemLabel="Master's"/>
   <f:selectItem itemValue="Doctorate" itemLabel=Doctorate"/>
</h:selectOneRadio>
4.6.2 菜单和列表框
h:selectOneListbox
h:selectManyListbox
h:selectOneMenu
h:selectManyMenu
//the size attribute to specify the number of visible items
<h:selectOneListbox value="#{form.year}" size="5">
   <f:selectItem itemValue="1900" itemLabel="1900"/>
   <f:selectItem itemValue="1901" itemLabel="1901"/>
   ...
</h:selectOneListbox>
<h:selectManyListbox value="#{form.languages}">
   <f:selectItem itemValue="English" itemLabel="English"/>
   <f:selectItem itemValue="French" itemLabel="French"/>
   <f:selectItem itemValue="Italian" itemLabel="Italian"/>
   <f:selectItem itemValue="Spanish" itemLabel="Spanish"/>
   <f:selectItem itemValue="Russian" itemLabel="Russian"/>
</h:selectManyListbox>
<h:selectOneMenu value="#{form.day}">
   <f:selectItem itemValue="Sunday" itemLabel="Sunday"/>
   <f:selectItem itemValue="Monday" itemLabel="Monday"/>
   <f:selectItem itemValue="Tuesday" itemLabel="Tuesday"/>
   <f:selectItem itemValue="Wednesday" itemLabel="Wednesday"/>
   <f:selectItem itemValue="Thursday" itemLabel="Thursday"/>
   <f:selectItem itemValue="Friday" itemLabel="Friday"/>
   <f:selectItem itemValue="Saturday" itemLabel="Saturday"/>
</h:selectOneMenu>
4.6.3 项目
SelectItem(Object value)
Creates a SelectItem with a value. The item label is obtained by applying
toString() to the value.
SelectItem(Object value, String label)
Creates a SelectItem with a value and a label.
SelectItem(Object value, String label, String description)
Creates a SelectItem with a value, label, and description.
SelectItem(Object value, String label, String description, boolean disabled)
Creates a SelectItem with a value, label, description, and disabled state.

<h:selectOneRadio value="#{form.condiments}>
   <f:selectItems value="#{form.condimentItems}"/>
</h:selectOneRadio>
//例子:p169
//Form.java
package djob2008;

/**
 * @author 邓惠敏
 * @time Jun 7, 20098:03:43 AM
 */
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.faces.model.SelectItem;
public class Form {
   enum Education { HIGH_SCHOOL, BACHELOR, MASTER, DOCTOR };
   private String name;
   private boolean contactMe;
   private Integer[] bestDaysToContact;
   private Integer yearOfBirth;
   private String[] colors;
   private String[] languages;
   private Education education;
// PROPERTY: name
   public String getName() {
      return name;
   }
   public void setName(String newValue) {
      name = newValue;
   }
   // PROPERTY: contactMe
   public boolean getContactMe() {
      return contactMe;
   }
   public void setContactMe(boolean newValue) {
       contactMe = newValue;
    }
    // PROPERTY: bestDaysToContact
    public Integer[] getBestDaysToContact() {
       return bestDaysToContact;
    }
    public void setBestDaysToContact(Integer[] newValue) {
       bestDaysToContact = newValue;
    }
    // PROPERTY: yearOfBirth
    public Integer getYearOfBirth() {
       return yearOfBirth;
    }
    public void setYearOfBirth(Integer newValue) {
       yearOfBirth = newValue;
    }
    // PROPERTY: colors
    public String[] getColors() {
       return colors;
    }
    public void setColors(String[] newValue) {
       colors = newValue;
    }
 // PROPERTY: languages
    public String[] getLanguages() {
       return languages;
    }
    public void setLanguages(String[] newValue) {
       languages = newValue;
    }
    // PROPERTY: education
    public Education getEducation() {
       return education;
    }
    public void setEducation(Education newValue) {
       education = newValue;
    }
    // PROPERTY: yearItems
    public Collection<SelectItem> getYearItems() {
	   return birthYears;
	}
	// PROPERTY: daysOfTheWeekItems
	public SelectItem[] getDaysOfTheWeekItems() {
	   return daysOfTheWeek;
	}
	// PROPERTY: languageItems
	public Map<String, Object> getLanguageItems() {
	   return languageItems;
	}
	// PROPERTY: colorItems
	public SelectItem[] getColorItems() {
	   return colorItems;
	}
	// PROPERTY: educationItems
	public SelectItem[] getEducationItems() {
	   return educationItems;
	}
	// PROPERTY: bestDaysConcatenated
	public String getBestDaysConcatenated() {
	   return concatenate(bestDaysToContact);
	}
	// PROPERTY: languagesConcatenated
	public String getLanguagesConcatenated() {
	   return concatenate(languages);
	}
	// PROPERTY: colorsConcatenated
	public String getColorsConcatenated() {
	   return concatenate(colors);
	}
	private static String concatenate(Object[] values) {
	   if (values == null)
	      return "";
	   StringBuilder r = new StringBuilder();
	   for (Object value : values) {
	      if (r.length()> 0)
	         r.append(',');
	      r.append(value.toString());
	   }
	   return r.toString();
	}
	private static SelectItem[] colorItems = {
	   new SelectItem("Red"),
	   new SelectItem("Blue"),
	   new SelectItem("Yellow"),
	   new SelectItem("Green"),
	   new SelectItem("Orange")
	};
	private static SelectItem[] educationItems = {
	   new SelectItem(Education.HIGH_SCHOOL, "High School"),
	   new SelectItem(Education.BACHELOR, "Bachelor's"),
	   new SelectItem(Education.MASTER, "Master's"),
	   new SelectItem(Education.DOCTOR, "Doctorate") };
	private static Map<String, Object> languageItems;
	static {
	   languageItems = new LinkedHashMap<String, Object>();
	   languageItems.put("English", "en"); // item, value
	   languageItems.put("French", "fr");
	   languageItems.put("Russian", "ru");
	   languageItems.put("Italian", "it");
	   languageItems.put("Spanish", "es");
	}
	  private static Collection<SelectItem> birthYears;
	  static {
	     birthYears = new ArrayList<SelectItem>();
	     for (int i = 1900; i < 2000; ++i) {
	        birthYears.add(new SelectItem(i));
	     }
	  }
	  private static SelectItem[] daysOfTheWeek;
	  static {
	     DateFormatSymbols symbols = new DateFormatSymbols();
	     String[] weekdays = symbols.getWeekdays();
	     daysOfTheWeek = new SelectItem[7];
	     for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++) {
	        daysOfTheWeek[i - 1] = new SelectItem(new Integer(i), weekdays[i]);
	     }
	  }
	}

//getInfo.jsp
<html>
	<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
	<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
	<f:view>
		<head>
			<title><h:outputText value="#{msgs.indexWindowTitle}" /></title>
		</head>
		<body>
			<h:outputText value="#{msgs.indexPageTitle}" styleClass="emphasis" />
			<h:form>
				<table>
					<tr>
						<td>
							<h:outputText value="#{msgs.namePrompt}" />
						</td>
						<td>
							<h:inputText value="#{form.name}" />
						</td>
					</tr>
					<tr>
						<td>
							<h:outputText value="#{msgs.contactMePrompt}" />
						</td>
						<td>
							<h:selectBooleanCheckbox value="#{form.contactMe}" />
						</td>
					</tr>
					<tr>
						<td>
							<h:outputText value="#{msgs.bestDayPrompt}" />
						</td>
						<td>
							<h:selectManyMenu value="#{form.bestDaysToContact}">
								<f:selectItems value="#{form.daysOfTheWeekItems}" />
							</h:selectManyMenu>
						</td>
					</tr>
					<tr>
						<td>
							<h:outputText value="#{msgs.yearOfBirthPrompt}" />
						</td>
						<td>
							<h:selectOneListbox size="5" value="#{form.yearOfBirth}">
								<f:selectItems value="#{form.yearItems}" />
							</h:selectOneListbox>
						</td>
					</tr>
					<tr>
						<td>
							<h:outputText value="#{msgs.colorPrompt}" />
						</td>
						<td>
							<h:selectManyCheckbox value="#{form.colors}">
								<f:selectItems value="#{form.colorItems}" />
							</h:selectManyCheckbox>
						</td>
					</tr>
					<tr>
						<td>
							<h:outputText value="#{msgs.languagePrompt}" />
						</td>
						<td>
							<h:selectManyListbox value="#{form.languages}">
								<f:selectItems value="#{form.languageItems}" />
							</h:selectManyListbox>
						</td>
					</tr>
					<tr>
						<td>
							<h:outputText value="#{msgs.educationPrompt}" />
						</td>
						<td>
							<h:selectOneRadio value="#{form.education}"
								layout="pageDirection">
								<f:selectItems value="#{form.educationItems}" />
							</h:selectOneRadio>
						</td>
					</tr>
				</table>
				<h:commandButton value="#{msgs.buttonPrompt}"
					action="showInformation" />
			</h:form>
			<h:messages/>
		</body>
	</f:view>
</html>
//showInformation.jsp
<html>
	<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
	<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
	<f:view>
		<head>
			<title><h:outputText value="#{msgs.indexWindowTitle}" /></title>
		</head>
		<body>
			<h:outputFormat value="#{msgs.thankYouLabel}">
				<f:param value="#{form.name}" />
			</h:outputFormat>
			<p>
			<table>
				<tr>
					<td>
						<h:outputText value="#{msgs.contactMeLabel}" />
					</td>
					<td>
						<h:outputText value="#{form.contactMe}" />
					</td>
				</tr>
				<tr>
					<td>
						<h:outputText value="#{msgs.bestDayLabel}" />
					</td>
					<td>
						<h:outputText value="#{form.bestDaysConcatenated}" />
					</td>
				</tr>
				<tr>
					<td>
						<h:outputText value="#{msgs.yearOfBirthLabel}" />
					</td>
					<td>
						<h:outputText value="#{form.yearOfBirth}" />
					</td>
				</tr>
				<tr>
					<td>
						<h:outputText value="#{msgs.languageLabel}" />
					</td>
					<td>
						<h:outputText value="#{form.languagesConcatenated}" />
					</td>
				</tr>
				<tr>
					<td>
						<h:outputText value="#{msgs.colorLabel}" />
					</td>
					<td>
						<h:outputText value="#{form.colorsConcatenated}" />
					</td>
				</tr>
				<tr>
					<td>
						<h:outputText value="#{msgs.educationLabel}" />
					</td>
					<td>
						<h:outputText value="#{form.education}" />
					</td>
				</tr>
			</table>
		</body>
	</f:view>
</html>
//msgs.properties
indexWindowTitle=Checkboxes, Radio buttons, Menus, and Listboxes
indexPageTitle=Please fill out the following information
namePrompt=Name:
contactMePrompt=Contact me
bestDayPrompt=What's the best day to contact you?
yearOfBirthPrompt=What year were you born?
buttonPrompt=Submit information
languagePrompt=Select the languages you speak:
educationPrompt=Select your highest education level:
emailAppPrompt=Select your email application:
colorPrompt=Select your favorite colors:
thankYouLabel=Thank you {0}, for your information
contactMeLabel=Contact me:
bestDayLabel=Best day to contact you:
yearOfBirthLabel=Your year of birth:
colorLabel=Colors:
languageLabel=Languages:
educationLabel=Education:
//face-config-xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
	version="1.2">
	<managed-bean>
		<managed-bean-name>user</managed-bean-name>
		<managed-bean-class>djob2008.User</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
	</managed-bean>
	<managed-bean>
		<managed-bean-name>localeChanger</managed-bean-name>
		<managed-bean-class>
			djob2008.ChangeLocaleBean
		</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
	</managed-bean>
	<managed-bean>
		<managed-bean-name>form</managed-bean-name>
		<managed-bean-class>djob2008.Form</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
	</managed-bean>
	<navigation-rule>
		<from-view-id>getInfo.jsp</from-view-id>
		<navigation-case>
			<from-outcome>showInformation</from-outcome>
			<to-view-id>/showInformation.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>

	<application>
		<locale-config>
			<default-locale>en</default-locale>
			<supported-locale>zh</supported-locale>
		</locale-config>
	</application>
	<navigation-rule>
		<from-view-id>/index.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/welcome.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	<navigation-rule>
		<from-view-id>/welcome.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/index.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	<navigation-rule>
		<from-view-id>gzh.jsp</from-view-id>
		<navigation-case>
			<from-outcome>thankyou</from-outcome>
			<to-view-id>/thankYou.jspjsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	<application>
		<resource-bundle>
			<base-name>msg</base-name>
			<var>msg</var>
		</resource-bundle>
		<resource-bundle>
			<base-name>msgs</base-name>
			<var>msgs</var>
		</resource-bundle>
	</application>
</faces-config>
4.7 消息
Information
Warning
Error
Fatal

NOTE: By default, h:messages shows message summaries but not details.
h:message, on the other hand, shows details but not summaries. If you use
h:messages and h:message together, as we did in the preceding example, sum-
maries will appear at the top of the page, with details next to the appropriate
input field.
4.8 面板
<h:panelGrid columns="2">
   ...
   <h:panelGroup>
       <h:inputText id="name" value="#{user.name}">
       <h:message for="name"/>
   </h:panelGroup>
   ...
</h:panelGrid>
//Grouping the text field and error message puts them in the same table cell.
 <h:form>
    <h:panelGrid columns="2" rowClasses="oddRows,evenRows">
     <h:outputText value="#{msgs.namePrompt}:" />
     <h:panelGroup>
      <h:inputText id="name" value="#{user.name}" required="true"
       label="#{msgs.namePrompt}" />
      <h:message for="name" errorClass="errors" />
     </h:panelGroup>
     <h:outputText value="#{msgs.agePrompt}:" />
     <h:inputText size="3" value="#{user.age}" label="#{msgs.agePrompt}" />
    </h:panelGrid>
    <br />
    <h:commandButton value="#{msgs.buttonPrompt}" />
   </h:form>

 

 

分享到:
评论

相关推荐

    Javaframework框架笔记

    除了上述独立的框架,Java EE(现在称为Jakarta EE)提供了一系列标准的服务器端框架,如JSF(JavaServer Faces)、EJB(Enterprise JavaBeans)、CDI(Contexts and Dependency Injection)等,它们共同构成了企业...

    良葛格JSF学习笔记.pdf

    - **书籍推荐**:《Core JavaServer Faces》、《使用JavaServer Faces开发UI》等。 - **在线资源**:包括但不限于JSF Central、JavaServer Faces Resources等网站,提供了丰富的文档和技术文章。 - **培训材料**:...

    java 笔记(自己整理的)

    Expression Language(EL)是JavaServer Faces (JSF)框架的一部分,它用于在JSP页面中简化表达式和数据绑定。EL提供了一种简洁的方式来访问JavaBean属性,使得视图层与业务逻辑层的交互更加清晰。 Java Core是指...

    JavaEE5学习笔记13-JSF集成Facelets使用经验总结

    **Facelets** 是一个为 **JSF**(JavaServer Faces)设计的视图技术,它提供了一种更为简洁高效的方式来构建JSF应用的用户界面。Facelets在JSF中的引入极大地简化了页面的开发过程,并且支持模板化,使得前端页面的...

    基于Matlab/Simulink的风电调频与风储联合频域模型仿真及应用

    内容概要:本文介绍了利用Matlab/Simulink进行风电调频与风储联合仿真的方法。针对传统时域仿真耗时的问题,提出了一种基于频域模型的方法,实现了快速高效的仿真。文中详细描述了虚拟惯性控制和储能下垂控制的具体实现方式及其对系统频率稳定性的影响。通过频域模型,将复杂的微分方程转化为简单的矩阵运算,显著提高了仿真速度。同时,加入了SOC(荷电状态)管理和滑动平均滤波,确保了储能系统的安全可靠运行。实验结果显示,在相同的硬件条件下,频域模型的仿真速度比传统时域模型快了近十倍,且频率偏差明显减小。 适合人群:从事电力系统仿真、风电调频研究的专业人士和技术爱好者。 使用场景及目标:适用于需要快速验证风电调频控制策略的研究人员和工程师。主要目标是在保证仿真精度的同时大幅提高仿真速度,为风电并网提供技术支持。 其他说明:本文提供的模型专注于调频性能分析,不涉及风机内部动态细节。对于更详细的风机模型,作者提供了进一步的参考资料。

    含碳交易与绿证的智能楼宇微网优化调度模型及其MATLAB实现

    内容概要:本文介绍了一种针对电热综合能源系统的优化调度模型,该模型在传统微网(风、光、储、火)的基础上加入了电动汽车(EVs)和智能楼宇单元,并引入了碳排放和绿色证书交易机制。模型通过MATLAB和YALMIP工具进行求解,主要关注于优化能源分配方案,降低整体成本并控制碳排放。文中详细讨论了模型的目标函数设计、约束条件设定、电动汽车充放电策略、智能楼宇温控负荷预测、绿证交易价格机制等方面的内容。实验结果显示,在考虑碳交易和绿证交易的情况下,系统的灵活性和经济性均有所提高。 适合人群:从事电力系统优化、智能楼宇设计、电动汽车调度等领域研究的专业人士和技术爱好者。 使用场景及目标:适用于希望深入了解电热综合能源系统优化调度方法的研究人员,尤其是那些对碳市场和绿证交易感兴趣的从业者。目标是提供一种能够有效整合多种能源形式并兼顾环境效益的解决方案。 其他说明:文中提供的代码片段展示了具体的实现细节,对于想要进一步探索相关领域的读者具有很高的参考价值。此外,作者还分享了一些调参经验和遇到的问题解决办法,有助于初学者更好地理解和应用这一复杂的优化模型。

    texlive-cweb-7:20180414-12.el8.x64-86.rpm.tar.gz

    1、文件说明: Centos8操作系统texlive-cweb-7:20180414-12.el8.rpm以及相关依赖,全打包为一个tar.gz压缩包 2、安装指令: #Step1、解压 tar -zxvf texlive-cweb-7:20180414-12.el8.tar.gz #Step2、进入解压后的目录,执行安装 sudo rpm -ivh *.rpm

    Matlab中地表水源热泵系统建模与粒子群算法优化制冷制热量

    内容概要:本文详细介绍了如何使用Matlab对地表水源热泵系统进行建模,并采用粒子群算法来优化每小时的制冷量和制热量。首先,文章解释了地表水源热泵的工作原理及其重要性,随后展示了如何设定基本参数并构建热泵机组的基础模型。接着,文章深入探讨了粒子群算法的具体实现步骤,包括参数设置、粒子初始化、适应度评估以及粒子位置和速度的更新规则。为了确保优化的有效性和实用性,文中还讨论了如何处理实际应用中的约束条件,如设备的最大能力和制冷/制热模式之间的互斥关系。此外,作者分享了一些实用技巧,例如引入混合优化方法以加快收敛速度,以及在目标函数中加入额外的惩罚项来减少不必要的模式切换。最终,通过对优化结果的可视化分析,验证了所提出的方法能够显著降低能耗并提高系统的运行效率。 适用人群:从事暖通空调系统设计、优化及相关领域的工程师和技术人员,尤其是那些希望深入了解地表水源热泵系统特性和优化方法的专业人士。 使用场景及目标:适用于需要对地表水源热泵系统进行精确建模和优化的情景,旨在找到既满足建筑负荷需求又能使机组运行在最高效率点的制冷/制热量组合。主要目标是在保证室内舒适度的前提下,最大限度地节约能源并延长设备使用寿命。 其他说明:文中提供的Matlab代码片段可以帮助读者更好地理解和复现整个建模和优化过程。同时,作者强调了在实际工程项目中灵活调整相关参数的重要性,以便获得更好的优化效果。

    流体力学中EMD经验模态分解的MATLAB实现与应用技巧

    内容概要:本文详细介绍了经验模态分解(EMD)在流体力学领域的应用,特别是通过MATLAB进行流场数据分析的方法。首先,文章解释了EMD的基本概念及其在处理非平稳信号方面的优势,如湍流和涡旋数据。接着,提供了具体的MATLAB代码示例,展示了如何将原始流场数据分解为多个本征模态函数(IMF),并通过可视化手段展示分解结果。此外,文中还讨论了一些常见的EMD应用技巧,如边界效应处理、筛分停止准则设置以及针对特定应用场景(如二维速度场、三维加速度信号)的优化方法。最后,强调了EMD在流场信号解剖中的重要性和实用性,并分享了多个实战案例,包括圆柱绕流、翼型失速、船舶波浪载荷等。 适合人群:从事流体力学研究的专业人士,尤其是需要处理非平稳流场数据的研究人员和技术人员。 使用场景及目标:适用于需要对复杂流场数据进行精细分析的情景,如风洞实验、CFD模拟结果后处理等。主要目标是帮助用户更好地理解和解析流场中的多尺度动态行为,提高数据分析的准确性和效率。 其他说明:文章不仅提供了详细的理论讲解,还包括丰富的代码示例和实用技巧,有助于读者快速掌握EMD的应用方法。同时,附带的实例数据和视频教程进一步增强了学习效果。

    滑模变结构控制MATLAB仿真:理论解析与实践应用

    内容概要:本文详细介绍了滑模变结构控制的基本理论及其在MATLAB环境下的仿真实现。首先解释了滑模变结构控制的概念,即系统结构随状态变化而切换,以达到理想的动态性能。文中通过具体的二阶系统实例展示了如何构建状态空间模型、设计滑模面和控制律,并利用MATLAB进行了详细的仿真验证。此外,还探讨了滑模控制中的关键问题,如抖振现象的处理、参数选择的原则以及面对不确定性和扰动时的鲁棒性表现。 适合人群:自动化专业学生、控制系统工程师、从事控制理论研究的研究人员。 使用场景及目标:适用于需要深入了解滑模变结构控制原理并在实践中加以应用的人群。具体应用场景包括但不限于机器人控制、航空航天、工业自动化等领域,旨在提高系统的稳定性和抗干扰能力。 其他说明:文章提供了丰富的MATLAB代码片段,帮助读者更好地理解和掌握滑模变结构控制的实际操作步骤。同时强调了在实际应用中需要注意的技术细节,如计算步长的选择、参数优化等。

    基于Zynq的高效以太网传输框架:FPGA数据DMA传输与千兆网通信解决方案

    内容概要:本文详细介绍了基于Zynq平台的以太网传输框架,涵盖从FPGA数据采集、DMA传输到DDR存储,再到通过千兆网传输给电脑的全过程。框架通过高效的DMA技术和合理的软硬件协同设计,实现了快速、可靠的数据传输。文中不仅提供了具体的VHDL、Verilog和C代码示例,还分享了实际应用中的经验教训和技术细节,如内存对齐、中断处理和网络带宽控制等。 适合人群:适用于嵌入式系统开发人员、FPGA工程师、模拟半导体芯片测试工程师以及相关专业的师生。 使用场景及目标:主要用于需要高效数据传输的应用场景,如模拟数字转换器(ADC)、数字模拟转换器(DAC)的数据采集与传输,摄像头数据回传,声呐采集等。目标是提高开发效率,减少开发周期,使开发者能够集中精力在特定功能的实现上。 其他说明:文章强调了框架的实际应用效果,如降低内存拷贝耗时、提高网络吞吐量、减少CPU占用率等,并提供了一些实用的调试和优化技巧。配套的工程文件和详细的文档支持进一步增强了其实用性和易用性。

    MATLAB中基于多普勒型降温曲线和记忆功能改进的模拟退火算法求解TSP问题

    内容概要:本文详细介绍了基于MATLAB的改进带记忆模拟退火算法求解旅行商问题(TSP)的方法。首先,针对传统模拟退火算法存在的收敛速度慢、易陷入局部最优的问题,提出了两种主要改进措施:一是引入多普勒型降温曲线,使算法在早期能够广泛搜索解空间,后期聚焦于局部优化;二是增加了记忆功能,记录迭代过程中找到的最优解,防止算法陷入局部最优。文中提供了具体的MATLAB代码实现,并展示了该算法在中国31城、64城、144城及att48城市数据集上的测试结果,表明改进后的算法显著提高了求解效率和准确性。 适合人群:对TSP问题及其解决方案感兴趣的科研人员、算法开发者、学生。 使用场景及目标:适用于需要高效求解大规模TSP问题的实际应用场合,如物流配送路径规划、电路板钻孔路径优化等领域。目标是通过改进的模拟退火算法快速找到全局最优解或近似最优解。 其他说明:文章不仅提供了详细的理论解释和技术细节,还包括了完整的MATLAB代码实现和测试实例,方便读者理解和实践。此外,还提到了一些实用的调参技巧,帮助用户更好地调整算法参数以适应不同规模和复杂度的问题。

    Delphi 12.3控件之DDevExtensions290.zip

    Delphi 12.3控件之DDevExtensions290.zip

    污水处理厂3D渲染与参数化建模:基于Blender和Python的全流程解决方案

    内容概要:本文详细介绍了如何利用Blender和Python为污水处理厂创建高精度3D渲染效果图及其背后的参数化建模方法。首先,作者展示了如何通过Python代码管理复杂的设备数据结构(如嵌套字典),并将其应用于3D模型中,确保每个工艺段的设备参数能够准确反映在渲染图中。接着,文章深入探讨了具体的材质处理技巧,比如使用噪声贴图和溅水遮罩来增强金属表面的真实感,以及如何优化渲染性能,如采用256采样+自适应采样+OpenImageDenoise的降噪组合拳,将渲染时间缩短至原来的三分之一。此外,文中还涉及到了一些高级特性,如通过Houdini的粒子系统模拟鸟类飞行路径,或者利用Three.js实现交互式的在线展示。最后,作者强调了参数化建模的重要性,它不仅提高了工作效率,还能更好地满足客户需求,尤其是在面对紧急的设计变更时。 适合人群:从事污水处理工程设计的专业人士,尤其是那些希望提升自己3D建模技能和提高工作效率的人。 使用场景及目标:适用于需要快速生成高质量污水处理厂设计方案的场合,特别是在投标阶段或向客户展示初步概念时。通过这种方式,设计师可以在短时间内制作出逼真的效果图,帮助客户直观理解设计方案,并且可以根据客户的反馈迅速调整模型参数,从而加快决策过程。 其他说明:除了技术细节外,本文还分享了许多实用的经验和技巧,如如何平衡美观与效率之间的关系,以及怎样应对实际项目中的各种挑战。对于想要深入了解这一领域的读者来说,这是一份非常有价值的学习资料。

    物流与路径优化:基于多种算法的车辆路径优化(VRP)、冷链物流、时间窗VRPTW及遗传算法的应用

    内容概要:本文详细介绍了车辆路径优化(VRP)的不同变种及其应用场景,如冷链物流VRP、带时间窗的VRP(VRPTW)、多配送中心VRP(MDVRP)以及电动车路径优化(EVRP)。文中不仅探讨了这些优化问题的基本概念和特点,还展示了如何利用遗传算法、蚁群算法、粒子群算法等多种智能优化算法来解决这些问题。特别地,针对冷链物流路径优化,文章提出了改进的遗传算法,通过引入大规模邻域搜索(LNS)和多目标优化方法,实现了更好的优化效果。此外,文章还提供了具体的MATLAB代码示例,帮助读者更好地理解和实现这些算法。 适合人群:对物流与路径优化感兴趣的科研人员、工程师和技术爱好者,尤其是那些希望深入了解VRP及其变种问题的人士。 使用场景及目标:适用于物流配送公司、电商平台、冷链物流公司等需要优化配送路径的企业。主要目标是通过合理的路径规划,减少运输成本、提高配送效率和服务质量,特别是在冷链物流中确保货物品质的同时降低运营成本。 其他说明:文章强调了不同算法在实际应用中的优劣比较,并指出在处理大规模问题时,改进后的遗传算法表现出显著优势。同时,文章还提供了一些实用的编程技巧和注意事项,有助于读者在实践中取得更好的优化结果。

    基于贝叶斯优化的LSTM模型参数优化及其实现方法

    内容概要:本文介绍了如何使用贝叶斯优化算法优化LSTM模型的隐含层个数、学习率和正则化参数,以提高多特征输入单输出的二分类或多分类任务的性能。文中详细展示了使用Matlab实现这一过程的具体步骤,包括数据准备、LSTM模型定义、贝叶斯优化设置、目标函数实现以及结果可视化等方面的内容。通过这种方法,不仅能够显著减少手动调参的时间成本,还能有效提升模型的分类准确性。 适合人群:对机器学习尤其是深度学习有一定了解的研究人员和技术开发者,特别是那些希望深入了解LSTM模型调参技巧的人群。 使用场景及目标:适用于需要处理序列数据或多特征输入的分类任务,旨在通过自动化调参手段获得更优的模型性能。具体应用场景包括但不限于医疗时序数据分析、地震预测、轴承故障诊断等领域。 其他说明:文中提供的代码模板可以直接应用于类似的任务中,只需根据实际情况调整输入数据即可。此外,作者还分享了一些实用的小贴士,如数据预处理方法、避免常见陷阱等,帮助读者更好地理解和应用所介绍的技术。

    图像与信号处理领域的低秩矩阵分解Matlab实现及其应用

    内容概要:本文详细介绍了利用Matlab实现低秩矩阵分解的方法,特别针对图像和信号处理中的杂波去除问题。文中首先解释了为何选择低秩矩阵分解这一方法,即很多实际数据矩阵虽然看起来复杂,但实际上具有低维结构,可以通过分解为低秩矩阵和稀疏矩阵来分别表示主要结构和杂波。接着展示了具体的Matlab代码实现,包括参数设置、初始化、迭代更新规则以及收敛条件的检查。此外,还提供了多个应用场景的具体实例,如处理含噪图像、老照片修复等,并讨论了一些优化技巧,如采用随机SVD提高效率。 适合人群:从事图像处理、信号处理的研究人员和技术开发者,尤其是对低秩矩阵分解感兴趣的学者。 使用场景及目标:适用于需要从含噪数据中提取有用信息的各种场合,如医学影像、遥感图像、音频信号等领域。目的是通过去除杂波,提高数据质量,增强后续分析的有效性和准确性。 其他说明:文中不仅给出了完整的代码示例,还深入探讨了各个步骤背后的数学原理,帮助读者理解算法的工作机制。同时提醒使用者注意处理大规模数据时可能出现的问题及解决方案。

    AGI智能时代2025让DeepSeek更有趣更有深度的思考研究分析报告24页.pdf

    AGI智能时代2025让DeepSeek更有趣更有深度的思考研究分析报告24页.pdf

    基于集成模型的LSBoost算法在时间序列预测中的Matlab实现及应用

    内容概要:本文详细介绍了基于集成模型的LSBoost算法在时间序列预测中的应用及其Matlab代码实现。首先解释了LSBoost算法的基本原理,即通过迭代训练一系列弱学习器并将其组合成强学习器,从而提高预测精度。接着展示了具体的Matlab代码实现步骤,包括数据生成与划分、LSBoost训练过程、预测与误差计算等。文中还讨论了实际应用中的注意事项,如滑动窗口机制、特征工程技巧、参数调优策略等。此外,提供了多种改进方法,如加入滞后项和移动平均交叉项、使用递归预测、模型融合等,以应对不同类型的时序数据。 适合人群:对时间序列预测感兴趣的科研人员、工程师和技术爱好者,尤其是有一定Matlab编程基础的人群。 使用场景及目标:适用于需要处理非平稳、波动剧烈的时间序列数据的场景,如电力负荷预测、金融数据分析等。主要目标是帮助读者掌握LSBoost算法的实现方法,提高时间序列预测的准确性和鲁棒性。 其他说明:文中提供的代码和技巧可以帮助读者更好地理解和应用LSBoost算法,同时强调了特征工程和模型融合的重要性。

    永磁同步电机(PMSM)滑模观测器与PLL相位补偿技术解析及应用

    内容概要:本文详细探讨了永磁同步电机(PMSM)控制系统中滑模观测器(SMO)与锁相环(PLL)相结合的技术,尤其关注相位补偿的应用。文中首先介绍了SMO的基本原理及其存在的高频抖动问题,随后提出了通过PLL进行相位补偿的方法,解决了观测波形与实际波形之间的相位滞后问题。通过加入比例积分补偿器,进一步提高了系统的稳定性和精确度。实验结果显示,在加入相位补偿后,观测波形与实际波形基本重合,转速估计更加平稳,三相电流波形也变得圆润对称。 适用人群:从事电机控制研究与开发的工程师和技术人员,尤其是对永磁同步电机控制有一定了解并希望深入理解滑模观测器和PLL相位补偿机制的人士。 使用场景及目标:适用于需要提高PMSM控制系统精度和稳定性的场合,如工业自动化设备、电动汽车驱动系统等。主要目标是解决滑模观测器输出波形与实际波形之间的相位滞后问题,从而提升整个系统的性能。 其他说明:文章提供了详细的代码片段和调试技巧,帮助读者更好地理解和实施相关技术。同时提醒了一些常见的调试陷阱,如补偿量过大导致的过冲现象以及低速时的特殊处理方式。

Global site tag (gtag.js) - Google Analytics