4 1 7 1 2 .c OM? E世博 登陆账户类型是信用卡还是visa借记卡哪个银行办

& “为探究微生物的抗性突变是自发产生的还是与...”习题详情
0位同学学习过此题,做题成功率0%
为探究微生物的抗性突变是自发产生的还是与相应的环境因素有关,有人设计了下列实验.实验选用对链霉紊敏感的原始大肠杆菌K12,培养基3、7、11中含有链霉素,其它培养基中不含链霉素.请回答下列问题:(1)将对链霉紊敏感的原始大肠杆菌K12菌种涂布在培养基1的表面培养,接着通过右图“印章”将培养基1中的菌群对应“印”在培养基2、3上培养.培养基3的A点处有菌落生长,将培养基2中相应的A点位置上的菌落挑出少量移入试管4中,反复几次实验,结果如图所示.请推测本实验可得出的结论是微生物的抗性突变是自发产生的&,并分析说明理由:抗链霉素菌种是从没有接触过链霉素的细菌中获得的&.(2)培养基3、7、11中的菌落具有抗链霉素&特性.逐一比较3号和2号培养基、7号和6号培养基、11号和10号培养基后发现,两培养基菌落数越来越接近,说明抗链霉素的菌种越来越纯&.此现象的形成是选择&的结果.(3)4号、8号试管在本实验中的作用是培养增加大肠杆菌的数量&.12号试管中的培养基除水、无机盐外,还必须含有碳源和氮源及琼脂(凝固剂)&等基本成分.(4)微生物实验中对培养基、接种环、实验操作者的双手通常所采用的灭菌或消毒方法的标号依次是①②③&.(①高压蒸汽灭菌&&②灼烧灭菌&&&⑨化学消毒)(5)若一培养基中有5种营养缺陷型菌株1、2、3、4、5,它们都是基因突变的结果,它们都不能合成生长所必需的物质G,已知A、B、C、D、E都是合成G物质的必需中间产物,但不知这些物质合成的顺序,于是在培养基中分别加入这几种物质并分析了这几种物质对各种营养缺陷型菌株生长的影响,结果如下表所示.那么这几种物质的合成顺序应是E-A-C-B-D-G&.
培养基中加入的物质
++:表示生长&&一:表示不生长.
本题难度:较难
题型:填空题&|&来源:2013-盐城三模
分析与解答
习题“为探究微生物的抗性突变是自发产生的还是与相应的环境因素有关,有人设计了下列实验.实验选用对链霉紊敏感的原始大肠杆菌K12,培养基3、7、11中含有链霉素,其它培养基中不含链霉素.请回答下列问题:(1)将对链霉紊...”的分析与解答如下所示:
首先把大量对链霉素敏感的大肠杆菌K12涂布在不含链霉素的平板1的表面,待其长出密集的小菌落后,用影印法接种到不含链霉素的培养基平板2上,随即再影印到含有链霉素的选择性培养基平板3上.影印的作用可保证这3个平板上所生长的菌落的亲缘和相对位置保持严格的对应性.经培养后,在平板3上出现了个别抗链霉素的菌落.对培养皿2和3进行比较,就可在平板2的相应位置上找到平板3上那几个抗性菌落的“孪生兄弟”.然后把平板2中最明显的一个部位上的菌落(实际上是许多菌落)挑至不含链霉素的培养液4中,经培养后,再涂布在平板5上,并重复以上各步骤.上述同一过程几经重复后,只要涂上越来越少的原菌液至相当于平板1的培养皿5和9中,就可出现越来越多的抗性菌落,最后甚至可以得到完全纯的抗性菌群体.由此可知,原始的链霉素敏感菌株只通过1→2→4→5→6→8→9→10→12的移种和选择序列,就可在根本未接触链霉素的情况下,筛选出大量的抗链霉素的菌株.
(1)培养基3、7、11中含有链霉素,从没有接触过链霉素的细菌接种到培养基3、7、11中,培养一段时间,在这三个培养基中有对链霉抗性大肠杆菌出现,则说明了微生物的抗性突变是自发产生的.(2)培养基3、7、11中含有链霉素,只有能对链霉素具有抗性才可以在这三个培养基中生长.2、6、10不含有链霉素,其中的菌种有抗链霉菌种和没有抗性的菌种;培养基3、7、11中含有链霉素,其中的菌种都具有抗链霉素特性.两培养基菌落数越来越接近,则说明抗链霉素的菌种越来越纯,这都是自然选择的结果.(3)4、8试管中含有该菌种生长的培养基,目的是培养大肠杆菌.培养基为微生物提供生长、繁殖和积累代谢产物的营养物质.这些物质归纳为碳源、氮源、生长因子、无机盐和水.12培养基是斜面培养基,故培养基还含有琼脂等凝固剂.(4)在微生物实验操作中,防止杂菌污染贯穿实验整个过程中.培养基是放在灭菌锅中进行高压蒸汽灭菌来灭菌.接种环和接种针需要酒精灯灼烧灭菌.实验者的双手需要用酒精灭菌.(5)G&是突变体的生长必须物质.A、B、C、D、E都是合成G物质的必需中间产物.突变体3的培养基只需要G,突变体1的培养基需要加入D和G,则说明合成顺序是D→G;突变2的培养基需要B、D、G,则说明合成顺序是B→D→G;以此类推,可知这些物质合成顺序是E-A-C-B-D-G.答案:(1)微生物的抗性突变是自发产生的 & 抗链霉素菌种是从没有接触过链霉素的细菌中获得的(2)抗链霉素&&&&抗链霉素的菌种越来越纯&&&&&&&选择(3)培养增加大肠杆菌的数量&&&&&&&&碳源和氮源及琼脂(凝固剂)(4)①②③(5)E-A-C-B-D-G
本题综合微生物的培养及实验设计和分析能力,意在考查考生能理解所学知识的要点,把握知识间的内在联系的能力;能运用所学知识与观点,对某些生物学问题进行解释、推理,做出合理的判断或得出正确的结论的能力;对实验现象和结果进行解释、分析、处理,能对一些简单的实验方案做出设计的能力.
找到答案了,赞一个
如发现试题中存在任何错误,请及时纠错告诉我们,谢谢你的支持!
为探究微生物的抗性突变是自发产生的还是与相应的环境因素有关,有人设计了下列实验.实验选用对链霉紊敏感的原始大肠杆菌K12,培养基3、7、11中含有链霉素,其它培养基中不含链霉素.请回答下列问题:(1)...
错误类型:
习题内容残缺不全
习题有文字标点错误
习题内容结构混乱
习题对应知识点不正确
分析解答残缺不全
分析解答有文字标点错误
分析解答结构混乱
习题类型错误
错误详情:
我的名号(最多30个字):
看完解答,记得给个难度评级哦!
“为探究微生物的抗性突变是自发产生的还是与...”的最新评论
欢迎来到乐乐题库,查看习题“为探究微生物的抗性突变是自发产生的还是与相应的环境因素有关,有人设计了下列实验.实验选用对链霉紊敏感的原始大肠杆菌K12,培养基3、7、11中含有链霉素,其它培养基中不含链霉素.请回答下列问题:(1)将对链霉紊敏感的原始大肠杆菌K12菌种涂布在培养基1的表面培养,接着通过右图“印章”将培养基1中的菌群对应“印”在培养基2、3上培养.培养基3的A点处有菌落生长,将培养基2中相应的A点位置上的菌落挑出少量移入试管4中,反复几次实验,结果如图所示.请推测本实验可得出的结论是____,并分析说明理由:____.(2)培养基3、7、11中的菌落具有____特性.逐一比较3号和2号培养基、7号和6号培养基、11号和10号培养基后发现,两培养基菌落数越来越接近,说明____.此现象的形成是____的结果.(3)4号、8号试管在本实验中的作用是____.12号试管中的培养基除水、无机盐外,还必须含有____等基本成分.(4)微生物实验中对培养基、接种环、实验操作者的双手通常所采用的灭菌或消毒方法的标号依次是____.(①高压蒸汽灭菌②灼烧灭菌⑨化学消毒)(5)若一培养基中有5种营养缺陷型菌株1、2、3、4、5,它们都是基因突变的结果,它们都不能合成生长所必需的物质G,已知A、B、C、D、E都是合成G物质的必需中间产物,但不知这些物质合成的顺序,于是在培养基中分别加入这几种物质并分析了这几种物质对各种营养缺陷型菌株生长的影响,结果如下表所示.那么这几种物质的合成顺序应是____.
培养基中加入的物质
++:表示生长一:表示不生长.”的答案、考点梳理,并查找与习题“为探究微生物的抗性突变是自发产生的还是与相应的环境因素有关,有人设计了下列实验.实验选用对链霉紊敏感的原始大肠杆菌K12,培养基3、7、11中含有链霉素,其它培养基中不含链霉素.请回答下列问题:(1)将对链霉紊敏感的原始大肠杆菌K12菌种涂布在培养基1的表面培养,接着通过右图“印章”将培养基1中的菌群对应“印”在培养基2、3上培养.培养基3的A点处有菌落生长,将培养基2中相应的A点位置上的菌落挑出少量移入试管4中,反复几次实验,结果如图所示.请推测本实验可得出的结论是____,并分析说明理由:____.(2)培养基3、7、11中的菌落具有____特性.逐一比较3号和2号培养基、7号和6号培养基、11号和10号培养基后发现,两培养基菌落数越来越接近,说明____.此现象的形成是____的结果.(3)4号、8号试管在本实验中的作用是____.12号试管中的培养基除水、无机盐外,还必须含有____等基本成分.(4)微生物实验中对培养基、接种环、实验操作者的双手通常所采用的灭菌或消毒方法的标号依次是____.(①高压蒸汽灭菌②灼烧灭菌⑨化学消毒)(5)若一培养基中有5种营养缺陷型菌株1、2、3、4、5,它们都是基因突变的结果,它们都不能合成生长所必需的物质G,已知A、B、C、D、E都是合成G物质的必需中间产物,但不知这些物质合成的顺序,于是在培养基中分别加入这几种物质并分析了这几种物质对各种营养缺陷型菌株生长的影响,结果如下表所示.那么这几种物质的合成顺序应是____.
培养基中加入的物质
++:表示生长一:表示不生长.”相似的习题。A short treatise on JavaServer Faces (JSF)
A short treatise onJavaServer Faces (JSF)
(random notes)
Russell Batemanlast update: 10 June 2010
JavaServer Faces (JSF) is a user-interface (UI) component based the Java web
application framework. JSF is serverbased, that is the JSF UI components and
their state are represented on the server. A JSF application run in a standard
web container, e.g.: Tomcat, GlassFish, Jetty, etc. JSF defines a standard
life-cycle for the UI components.
These notes will one day be incorporated into a formal tutorial on writing
applications using JavaServer Faces. For this reason, things get seriously
random and out-right bird-brained the further you read. It's up to you when to
stop paying attention.
Though these notes are extremely useful (to me) in sorting out problems in JSF,
a shorter, more definitive article is my
Table of Contents
a simple Java Runtime Environment (JRE) will not do
; you need both the
JSTL API and the JSTL Implementation JARs.
Consider the class Person, ...
package com.etretatlogiciels.jsf.
public class Person
String firstN
Managed beans are "plain, old Java objects" (POJOs) declared in
faces-config.xml. For example, you can define a Java object
Person. Once you define the object in faces-config.xml you use
the attributes of Person in your UI components by binding the field,
say, firstName of an object of this class to a JSF input field.
JSF uses the , used also by JSP, to bind UI components
to object attributes or methods. This "language" consists of the XML tags you
will come to recognize in the JSP/JSF code.
A managed bean is specified in faces-config.xml thus:
&managed-bean&
&managed-bean-name&
&/managed-bean-name&
&managed-bean-class&
com.etretatlogiciels.jsf.treatise.Person
&/managed-bean-class&
&managed-bean-scope&
&/managed-bean-scope&
&/managed-bean&
The various scopes available for managed beans are:
&managed-bean-scope& session|request|application|none &/managed-bean-scope&
It is the framework within the Tomcat (etc.) container that ensures the
communication of values between HTML (user/presentation) and the component
Initialization
In Eclipse, edit faces-config.xml and use the Managed Bean tab
of the editor to create of your Java class a managed bean. Use the
Initialization section to initialize the bean's properties even if
they are a Map or List. In addition to the "managed-bean"
specification (illustrated previously), a paragraph for "managed-property" can
be added that looks like this:
&managed-property&
&property-name&
&property-name&
&property-class&
com.etretatlogiciels.jsf.treatise.Person &property-class&
#{firstName}
&/managed-property&
JSP problems...
If you're missing a tag such as given in the validation warning/error:
Unknown tag (fmt:setLocale).
Unknown tag (fmt:setBundle).
Unknown tag (fmt:message).
...adding this will fix it:
&%@ taglib uri='/jstl/fmt' prefix='fmt'%&
Expression language (EL) for accessing a message bundle...
from the JSF forum on
to a question on why a piece
of code I wrote wasn't working. One article on the web induced me to think
the syntax should be
value="#{msg.login.username}"
...but this never worked in the context in which I was trying to use it.
&f:loadBundle basename="com.etretatlogiciels.dvdcatalog.messages" var="msg" /&
&td& &h:outputText
value="#{msg['login.username']}" /& &/td&
&td& &h:inputText id="loginname" value="#{Login.name}" /&
These are just warnings that nothing's been set in web.xml and a default
Millions of console nastygrams launching JSP
This is probably due to a "java.lang.StackOverflowError".
INFO: Server startup in 984 ms
May 3, :45 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet faces threw exception
java.lang.StackOverflowError
at org.apache.catalina.core.ApplicationHttpRequest.getAttributeNames(ApplicationHttpRequest.java:243)
at org.apache.catalina.core.ApplicationHttpRequest$AttributeNamesEnumerator.(ApplicationHttpRequest.java:905)
at org.apache.catalina.core.ApplicationHttpRequest.getAttributeNames(ApplicationHttpRequest.java:243)
This arises from having duplicate &servlet& entries in
web.xml, such as:
You cannot configure faces for .jsp and .jsf. I've
found that not defining .jsp that way is the solution. For a Faces
application, it's not necessary even though you might be led to think it is by
reason of the presence of .jsp files (and not files extended with
"ALT attribute" warning
If you're missing the alt attribute on an image, you'll get this
WARN - ALT attribute is missing for : j_id_jsp__2
Add it thus:
&h:graphicImage value="#{msg['dvdcatalog.logo']}" alt="[dvdcatalog-logo.png]" /&
Exception "final block not properly padded"
After typing in username and password, you get this:
INFO: Server startup in 1000 ms
ERROR - An exception occurred
javax.faces.FacesException: javax.crypto.BadPaddingException: Given final block not properly padded
at org.apache.myfaces.shared_impl.util.StateUtils.symmetric(StateUtils.java:474)
at org.apache.myfaces.shared_impl.util.StateUtils.symmetric(StateUtils.java:512)
I added this to web.xml. It opens a security hole, but it appears to be
a bug in MyFaces.
&context-param&
&description&
This is my attempt to get rid of the
javax.faces.FacesException: javax.crypto.BadPaddingException: Given final
block not properly padded problem.
&/description&
&param-name&org.apache.myfaces.USE_ENCRYPTION&/param-name&
&param-value&false
&/context-param&
Exception "invalid stream header: 70DB8AB1"
After typing in username and password, you get this:
INFO: Server startup in 1009 ms
ERROR - An exception occurred
javax.faces.FacesException: java.io.StreamCorruptedException: invalid stream header: 70DB8AB1
at org.apache.myfaces.shared_impl.util.StateUtils.getAsObject(StateUtils.java:374)
at org.apache.myfaces.shared_impl.util.StateUtils.reconstruct(StateUtils.java:264)
I found no solution to this. I went back to a working JSF project (not the same
one) to see how it worked. It magically had this same problem. So, I bounced
Eclipse passing the -clean option. That cleared both the old, good project and
my new one. Incidentally, the old project didn't have the web.xml
work-around for the "final block not properly padded" problem, so that was a
red herring too.
is a great page to use for
composing various controls as it has the JSF expressions, a visual example
of each, plus the HTML code generated. Sadly, it lacks the corresponding
bean code.
Hair-pulling over selectOneListbox
My very first attempt at this "advanced" JSF skill. Imagine a section of JSF
code such as:
&h:selectOneMenu id="shippingOption"
required="true"
value="#{cashier.shippingOption}"&
&f:selectItem itemValue="2" itemLabel="#{bundle.QuickShip}"/&
&f:selectItem itemValue="5" itemLabel="#{bundle.NormalShip}"/&
&f:selectItem itemValue="7" itemLabel="#{bundle.SaverShip}"/&
&/h:selectOneMenu&
Here is the property, in CashierBean.java corresponding to this tag:
protected String shippingOption = "2";
public void
setShippingOption( String shippingOption ) { this.shippingOption = shippingO }
public String getShippingOption()
{ return this.shippingO }
That was one example I found by Googling, and the only one (believe it or not)
that revealed its backing-bean code. The others just gave the JSF and assumed
the bean code was simple, clear and unworthy to be featured. Of course, they
assumed I already knew how this selectOneListbox construct worked
while I needed just a bit more help piercing the veil.
I resorted there especially in an attempt to resolve an Eclipse JSP/JSF
validation error in view.jsp, "JSF attribute expects settable value but
expression is not settable". I couldn't get what goes into value just
right. You see the shippingOption in
value="#{cashier.shippingOption}" is crucial.
It's not just the initial value to display in the drop-down menu when it hits
the browser, but also must be able to gather that value if
changed. This input/output relationship in JSF is wired delicately on the
backing bean's getters and setters, in this case, getShippingOption()
and setShippingOption().
In my own code, selecting different types of query filters went like this:
&h:selectOneListbox size="1"
&%-- (show only one option at a time) --%&
title="#{msg['view.filter_prompt']}"
value="#{queryBean.filterMethod}"&
&f:selectItems value="#{queryBean.filterMethodsList}"/&
&/h:selectOneListbox&
This is, I believe, correct. My backing bean is where I had the trouble and was
either crashing or, more frequently, merely in some infinite, "I'll never
display anything" loop. Here's how it started out the first time it didn't
crash or loop out:
QueryBean.java:
private String
filterMethod
private static LinkedHashMap filterMethods =
redoMessages();
// (default initialization of messages)
public static void redoMessages() // (ChangeLocaleBean.xxAction() calls this when the locale has changed)
filterMethods = new LinkedHashMap();
filterMethods.put( 1, getGenericMessage( "view.filter.all"
filterMethods.put( 2, getGenericMessage( "view.filter.year"
filterMethods.put( 3, getGenericMessage( "view.filter.rating"
filterMethods.put( 4, getGenericMessage( "view.filter.genre"
filterMethods.put( 5, getGenericMessage( "view.filter.language" ) );
// this is for handling the &h:selectOneListbox value=...& construct
public void
setFilterMethod( String newMethod )
{ this.filterMethod = newM }
public String getFilterMethod()
{ return this.filterM
// this is for building the &f:selectItems ...& construct
public Map getFilterMethodsList()
{ return filterM
This gave me:
Of course, I want very different things in the filter drop-down list, so I
reverse the order thinking I'll get my strings instead of the numbers. On my
second try, which was to change the type from
& Integer, String & to
& String, Integer &&how I wanted it in the first
place, I got a crash instead:
I think the important part of the error is "value is no String" which is why I
had changed it to the "unlikely" order in the first place. Another key part of
the error is "HtmlSelectOneListbox" which tells me to look at my
&h:selectOneListbox ...& construct instead of the
&f:selectItems ...& construct to find the problem.
But, what's the solution?
On my third try, I changed
& String, Integer & to
& String, String & and then adjusted other code:
QueryBean.java:
filterMethods = new LinkedHashMap();
filterMethods.put( getGenericMessage( "view.filter.all" ),
filterMethods.put( getGenericMessage( "view.filter.year" ),
filterMethods.put( getGenericMessage( "view.filter.rating" ),
filterMethods.put( getGenericMessage( "view.filter.genre" ),
filterMethods.put( getGenericMessage( "view.filter.language" ), "5" );
...and I got the following, which is closer, missing only the localization:
I went to add the ratings drop-down. I copied the filter method work and then
ran only to get:
The reason I'm reproducing this here is out of honesty and to expose another
sort of error, as stupid as it might be. In this instance, I failed to add the
first line of code here and there was no list ready for items to be put to.
QueryBean.java:
ratings = new LinkedHashMap();
ratings.put( getGenericMessage( "view.rating.NR" ),
ratings.put( getGenericMessage( "view.rating.G" ),
ratings.put( getGenericMessage( "view.rating.PG" ),
ratings.put( getGenericMessage( "view.rating.PG_13" ), "4" );
ratings.put( getGenericMessage( "view.rating.NC_17" ), "5" );
ratings.put( getGenericMessage( "view.rating.R" ),
The line number in the error doesn't correspond to where the new JSF code was
put for the rating drop-down, but here. Line 27 isn't too enlightening, but
think about it: changing the locale is what reaches the Java code above. (Or, I
it's the same.)
Making large-scale changes such as these may not even appear in the browser
when you run the JSP. When this happens, do the following, including the last
one when it just really persists:
Ensure that all files (*.jsp, *.java, etc.) are saved.
Select the project and press F5 (for refresh).
Pull down the Project menu and choose Clean to rebuild
the project.
Right-click the server in the Server view (pane) and
Stop, then Clean and Start it again.
Now switching our year list from selectOneListbox to
selectManyListbox, we crash with this error, doubtless linked to what
we need to do beyond how the other kind of list is done.
This is because we're not passing the right sort of animal to value;
it's going to be different from what we pass to selectOneListbox.
Please study the code below for the differences between
selectOneListbox and selectManyListbox.
Then see the result which has been heavily reformatted to make room for
everything. Also, the years field became something that will have to be
parsed (and therefore some kind of high-level SQL statement), and the "many"
list boxes cannot (apparently) be scrollable. Or can they? I need to
investigate.
QueryBean.java:
public class QueryBean
private static Logger
log = Logger.getLogger( MessageBean.class );
private static Locale
private static String
bundleName =
private String
filterMethod
private static LinkedHashMap
filterMethods =
private String[]
private static LinkedHashMap
ratingsItems
private String[]
private static LinkedHashMap
genreItems
private String[]
private static LinkedHashMap
languageItems =
private String
private static LinkedHashMap
private String
redoMessages();
private static final void getFacesContext()
FacesContext context = FacesContext.getCurrentInstance();
if( context != null )
= context.getViewRoot().getLocale();
bundleName = context.getApplication().getMessageBundle();
* Call this when the locale has changed.
public static void redoMessages()
getFacesContext();
if( locale == null || bundleName == null )
( "Redoing messages..." );
filterMethods = new LinkedHashMap();
filterMethods.put( getGenericMessage( "view.filter.all" ),
filterMethods.put( getGenericMessage( "view.filter.year" ),
filterMethods.put( getGenericMessage( "view.filter.rating" ),
filterMethods.put( getGenericMessage( "view.filter.genre" ),
filterMethods.put( getGenericMessage( "view.filter.language" ), "5" );
ratingsItems = new LinkedHashMap();
ratingsItems.put( getGenericMessage( "view.rating.NR" ),
ratingsItems.put( getGenericMessage( "view.rating.G" ),
ratingsItems.put( getGenericMessage( "view.rating.PG" ),
ratingsItems.put( getGenericMessage( "view.rating.PG_13" ), "4" );
ratingsItems.put( getGenericMessage( "view.rating.NC_17" ), "5" );
ratingsItems.put( getGenericMessage( "view.rating.R" ),
genreItems = new LinkedHashMap();
genreItems.put( getGenericMessage( "view.genre.action" ),
genreItems.put( getGenericMessage( "view.genre.adventure" ), "2" );
genreItems.put( getGenericMessage( "view.genre.allegory" ),
genreItems.put( getGenericMessage( "view.genre.cartoon" ),
genreItems.put( getGenericMessage( "view.genre.chick" ),
genreItems.put( getGenericMessage( "edy" ),
genreItems.put( getGenericMessage( "view.genre.drama" ),
genreItems.put( getGenericMessage( "view.genre.fantasy" ),
genreItems.put( getGenericMessage( "view.genre.history" ),
genreItems.put( getGenericMessage( "view.genre.military" ),
genreItems.put( getGenericMessage( "view.genre.music" ),
genreItems.put( getGenericMessage( "view.genre.musical" ),
genreItems.put( getGenericMessage( "view.genre.mystery" ),
genreItems.put( getGenericMessage( "view.genre.politics" ),
genreItems.put( getGenericMessage( "view.genre.religious" ), "15" );
genreItems.put( getGenericMessage( "view.genre.science" ),
genreItems.put( getGenericMessage( "view.genre.suspense" ),
genreItems.put( getGenericMessage( "view.genre.thriller" ),
languageItems = new LinkedHashMap();
languageItems.put( getGenericMessage( "view.language.chinese" ),
languageItems.put( getGenericMessage( "view.language.finnish" ),
languageItems.put( getGenericMessage( "view.language.french" ),
languageItems.put( getGenericMessage( "view.language.german" ),
languageItems.put( getGenericMessage( "view.language.greek" ),
languageItems.put( getGenericMessage( "view.language.italian" ),
languageItems.put( getGenericMessage( "view.language.japanese" ),
languageItems.put( getGenericMessage( "view.language.korean" ),
languageItems.put( getGenericMessage( "view.language.portuguese" ),"pt" );
languageItems.put( getGenericMessage( "view.language.russian" ),
languageItems.put( getGenericMessage( "view.language.spanish" ),
languageItems.put( getGenericMessage( "view.language.thai" ),
sortings = new LinkedHashMap();
sortings.put( getGenericMessage( "view.sort.title" ), "1" );
sortings.put( getGenericMessage( "view.sort.year" ),
sortings.put( getGenericMessage( "view.sort.rating" ),"3" );
// this is for handling the &h:selectOneListbox value=...& construct for filter methods...
public void
setFilterMethod( String newValue ) { this.filterMethod = newV }
public String getFilterMethod()
{ return this.filterM
// this is for building the &f:selectItems ...& construct
public Map getFilterMethodsList() { return filterM
// this is for handling the &h:selectManyListbox value=...& construct for ratings...
public void
setRatings( String[] newValue )
{ this.ratings = newV }
public String[] getRatings()
{ return this.
// this is for building the &f:selectItems ...& construct
public Map getRatingsItems() { return ratingsI
// and for genre (etc.)...
public void
setGenres( String[] newValue ) { this.genres = newV
public String[] getGenres()
{ return this.
public Map getGenreItems()
{ return genreI
// and for languages...
public void
setLanguages( String[] newValue ) { this.languages = newV
public String[] getLanguages()
{ return this.
public Map getLanguagesItems()
{ return languageI
// and for sortings...
public void
setSortedBy( String newValue )
{ this.sortedBy = newV }
public String getSortedBy()
{ return this.sortedBy;
public Map getSortingsList()
public void
setYears( String newValue ) { this.years = newV }
public String getYears()
{ return this.
private static final String getGenericMessage( String messageKey )
String text = MessageUtils.getMessageResourceString( bundleName, messageKey, null, locale );
if( text == null )
text = "No message bundle or no property \"dvdcatalog.title\"";
...and the JSF code illustrates outputText, inputText,
selectOneListbox, selectManyListbox and selectItems:
styles.css:
.gutter { width: 20 }
.query-prompt
font-size:
font-weight:
text-align:
&h2& &h:outputText value="#{msg['dvdcatalog.title']}" /& &/h2&
&div class="textbox"&
&h:outputText value="#{msg['view.last']}" /&
&h:outputText value=" #{statisticsBean.lastUpdate}" /&
&h:outputText value="#{msg['view.total']}" /&
&h:outputText value=" #{statisticsBean.totalTitles}" /&
&h:outputText value="#{msg['view.foreign']}" /&
&h:outputText value=" #{statisticsBean.totalForeignTitles}" /&
&p class="notes"&
&h:outputText value="#{msg['view.legend']}" /&&
&h:outputText value="#{msg['view.notes_1']}" /&&
&h:outputText value="#{msg['view.notes_2']}" /&
&tr&&td class="query-prompt"&
&%-- Filter this list by: --%&
&h:outputText value="#{msg['view.filter_prompt']}" /& &
&h:selectOneListbox size="1"
title="#{msg['view.filter_prompt']}"
value="#{queryBean.filterMethod}"&
&f:selectItems value="#{queryBean.filterMethodsList}"/&
&/h:selectOneListbox&
&td class="gutter"&
&td class="query-prompt"&
&%-- Sort this list by: --%&
&h:outputText value="#{msg['view.sort_prompt']}" /& &
&h:selectOneListbox size="1"
title="#{msg['view.sort_prompt']}"
value="#{queryBean.sortedBy}"&
&f:selectItems value="#{queryBean.sortingsList}"/&
&/h:selectOneListbox&
&tr&&td& & &/td&&/tr&
&tr&&td valign="top"&
&tr&&td valign="top"&
&tr&&td class="query-prompt" valign="top"&
&%-- Rating: --%&
&h:outputText value="#{msg['view.rating_prompt']}" /&
&td valign="top"&
&h:selectManyListbox title="#{msg['view.rating_prompt']}"
value="#{queryBean.ratings}"&
&f:selectItems value="#{queryBean.ratingsItems}"/&
&/h:selectManyListbox&
&tr&&td& & &/td&
&td class="query-prompt" valign="top"&
&%-- Years: --%&
&h:outputText value="#{msg['view.year_prompt']}" /& &
&h:inputText value="#{queryBean.years}" /&
&td class="gutter"&
&td class="query-prompt" valign="top"&
&%-- Genre: --%&
&h:outputText value="#{msg['view.genre_prompt']}" /& &
&td valign="top"&
&h:selectManyListbox title="#{msg['view.genre_prompt']}"
value="#{queryBean.genres}"&
&f:selectItems value="#{queryBean.genreItems}"/&
&/h:selectManyListbox&
&td class="gutter"&
&td class="query-prompt" valign="top"&
&%-- Language: --%&
&h:outputText value="#{msg['view.language_prompt']}" /& &
&td valign="top"&
&h:selectManyListbox title="#{msg['view.language_prompt']}"
value="#{queryBean.languages}"&
&f:selectItems value="#{queryBean.languagesItems}"/&
&/h:selectManyListbox&
&tr&&td colspan="3" /&
&td colspan="3" align="center"&
&tr&&td&[button]&/td&
&td class="gutter"&&/td&
&td&[button]&/td&
very handy when I was pulling my hair out over my initial
selectOneListbox
&About JavaServer
Pages Standard Tags Library.
rendering JSF.
on creating a JSF web app in 10 it doesn't work, but it's got
some useful information.
JSF tutorial.
slide presentation with real wish I had seen this
years ago.
The value attribute of HTML (JSF) tags
It's easy to get lost in all the attributes passed to the likes of
outputLabel
inputSecret
commandButton
commandLink
selectOneListbox
selectManyListbox
Here's how I think of it: Consider what the construct does. If it's just to
force some string to the page when renderedi or it's the title of a control
(button or link), then the value attribute is likely going to be an
expression that evaluates to a string, number or graphic. It probably comes out
of messages.properties or similar file.
&h:outputLabel value="#{msg.username}" /&
This includes command links and buttons because of the text item associated
with them.
On the other hand, if the tag is looking for dynamically created values (at
run-time), it likely indicates a bean property (method). For example, here,
the first value is a list of supported
(or considered) languages that could (or may not necessarily) fluctuate at
The second value is an array of the
same languages, except as items in a selection control and it is composed for
being set (as state) in the bean. It is the "result" of the user's answering
the form. So, when done, it's a list of zero, one or more languages. From the
bean, the code...
private String[]
languages = { "French", "Latin", "Greek", "German" };
private static LinkedHashMap& String, String & languageItems =
languageItems = new LinkedHashMap& String, String &();
languageItems.put( getGenericMessage( "view.language.french" ), "fr" );
languageItems.put( getGenericMessage( "view.language.french" ), "la" );
languageItems.put( getGenericMessage( "view.language.french" ), "el" );
languageItems.put( getGenericMessage( "view.language.french" ), "de" );
public String[]
getLanguages() { return this. }
public Map& String, String & getLanguageItems() { return languageI }
...underlies the JSF constructs. languages may be initialized
statically at compile-time or at run-time or even dynamically at run-time.
&h:selectManyListbox title="#{msg['view.language_prompt']}"
value="#{queryBean.languages}"&
&f:selectItems value="#{queryBean.languageItems}" /&
&/h:selectManyListbox&
. This may also affect
selectOneListbox.
The action attribute of HTML (JSF) tags
The action attribute is always going to be a bean method that returns
&h:commandButton value="#{msg['view.reset_button']}"
action="#{queryBean.clear}"
type="reset" /&
The "action" method is going to return a String. This is all important
since it's this string that determines JSF navigation as described in the
from-outcome element of the navigation-case of a
navigation-rule in faces-config.xml.
public String clear()
( "Resetting query parameters..." );
this.filter
this.languages =
return "reset";
It's important to note that the type attribute of an
&h:commandButton& can never be anything but "submit" or "reset".
documentation.
Continuing DVD catalog UI development
Set up navigation to look like this:
You can do this visually using the faces-config.xml
Navigation Rule editor or simply add these lines to
faces-config.xml by hand:
/login.jsp
/validlogin.jsp
/login.jsp
/invalidlogin.jsp
/login.jsp
/powerlogin.jsp
validlogin
/validlogin.jsp
/query.jsp
powerlogin
/powerlogin.jsp
/query.jsp
/query.jsp
/query.jsp
Note: The "power-login" stuff is for a putative power user that will have the
ability to add, delete or modify entries in the database. This work won't
appear in this tutorial, but is already stubbed in and I don't want to remove
Here's the log-in page. You can control the user interface lnaguage at this
point (and again from the query page).
And here's the welcome page. It for me, a power user and signals this by
reprising a line from Hunt for Red October.
The ordinary welcome page appears thus&without the power statement about
being authorized to launch missiles.
If we had failed, if we had entered user "snagglepuss" with password "the
lion", we'd have seen an error message on the login page rather than
invalidlogin.jsp getting used. We may take out this additional, unused
Finally, clicking with a valid log-in on the Configure query button
gets us to our more or less finished and working query page. We just have to
write and debug our view page and wire up the Hibernate guts.
Notes on tags
for entry point to both h and f
Notes on construct &dataTable ...&
A good reference
The Javadoc is at
Use of attribute var
is not required
must evaluate to String
the name of a request-scope attribute under which the model data for
the row selected by the current value of the rowIndex property
will be exposed.
Use it as a "cookie" according to the following pseudocode. Imagine a Java
class, TupleBean, that returns tuples by name and value. The utility
of prefacing the cookie name with an underscore, as suggested by one tutorial I
read, is to avoid it confusing the reader with other entities (classes,
methods, bean names, etc.). TupleBean furnishes the getters
getName() and getValue().
&h:dataTable var="_tuple"
value="#{tupleBean.all}"&
&h:column&
&f:facet name="header"&
&h:outputText value="Name" /&
&/f:facet&
&h:outputText value="#{_tuple.name}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="Value" /&
&/f:facet&
&h:outputText value="#{_tuple.value}" /&
&/h:column&
&/h:dataTable&
Note: if the table as displayed is empty, it's only because the
getAll() method (from TupleBean) failed to produce any rows.
Sample rendering of an &h:dataTable&
Consider the following &h:dataTable& construct from a JSF file.
This should help you visualize how what's coded in JSF and CSS is used to
generate the page dynamically.
&h:dataTable value="#{dvdTitle.all}"
var="_title"
styleClass="dvdStyles"
headerClass="dvdHeader"
columnClasses="dvdId,dvdBluray,dvdTitle,dvdYear,dvdMinutes,dvdRating,dvdGenre,dvdLanguage,dvdUrl,dvdStars"
rowClasses="oddRow,evenRow"&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.id']}" /&
&/f:facet&
&h:outputText value="#{_title.id}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.bluray']}" /&
&/f:facet&
&h:outputText value="#{_title.getBluray}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.title']}" /&
&/f:facet&
&h:outputText value="#{_title.title}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.year']}" /&
&/f:facet&
&h:outputText value="#{_title.year}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.minutes']}" /&
&/f:facet&
&h:outputText value="#{_title.minutes}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.rating']}" /&
&/f:facet&
&h:outputText value="#{_title.rating}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.genre']}" /&
&/f:facet&
&h:outputText value="#{_title.genre}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.language']}" /&
&/f:facet&
&h:outputText value="#{_title.language}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.url']}" /&
&/f:facet&
&h:outputText value="#{_title.url}" /&
&/h:column&
&h:column&
&f:facet name="header"&
&h:outputText value="#{msg['view.stars']}" /&
&/f:facet&
&h:outputText value="#{_title.stars}" /&
&/h:column&
&/h:dataTable&
Notice that each element (data cell, header, etc. has its own style setting).
The &f:facet& tag is either "header" or "footer" ("caption",
etc.) and thus the dvdHeader style class is associated with our usage
(we have no footer material here). This is what's generated for display in the
&table class="dvdStyles"&
&th class="dvdHeader" scope="col"& id
&th class="dvdHeader" scope="col"& Blu-ray?
&th class="dvdHeader" scope="col"& Title
&th class="dvdHeader" scope="col"& Year
&th class="dvdHeader" scope="col"& Length
&th class="dvdHeader" scope="col"& Rating
&th class="dvdHeader" scope="col"& Genres
&th class="dvdHeader" scope="col"& Languages &/th&
&th class="dvdHeader" scope="col"& Link
&th class="dvdHeader" scope="col"& Stars
&tbody id="j_id_jsp_:j_id_jsp_:tbody_element"&
&tr class="oddRow"&
&td class="dvdId"&
&td class="dvdBluray"&
&td class="dvdTitle"&
Lord of the Rings: Fellowship of the Ring&/td&
&td class="dvdYear"&
&td class="dvdMinutes"& 180
&td class="dvdRating"&
&td class="dvdGenre"&
&td class="dvdLanguage"&Spanish
&td class="dvdUrl"&
www.lordoftherings.net
&td class="dvdStars"&
Elijah Wood, Sean Austin, Dominique Monahan, Billy Boyd, Viggo Mortensen, Sean Bean, Orlando Gibbons, John Rhys-Davies, Ian McKellen&/td&
&tr class="evenRow"&
&td class="dvdId"&
&td class="dvdBluray"&
&td class="dvdTitle"&
Lord of the Rings: The Two Towers&/td&
&td class="dvdYear"&
&td class="dvdMinutes"& 180
&td class="dvdRating"&
&td class="dvdGenre"&
&td class="dvdLanguage"&Spanish
&td class="dvdUrl"&
www.lordoftherings.net
&td class="dvdStars"&
Elijah Wood, Sean Austin, Dominique Monahan, Billy Boyd, Viggo Mortensen, Sean Bean, Orlando Gibbons, John Rhys-Davies, Ian McKellen&/td&
And here is the relevant portion of the cascading-styles sheet:
/* DVD titles list... */
.dvdStyles /* class for the &table& tag rendering an &h:dataTable& */
.dvdHeader /* class for &th& tags in the &thead& rendering an &h:dataTable& */
text-align:
vertical-align: text-
font-style:
text-align:
text-align:
.dvdBluray { width: 80 }
.dvdYear { width: 20 }
.dvdMinutes { width: 20 }
.dvdRating { width: 20 }
.dvdGenre { width: 80 }
.dvdLanguage{ width: 80 }
{ width: 80 }
.dvdStars { width: 80 }
background-image: url('bg1.jpg');
background-image: url('bg2.jpg');
Appendix: view.jsp
Here's the view page at one point with four titles in the database, JSF and CSS
work done closer to what I hope to end up with. Notice that the "Movie site"
links are actual links and if you click on them, they take you to the movie
site (if the link isn't stale or bogus).
Appendix: web.xml
This is the application's web.xml that works both for the Tomcat Eclipse
uses and the "real" one installed. Despite the *.jsf entry below, we
have only .jsp this works anyway and, in fact, does not if we
change the entry to specify .jsp.
&?xml version="1.0" encoding="UTF-8"?&
&web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="/xml/ns/javaee"
xmlns:web="/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="/xml/ns/javaee
/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID"
version="2.5"&
&display-name&dvdcatalog&/display-name&
&welcome-file-list&
&welcome-file&index.html&/welcome-file&
&welcome-file&index.htm&/welcome-file&
&welcome-file&index.jsp&/welcome-file&
&welcome-file&default.html&/welcome-file&
&welcome-file&default.htm&/welcome-file&
&welcome-file&default.jsp&/welcome-file&
&/welcome-file-list&
&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&/faces/*&/url-pattern&
&/servlet-mapping&
&context-param&
&param-name&javax.servlet.jsp.jstl.fmt.localizationContext&/param-name&
&param-value&resources.application&/param-value&
&/context-param&
&context-param&
&param-name&javax.faces.STATE_SAVING_METHOD&/param-name&
&param-value&client&/param-value&
&/context-param&
&context-param&
&param-name&org.apache.myfaces.ALLOW_JAVASCRIPT&/param-name&
&param-value&true&/param-value&
&/context-param&
&context-param&
&param-name&org.apache.myfaces.PRETTY_HTML&/param-name&
&param-value&true&/param-value&
&/context-param&
&context-param&
&param-name&org.apache.myfaces.DETECT_JAVASCRIPT&/param-name&
&param-value&false&/param-value&
&/context-param&
&context-param&
&param-name&org.apache.myfaces.AUTO_SCROLL&/param-name&
&param-value&true&/param-value&
&/context-param&
&servlet-name&faces&/servlet-name&
&servlet-class&org.apache.myfaces.webapp.MyFacesServlet&/servlet-class&
&load-on-startup&1&/load-on-startup&
&/servlet&
&servlet-mapping&
&servlet-name&faces&/servlet-name&
&url-pattern&*.jsf&/url-pattern&
&/servlet-mapping&
&servlet-mapping&
&servlet-name&faces&/servlet-name&
&url-pattern&*.faces&/url-pattern&
&/servlet-mapping&
&listener&
&listener-class&org.apache.myfaces.webapp.StartupServletContextListener&/listener-class&
&/listener&
&context-param&
&param-name&org.apache.myfaces.USE_ENCRYPTION&/param-name&
&param-value&false&/param-value&
&/context-param&
&/web-app&
Appendix: Where to find deployment?
Eclipse deploys to "its" Tomcat on a peculiar path. It's sometimes useful to go
looking for this in diagnosing problems such as working on a project from more
than one computer (say, at work and at home). The path to which Eclipse deploys
your web application is as shown below and has the structure, part of which
depends on your application packages obviously, shown:
C:\Users\russ\dev\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps&tree
Folder PATH listing
Volume serial number is BE79-0AEB
+---dvdcatalog
+---images
+---META-INF
+---styles
+---WEB-INF
+---classes
+---etretatlogiciels
+---dvdcatalog
+---schema
+---validator
+---WEB-INF
For example, dvdcatalog, my web application, uses a number of user libraries
all of which are copied to ..../dvdcatalog/WEB-INF/lib. The name of
the user library (as defined by me in Eclipse Build Path) is given in
443,432 antlr-2.7.6.jar
322,362 cglib-nodep-2.2.jar
188,671 commons-beanutils-1.7.0.jar
[JSF 1.2 (Apache MyFaces)]
46,725 commons-codec-1.3.jar
[JSF 1.2 (Apache MyFaces)]
559,366 commons-collections-3.1.jar
[JSF 1.2 (Apache MyFaces)]
571,259 commons-collections-3.2.jar
[JSF 1.2 (Apache MyFaces)]
143,602 commons-digester-1.8.jar
[JSF 1.2 (Apache MyFaces)]
76,685 commons-discovery-0.4.jar
[JSF 1.2 (Apache MyFaces)]
60,686 commons-logging-1.1.1.jar
[JSF 1.2 (Apache MyFaces)]
313,898 dom4j-1.6.1.jar
[Hibernate 3.5.1]
3,893,179 hibernate3.jar
[Hibernate 3.5.1]
597,476 javassist-3.9.0.GA.jar
[Hibernate 3.5.1]
153,115 jdom-1.1.jar
56,702 jettison-1.0.1.jar
534,827 joda-time-1.6.jar
30,691 jstl-api-1.2.jar
[JSTL 1.2]
392,435 jstl-impl-1.2.jar
[JSTL 1.2]
10,899 jta-1.1.jar
[Hibernate 3.5.1]
391,834 log4j-1.2.15.jar
378,921 myfaces-api-1.2.8.jar
[JSF 1.2 (Apache MyFaces)]
801,254 myfaces-impl-1.2.8.jar
[JSF 1.2 (Apache MyFaces)]
732,695 mysql-connector-java-5.1.12-bin.jar
[MySQL JDBC Driver]
23,445 slf4j-api-1.5.8.jar
[Hibernate 3.5.1]
7,600 slf4j-simple-1.5.11.jar
179,346 stax-1.2.0.jar
26,514 stax-api-1.0.1.jar
520,969 wstx-asl-3.2.7.jar
5,234 xml-writer-0.2.jar
431,568 xom-1.1.jar
24,956 xpp3_min-1.1.4c.jar
431,406 xstream-1.3.1.jar
31 File(s)
12,351,752 bytes
If I'm getting ClassNotFound exceptions, something that seems to
plague JSTL, and don't have the same libraries on both computers (work and
home), this is a place to start asking why.
Appendix: &h:panelGrid&
The preferred way in JSF to create grid alignment is to use this construct.
However, it is very weak (JSF 1.2) as compared to, say,
&dataTable& in that it's not really possible to get
vertical-align: top onto the &td& elements generated.
If you don't care to align things to the top, then it doesn't matter. Here's
how you should do it:
&h:panelGrid columns="3" rowStyles="query-prompt,query-prompt,query-prompt"&
&h:panelGroup style="query-prompt"&
&h:panelGrid rowClasses="query-prompt,query-prompt,query-prompt" styleClass="query-prompt"&
&h:panelGroup style="query-prompt"&
&h:outputText value="#{msg['query.rating_prompt']}" /& &
&h:selectManyListbox title="#{msg['query.rating_prompt']}"
value="#{queryBean.ratings}"&
&f:selectItems value="#{queryBean.ratingsItems}" /&
&/h:selectManyListbox&
&/h:panelGroup&
&h:panelGroup style="query-prompt"&
&h:outputText value="#{msg['query.year_prompt']}" /& &
&h:inputText value="#{queryBean.years}" /&
&/h:panelGroup&
&/h:panelGrid&
&/h:panelGroup&
&h:panelGroup style="query-prompt"&
&h:outputText value="#{msg['query.genre_prompt']}" /& &
&h:selectManyListbox title="#{msg['query.genre_prompt']}"
value="#{queryBean.genres}"&
&f:selectItems value="#{queryBean.genreItems}" /&
&/h:selectManyListbox&
&/h:panelGroup&
&h:panelGroup style="query-prompt"&
&h:outputText value="#{msg['query.language_prompt']}" /& &
&h:selectManyListbox title="#{msg['query.language_prompt']}"
value="#{queryBean.languages}"&
&f:selectItems value="#{queryBean.languageItems}" /&
&/h:selectManyListbox&
&/h:panelGroup&
&/h:panelGrid&
Instead, despite opinions to the contrary, the good old HTML construct,
&table& turned out still to be the best. (Note that CSS class
query-prompt contains vertical-align: top.
&td class="query-prompt"&
&%-- column 1 --%&
&td class="query-prompt"&
&h:outputText value="#{msg['query.rating_prompt']}" /& &
&td class="query-prompt"&
&h:selectManyListbox title="#{msg['query.rating_prompt']}"
value="#{queryBean.ratings}"&
&f:selectItems value="#{queryBean.ratingsItems}" /&
&/h:selectManyListbox&
&td& &br /& &/td&
&td class="query-prompt"&
&h:outputText value="#{msg['query.year_prompt']}" /& &
&td class="query-prompt"&
&h:inputText value="#{queryBean.years}" /&
&td class="query-prompt"&
&%-- column 2 --%&
&%-- Genre: --%&
&td class="query-prompt"&
&h:outputText value="#{msg['query.genre_prompt']}" /& &
&td class="query-prompt"&
&h:selectManyListbox title="#{msg['query.genre_prompt']}"
value="#{queryBean.genres}"&
&f:selectItems value="#{queryBean.genreItems}" /&
&/h:selectManyListbox&
&td class="query-prompt"&
&%-- column 3 --%&
&%-- Language: --%&
&td class="query-prompt"&
&h:outputText value="#{msg['query.language_prompt']}" /& &
&td class="query-prompt"&
&h:selectManyListbox title="#{msg['query.language_prompt']}"
value="#{queryBean.languages}"&
&f:selectItems value="#{queryBean.languageItems}" /&
&/h:selectManyListbox&
Of course, this last representation is what gives us:
...instead of seeing the prompts at the bottom of the lists instead of the top.
Appendix: Fixing navigation problems
faces-config.xml describes where link- and button-clicks will take the
user, in general, but there is also corresponding information in two places
that tie the elements of navigation together.
In this discussion, we'll be talking about exactly three buttons on two pages.
The pages inter-refer in that one leads to the other and the other gives the
option to return to the first starting over as if just getting there.
Here are two pages, query.jsp and view.jsp. The user tailors the
query on the first and clicks either a button, Reset Query, that calls
QueryBean.clear() and whose result it isn't necessary to specify here
(a sort of internal operation), or Submit Query, which takes him to
the viewing page where the results of the query will be displayed.
faces-config.xml
&navigation-rule&
&display-name&
&/display-name&
&from-view-id&
/query.jsp
&/from-view-id&
&navigation-case&
&from-outcome&
&/from-outcome&
&to-view-id&
&/to-view-id&
&/navigation-case&
&/navigation-rule&
&navigation-rule&
&display-name&
&/display-name&
&from-view-id&
&/from-view-id&
&navigation-case&
&from-outcome&
&/from-outcome&
&to-view-id&
/query.jsp
&/to-view-id&
&/navigation-case&
&/navigation-rule&
The JSP file
For the navigation rule above, here's what to expect in terms of JSF code.
One button submits the query as configured on this page navigating to the view
page where an &h:dataTable& displays the results. The other
button zeroes out the configuration so the user can start over tailoring his
query. The second button does not need to "go anywhere" despite a type
of "reset".
&h:commandButton value="#{msg['query.submit_button']}"
action="#{queryBean.submitQuery}"
type="submit" /&
&h:commandButton value="#{msg['query.reset_button']}"
action="#{queryBean.clear}"
type="reset" /&
This button, Reset Query, returns the user to the previous (query)
&h:commandButton value="#{msg['query.reset_button']}"
action="#{queryBean.clear}"
type="query" /&
The Java bean
The query bean code establishes the query in a static place where the schema
bean, in this case, the one that defines and handles the DVD catalog table, can
find and consume it.
Note the strings returned from Java. To a old C programmer, this looks cheesy,
but it's critically necessary. These strings must match
The type attribute in the JSF button (or link) construct of the
JSP file as shown above.
The from-outcome element of the navigation-case in
faces-config.xml (also as shown above).
The return string of the bean action (method) noted in the JSF code. See
QueryBean.java
public String clear()
( "Resetting query parameters..." );
this.ratings
this.genres
this.languages =
this.sortedBy
this.years
return "query";
public String submitQuery()
( "Submitting request..." );
chosenSortedBy = new String( this.sortedBy );
chosenYears
= new String( this.years );
String[] newArray =
= this.ratings.
newArray = new String[ length ];
System.arraycopy( this.ratings, 0, newArray, 0, length );
chosenRatings = newA
= this.genres.
newArray = new String[ length ];
System.arraycopy( this.genres, 0, newArray, 0, length );
chosenGenres = newA
= this.languages.
newArray = new String[ length ];
System.arraycopy( this.languages, 0, newArray, 0, length );
chosenLanguages = newA
( "--------- To be sorted by: " + this.sortedBy );
( "---------
Ratings: " + Arrays.toString( this.ratings ) );
( "---------
Genres: " + Arrays.toString( this.genres ) );
( "---------
Languages: " + Arrays.toString( this.languages ) );
( "---------
Years: " + this.years );
return "submit";
Displaying the results
DvdTitle.java
For reference, here is one working incantation of the getAll() method
invoked by view.jsp's &h:dataTable&.
public Result getAll() throws SQLException, NamingException
( "Performing SQL select to build view.jsp..." );
ResultSet rs
String[] ratings
= QueryBean.getChosenRatings(),
= QueryBean.getChosenGenres(),
languages = QueryBean.getChosenLanguages();
= QueryBean.getChosenYears(),
= QueryBean.getChosenSortedBy();
openConnection();
Statement stmt = this.conn.createStatement();
== null || ratings.length
&& ( genres
== null || genres.length
&& ( languages == null || languages.length == 0 )
&& ( years
== null || years.length()
// the query isn't to be qualified in any way...
query = "SELECT * FROM " + TABLE_NAME;
if( sortedBy != null )
query += " ORDER BY " + sortedBy;
query += ";";
( query );
rs = stmt.executeQuery( query );
= ResultSupport.toResult( rs );
if( r == null )
( "Query returned nothing." );
// these are crucial to helping us build SQL syntax in the query...
boolean gotRating
boolean gotGenre
boolean gotLanguage =
// the query will be qualified in some way...
query = "SELECT * FROM " + TABLE_NAME + " WHERE ";
if( ratings != null && ratings.length > 0 )
// Ratings, could be one or more: [g, pg, pg-13, r]
for( String rating : ratings )
query += ( gotRating ) ? " OR " : "( ";
query += RATING + " = '" + rating + "'";
gotRating =
if( gotRating )
query += " )";
if( genres != null && genres.length > 0 )
if( gotRating )
query += " AND ";
// Genres, could be one or more: [action, drama, history, music, politics, suspense]
for( String genre : genres )
query += ( gotGenre ) ? " OR " : "( ";
query += GENRE + " = '" + genre + "'";
gotGenre =
if( gotGenre )
query += " )";
if( languages != null && languages.length > 0 )
if( gotRating || gotGenre )
query += " AND ";
// Languages, could be one or more: [su, el, it, ja, pt]
for( String language : languages )
query += ( gotLanguage ) ? " OR " : "( ";
query += LANGUAGE + " = '" + language + "'";
gotLanguage =
if( gotLanguage )
query += " )";
/* Do years stuff here--very ugly, very nasty.
* What we support, e.g.:
* single year, i.e.: 2010
* year range, i.e.:
* year list, i.e.: , 1997
* What is used here, no matter how simple or complex, is an array.
String[] yearList = getYearQuery( years );
if( yearList != null && yearList.length > 0 )
if( gotRating || gotGenre || gotLanguage )
query += " AND ";
if( yearList.length == 3 && yearList[ 1 ].equals( "-" ) )
// manufacture a BETWEEN query
query += YEAR + " BETWEEN '" + yearList[ 0 ] + "' AND '" + yearList[ 2 ] + "'";
// manufacture an OR ... OR ... OR ... query
boolean gotYear =
for( String y : yearList )
query += ( gotYear ) ? " OR " : "( ";
query += YEAR + " = '" + y + "'";
if( gotYear )
query += " )";
if( sortedBy != null )
query += " ORDER BY " + sortedBy;
query += ";";
( query );
rs = stmt.executeQuery( query );
= ResultSupport.toResult( rs );
if( r == null )
( "Query returned nothing." );
Here's how to display the results in JSF.
&h:dataTable value="#{dvdTitle.all}"
var="_title"
styleClass="dvdStyles"
headerClass="dvdHeader"
rowClasses="oddRow,evenRow"&
&h:column&
&div style="margin-left: 10px"&
&span style="font-style: italic"&
&h:outputText value="#{_title.title}" /&
&h:outputText value="(#{_title.year})" /&
&h:outputText value="#{_title.minutes} #{msg['view.minutes.prompt']}" /&
&h:outputText value="#{_title.rating}" /&
&%-- &h:outputText value=", #{_title.genre}" /& --%&
&h:outputText value="#{msg['view.languages']} " /&
&h:outputText value="#{_title.language}" /&
&h:outputText value="#{msg['view.site.prompt']}" /&
&h:outputText value="#{_title.url}" /&
&p&&h:outputText value="#{msg['view.stars']}" /&&/p&
&p style="margin-left: 20px"&
&h:outputText value="#{_title.stars}" /&
&/h:column&
&/h:dataTable&
Getters take no argument
Early on, in imitation of view.jsp's value attribute to
&h:dataTable&, "#{dvdTitle.all}", I unthinkingly added such a
reference to an additional method that looked for just one title and returned a
Result. The problem was that this method originally took String
title. Hence, it was not a "property". I got:
ERROR - An exception occurred
org.apache.jasper.el.JspPropertyNotFoundException: /view-one.jsp(38,1) '#{dvdTitle.single}' Property 'single' not found on \
type com.etretatlogiciels.dvdcatalog.schema.DvdTitle
Later, as I struggled with it, I began to get another warning in the JSP:
'single' cannot be resolved as a member of 'DvdTitle'
This was solved of course by removing the argument. A property, by definition,
has a getter and a setter. This is a getter and must have no argument.
Ultimately, peace ensued in view-one.jsp:
view-one.jsp
&%-- usually this is just one other film, but it can be more --%&
&h:dataTable value="#{dvdTitle.single}"
var="_title"
styleClass="dvdStyles"
headerClass="dvdHeader"
rowClasses="oddRow,evenRow"&
&h:column&
At this point, view-one.jsp presents the option of adding the new title
despite its already existing or returning to addtitle.jsp to add a
different title.
We're obviously adding the power user stuff (by which the power user can add
titles to the database). Later, addtitle.jsp will be linked to via a
button from powerlogin.jsp.
Solution to &h:commandButton...& in view-one.jsp
The button "not to add" a duplicate DVD title to the database on this page
would not work with type as "reset" and, of course, the button to add
it anyway was typed "submit". The solution, after exploring
immediate="true", changing the bean type for AddBean to
"request" or "none" from "session", etc. was the third possible option, that
is, "button". Prior to this, clicking on it resulted in nothing, not even
AddBean.clear() was called.
See discussion at
&%-- Don't Add This Title --%&
&h:commandButton value="#{msg['view-one.reset_button']}"
action="#{addBean.clear}"
type="button" /&
&%-- Add This Title --%&
&h:commandButton value="#{msg['view-one.confirm_button']}"
action="#{addBean.retainAddition}"
type="submit" /&
The final navigation
Here's a representation of the final details of application navigation (between
What's left to do?
The following, whether we do them or not, are left to do to make this a real
application.
Add the ability to identify, then delete unwanted titles by the power
Flesh out the genre and language tables and connect them up with the
titles table. Write SQL statements in consequence. Answer the question,
"Do these need a junction table?"
Move authentication to the (or a) database.
Enhance messaging in the application (via
&h:message[s]...&, etc.)
Deploy to Tomcat 6.

我要回帖

更多关于 visa借记卡 的文章

 

随机推荐