<f:view encoding="utf-8" locale="#{staff.language}">
<h:outputText value="#{staff.errMsg}" style="color:red"/><p/>想請教下這個staff是在哪裡定義的?
解决方案 »
- 关于struts2标签的两个问题
- JSP论坛的发帖问题
- tomcat 提示No Java compiler was found错误,困惑N久(解决马上给分)
- SSH jsp页面得不到Action的值!急
- 用java如何实现论坛的消息互发
- 想写个大型的论坛 精确的需求分析 优秀的系统设计 强健的系统 优秀的伸缩性 合理的开发时间 我给不起报酬 需要各样人才加入
- 怎么根据第一个select的值改变第二个select的内容?
- 创建表的怪SQL语句, 怎么解释....
- 近日想求购关于SERVLET、JSP的书,麻烦各位给点意见。谢谢!
- 新手学习struts2提供的上传但是娶不到上传的文件
- 使用Jquery返回实体类,在页面怎么获取实体类的属性???
- 高人指点下maven2的使用
具体你还要看看faces-config.xml里面这个页面Managed Beans里面关联哪个bean类了!
<?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_2_0.xsd"
version="2.0"> <application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
<locale-config>
<default-locale>en</default-locale>
<supported-locale>th</supported-locale>
<supported-locale>zh_CN</supported-locale>
<supported-locale>zh_HK</supported-locale>
</locale-config>
<resource-bundle>
<base-name>com.toysrus.quiz.ui.UIControl</base-name>
<var>uic</var>
</resource-bundle>
</application> <!--
========================= navigation-rule
=============================
-->
<navigation-rule>
<from-view-id>/staffInfo.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/showQuestion.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/staffInfo.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/showQuestion.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/checkAnswer.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/login.xhtml</to-view-id>
</navigation-case>
</navigation-rule> </faces-config>也沒看出在哪里定義了這個staff 實體類 這個uic倒是看到了 有的是這么用的 #{uic.admin_region}
可是staff實在是沒看出來怎么弄
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF\applicationContext.xml;WEB-INF\applicationContext-security.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener</listener-class>
</listener> <!-- place constraints on a single user's ability to log in to your application -->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener> <filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- DelegatingFilterProxy delegates to a filter implementation which is defined as a Spring bean in your APP
web security are configured using http element-->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter> <filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping> <servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping> <servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet> <servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping> <resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the configurartion for the web application.
</description>
<res-ref-name>jdbc/QuizAdmin</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list></web-app>
我看了半天看不明白 在另外一個項目里面也有類似的應用 #{admin. 什么什么的 跟這個#{staff.什么的類似 我都不知道這個實體是什么類型的
而且好像和spring整合后,#{}能调用spring定义的bean,request\session\application的bean也可以调用。只是不能自动生成新的对象
很有可能是用annotation定义的staff。
比如:@ManagedBean(name="staff")
@SessionScoped
public class StaffBean {
// some code...
}这种情况,在faces-config.xml中是找不到staff的定义的,因此只能在代码中去找了。(在JSF1.2中不能用此种方法)
比如說這個頁面 用到了staff這個類的<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core" template="template.xhtml">
<ui:define name="head">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</ui:define>
<ui:define name="content">
<f:view encoding="utf-8" locale="#{staff.language}">
<table width="700px" align="center">
<c:if test="${staff.language=='th_TH'}">
<tr>
<td><h:outputText value="Welcome" /><h:outputText
value=", ${staff.userName}" /></td>
</tr>
<tr></tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_description} เกรด 4 และสูงกว่าทั้งหมดควรตอบคำถาม" /></td>
</tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_description2} ประกอบด้วยคำตอบให้เลือก 10 คำถาม กรุณาอ่านคำถามอย่างรอบคอบและเลือกคำตอบที่ถูกต้อง" /></td>
</tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_passingRate} ผ่านระดับ: 8" /></td>
</tr>
<tr>
<td height="20px"></td>
</tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_fill} กรุณากรอกข้อมูลของคุณ" /></td>
</tr>
</c:if>
<c:if test="${staff.language=='zh_CN' || staff.language=='zh_HK' || staff.language=='en'}">
<tr>
<td><h:outputText value="Welcome" /><h:outputText
value=", ${staff.userName}" /></td>
</tr>
<tr></tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_description}" /></td>
</tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_description2} " /></td>
</tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_passingRate} " /></td>
</tr>
<tr>
<td height="20px"></td>
</tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_fill}" /></td>
</tr>
</c:if>
</table>
<h:form method="post" id="staffForm" prependId="false">
<table width="700px" align="center">
<tr>
<td>
<table width="80%" align="center">
<tr>
<td width="30%"><h:outputText
value="#{uic.staffInfo_region}" /></td>
<td><h:selectOneMenu id="region"
value="#{staff.staffRegion}">
<f:selectItem itemLabel="HK" itemValue="HK" />
<f:selectItem itemLabel="China" itemValue="CN" />
<f:selectItem itemLabel="Thailand" itemValue="TH" />
<f:selectItem itemLabel="Singapore" itemValue="SG" />
<f:selectItem itemLabel="Malaysia" itemValue="MY" />
<f:selectItem itemLabel="Taiwan" itemValue="TW" />
</h:selectOneMenu></td>
</tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_name}" /></td>
<td><h:inputText name="staffName" id="staffName"
value="#{staff.staffName}" required="true"
requiredMessage="Full Name is required" /></td>
</tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_staffID}" /></td>
<td><h:inputText name="staffID" id="staffID"
value="#{staff.staffNo}" required="true"
requiredMessage="Staff Number is required" /></td>
</tr>
<tr>
<td><h:outputText value="#{uic.staffInfo_division}" /></td>
<td><h:selectOneMenu id="division"
value="#{staff.staffDivision}">
<f:selectItem itemLabel="Management" itemValue="Management" />
<f:selectItem itemLabel="Store Planning"
itemValue="Store Planning" />
<f:selectItem itemLabel="Administration"
itemValue="Administration" />
<f:selectItem itemLabel="Customer Service/ Call Centre"
itemValue="Customer Service/ Call Centre" />
<f:selectItem itemLabel="Marketing" itemValue="Marketing" />
<f:selectItem itemLabel="Logistic and Inventory Control"
itemValue="Logistic and Inventory Control" />
<f:selectItem itemLabel="Sales and Merchandising"
itemValue="Sales and Merchandising" />
<f:selectItem itemLabel="Quality Assurance"
itemValue="Quality Assurance" />
<f:selectItem itemLabel="Human Resource"
itemValue="Human Resource" />
<f:selectItem itemLabel="Information Technology"
itemValue="Information Technology" />
<f:selectItem itemLabel="Finance & Accounting"
itemValue="Finance & Accounting" />
<f:selectItem itemLabel="Store Operations - Stores"
itemValue="Store Operations - Stores" />
<f:selectItem itemLabel="Store Operations - Office"
itemValue="Store Operations - Office" />
</h:selectOneMenu></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height="20px"></td>
</tr>
<tr>
<td align="center"><h:commandButton type="submit"
value="#{uic.staffInfo_start}" action="#{staff.startQuiz}" /></td>
</tr>
</table>
</h:form>
</f:view>
</ui:define>
</ui:composition>
去哪裡順著找你所說的bean呢?
在1.2时代,我们这样写一个bean:public class StaffBean {
// some code here
}然后在faces-config.xml中描述它:
<managed-bean>
<managed-bean-name>staff</managed-bean-name>
<managed-bean-class>Staff</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
我们要去找staff的时候,去faces-config.xml中去看就知道了。可是在JSF2.0中,如果我们用annotation,bean就是这样写了:@ManagedBean(name="staff")
@SessionScoped
public class StaffBean {
// some code here
}
这种情况下要去找staff在那里定义的,只好一个一个地去查看java源文件了。不过呢,JSF2在使用annotation时有一个规则很有用:如果在用@ManagedBean没有指定name属性时,直接用类名来作为name(将类名的首字母自动小写)。如:@ManagedBean
@SessionScoped
public class Staff {
// some code here
}
这种情况,一个名为staff的变量就自动定义在session里了。建议在JSF2中使用annotation的时候用这种方式,这时候要去找staff的话只需要去找叫Staff的java文件。