下拉列表(drop-down list)
<h:selectone_menu>标记用于生成包含几个颜色选项的下拉列表。
<h:selectitem>标记包含在<h:selectone_menu>中,作为下拉列表的选项:
<f:use_faces>
<h:form formname="pform">
..........
<p><h:output_text value="color:"/><br>
<h:selectone_menu id="color" valueref="pbean.color">
<f:validate_required/>
<h:selectitem itemvalue="black" itemlabel="black"/>
<h:selectitem itemvalue="red" itemlabel="red"/>
<h:selectitem itemvalue="blue" itemlabel="blue"/>
<h:selectitem itemvalue="green" itemlabel="green"/>
</h:selectone_menu>
<br><h:output_errors for="color"/>
..........
</h:form>
</f:use_faces>
<form method="post" action="/usingjsf/faces/edit.jsp">
..........
<p>color:<br>
<select name="color" size="1">
<option value="black">black</option>
<option value="red">red</option>
<option value="blue">blue</option>
<option value="green" selected>green</option>
</select>
<br>
..........
</form>
public class pbean implements java.io.serializable {
..........
private string color;
public string getcolor() {
return color;
}
public void setcolor(string color) {
this.color = color;
}
..........
}
<f:use_faces>
<h:form formname="pform">
..........
<p><h:output_text value="alignment:"/><br>
<h:selectone_radio id="align" valueref="pbean.align"
layout="line_direction">
<f:validate_required/>
<h:selectitem itemvalue="left" itemlabel="left"/>
<h:selectitem itemvalue="center" itemlabel="center"/>
<h:selectitem itemvalue="right" itemlabel="right"/>
</h:selectone_radio>
<br><h:output_errors for="align"/>
..........
</h:form>
</f:use_faces>
<form method="post" action="/usingjsf/faces/edit.jsp">
..........
<p>alignment:<br>
<table border="0">
<tr>
<td><input type="radio" checked
name="align" value="left"> left</td>
<td><input type="radio"
name="align" value="center"> center</td>
<td><input type="radio"
name="align" value="right"> right</td>
</tr>
</table>
<br>
..........
</form>
public class pbean implements java.io.serializable {
..........
private string align;
public string getalign() {
return align;
}
public void setalign(string align) {
this.align = align;
}
..........
}
<f:use_faces>
<h:form formname="pform">
..........
<p><h:output_text value="style:"/><br>
<h:panel_grid columns="3" border="0" cellspacing="5">
<h:panel_group>
<h:selectboolean_checkbox id="bold"
valueref="pbean.bold"/>
<h:output_text value="bold"/>
</h:panel_group>
<h:panel_group>
<h:selectboolean_checkbox id="italic"
valueref="pbean.italic"/>
<h:output_text value="italic"/>
</h:panel_group>
<h:panel_group>
<h:selectboolean_checkbox id="underline"
valueref="pbean.underline"/>
<h:output_text value="underline"/>
</h:panel_group>
</h:panel_grid>
..........
</h:form>
</f:use_faces>
<form method="post" action="/usingjsf/faces/edit.jsp">
..........
<p>style:<br>
<table border="0" cellspacing="5">
<tr>
<td><input type="checkbox"
name="bold">bold</td>
<td><input type="checkbox"
name="italic" checked>italic</td>
<td><input type="checkbox"
name="underline">underline</td>
</tr>
</table>
..........
</form>
public class pbean implements java.io.serializable {
..........
private boolean bold;
public boolean isbold() {
return bold;
}
public void setbold(boolean bold) {
this.bold = bold;
}
private boolean italic;
public boolean isitalic() {
return italic;
}
public void setitalic(boolean italic) {
this.italic = italic;
}
private boolean underline;
public boolean isunderline() {
return underline;
}
public void setunderline(boolean underline) {
this.underline = underline;
}
..........
}
..........
<faces-config>
<navigation-rule>
<from-tree-id>/edit.jsp</from-tree-id>
<navigation-case>
<from-outcome>editoutcome</from-outcome>
<to-tree-id>/edit.jsp</to-tree-id>
</navigation-case>
<navigation-case>
<from-outcome>viewoutcome</from-outcome>
<to-tree-id>/view.jsp</to-tree-id>
</navigation-case>
</navigation-rule>
..........
</faces-config>
<f:use_faces>
<h:form formname="pform">
..........
<p>
<h:command_button id="view" label="view"
commandname="viewcmd" action="viewoutcome"/>
<h:command_button id="bolduppercase"
label="bold upper case / view"
commandname="bolduppercasecmd"
actionref="pbean.bolduppercaseaction"/>
</h:form>
</f:use_faces>
<form method="post" action="/usingjsf/faces/edit.jsp">
..........
<p>
<input type="submit" name="view" value="view">
<input type="submit" name="bolduppercase"
value="bold upper case / view">
</form>
public class pbean implements java.io.serializable {
..........
public bolduppercaseaction getbolduppercaseaction() {
return new bolduppercaseaction();
}
public class bolduppercaseaction
extends javax.faces.application.action {
public string invoke() {
string uctext = gettext().touppercase();
if (isbold() && gettext().equals(uctext))
return "viewoutcome";
else {
setbold(true);
settext(uctext);
return "editoutcome";
}
}
}
}
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器