📄 commandlink.jsp
字号:
<%-- tpl:insert page="/template/jsfTemplate.jtpl" --%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://www.ibm.com/jsf/html_extended" prefix="hx"%>
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM Software Development Platform">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="../theme/Master.css" rel="stylesheet" type="text/css">
<LINK href="../theme/new.css" rel="stylesheet">
<LINK rel="stylesheet" type="text/css" href="../theme/stylesheet.css" title="Style">
<%-- tpl:put name="headarea" --%>
<title>commandLink.jsp</title>
<%-- /tpl:put --%>
<LINK rel="stylesheet" type="text/css" href="/JSFandSDO/theme/stylesheet.css" title="Style">
</HEAD>
<f:view>
<BODY>
<TABLE class="title" cellpadding="0">
<TBODY>
<TR>
<TD class="noBorder" background="../images/gradient.jpg"
align="CENTER"><IMG border="0" src="../images/title.jpg"></TD>
</TR>
<TR>
<TD class="noBorder" align="RIGHT"><A href="/JSFandSDO">Return to Main Menu</A></TD>
</TR>
</TBODY>
</TABLE>
<%-- tpl:put name="bodyarea" --%>
<hx:scriptCollector id="scriptCollector1">
<h:form styleClass="form" id="form1">
<H2>Passing Data using command-Hyperlinks and output-Links</H2>
This sample demonstrates the use of command-hyperlink and output-link parameters to pass data between JSF pages.<P>When
a "More Information" link is selected, the Product ID of the
selected item is passed to the results page and is used to display
addition information about the product. The command-hyperlink will pass the Product ID as a request scope parameter, while the output-link will pass it as a URL parameter.<BR>
<BR>
<h:dataTable id="table1" value="#{pc_CommandLink.products}" var="varproducts" styleClass="dataTable" headerClass="headerClass" footerClass="footerClass" rowClasses="rowClass1, rowClass2" border="1" cellpadding="2" cellspacing="0" columnClasses="colClass1">
<h:column id="column4">
<f:facet name="header">
<h:outputText styleClass="outputText" value="Product ID" id="text7"></h:outputText>
</f:facet>
<h:outputText id="text8" value="#{varproducts.PRODUCT_ID}" styleClass="outputText">
<f:convertNumber />
</h:outputText>
</h:column>
<h:column id="column1">
<f:facet name="header">
<h:outputText styleClass="outputText" value="Product Type" id="text1"></h:outputText>
</f:facet>
<h:outputText id="text2" value="#{varproducts.PRODUCT_TYPE}" styleClass="outputText">
</h:outputText>
</h:column>
<h:column id="column2">
<f:facet name="header">
<h:outputText styleClass="outputText" value="Product Name" id="text3"></h:outputText>
</f:facet>
<h:outputText id="text4" value="#{varproducts.PRODUCT_NAME}" styleClass="outputText">
</h:outputText>
</h:column>
<h:column id="column3">
<f:facet name="header">
<h:outputText styleClass="outputText" value="Command-Hyperlink"
id="text5"></h:outputText>
</f:facet>
<%--Command-Link being created with the parameter being set to Product Id --%>
<h:commandLink styleClass="commandLink" id="link1" action="#{pc_CommandLink.doLink1Action}">
<h:outputText id="text6" styleClass="outputText" value="More Information"></h:outputText>
<f:param name="ID" value="#{varproducts.PRODUCT_ID}"></f:param>
</h:commandLink>
</h:column>
<h:column id="column5">
<f:facet name="header">
<h:outputText styleClass="outputText" value="Output-Link" id="text11"></h:outputText>
</f:facet>
<%--Output Link being created with parameter being set to product ID --%>
<hx:outputLinkEx styleClass="outputLinkEx" value="commandLinkResult.faces" id="linkEx1">
<h:outputText id="text12" styleClass="outputText" value="More Information"></h:outputText>
<f:param name="ID" value="#{varproducts.PRODUCT_ID}"></f:param>
</hx:outputLinkEx>
<f:attribute value="center" name="align" />
</h:column>
</h:dataTable></P>
<H4>How It works:</H4>
In this sample there are two levels to data passing taking place: browser to server and server to page.<BR>
<BR>
When a command-hyperlink is selected a parameter is passed from a hidden field in the browser to the server using a page POST operation. The command-hyperlink operation then places the parameter into the Request Scope of the resulting page specified by the navigation rules. <BR>
<BR>To create a navigation rule:<BR>1. Open the Properties view for the command-hyperlink.<BR> 2. Select "Add Rule". The "Add Navigation Rule" window opens.<BR>3. Enter the name of the page you want to navigate to when the link is clicked.<BR>
<BR>A command-hyperlink also returns a string value which can be used to determine which navigation rule to invoke. To set up the return string:<BR>1. Open the Quick Edit view of the command-hyperlink.<BR>2. Find the "Command" method and set the return value. When creating the navigation rule you can tell it which return string it will respond to.<BR>
<BR>
When an output-link is selected a URL parameter is passed to the server and automatically placed into the Request Scope of the resulting page using a GET operation. If you are using Output-Links you must use Page Forwarding and not Redirect or your URL parameter will be lost. <BR>
<BR>To set up the navigation for an output-link:<BR>1. Open the Properties view for the output-link.
<BR>2. Enter the URL you want the page to navigate to.<BR>
<BR>To add links to the data table, you must create a column to place them in:<BR>1. Select the data table in the Page Designer.<BR>2. Open the Properties view.<BR>3. Select "Add" next to the column table. <BR>4. Drag a command-hyperlink or link component from the JSF Palette onto the new column.<BR>
<BR>To add a parameter to a link:<BR>1. Select the link in the Page Designer.<BR>2. Open the Properties view.<BR>3. On the Parameter tab select "Add Parameter".<BR>
<BR> In this example, we bound the parameter to the Product ID of the selected row. Parameters can be accessed on the resulting page by pulling them out of the Request Parameter Scope - #{param.ID};<BLOCKQUOTE><P class="code">Command-Link Example: <BR><h:commandLink styleClass="commandLink" id="link1" action="#{pc_CommandLink.doLink1Action}"><BR>
<h:outputText id="text6" styleClass="outputText" value="More Information"></h:outputText><BR>
<f:param name="ID" value="#{varproducts.PRODUCT_ID}"></f:param><BR>
</h:commandLink></P></BLOCKQUOTE>
<BLOCKQUOTE><P class="code">Output-Link Example:<BR> <hx:outputLinkEx styleClass="outputLinkEx" value="commandLinkResult.jsp" id="linkEx1"><BR>
<h:outputText id="text12" styleClass="outputText" value="More Information"></h:outputText><BR>
<f:param name="ID" value="#{varproducts.PRODUCT_ID}"></f:param><BR>
</hx:outputLinkEx></P></BLOCKQUOTE><H4>Files
of Interest:</H4>
<UL>
<LI><B>WebContent/passData/commandLink.jsp</B> - (This Page) Where the link JSP tags are located.</LI>
<LI><B>WebContent/passData/commandLinkResult.jsp</B> -Where the result is displayed.</LI>
<LI><B>src/pagecode.passData.CommandLink.java</B> - The Page Code file for this page.</LI>
</UL>
</h:form>
</hx:scriptCollector>
<%-- /tpl:put --%>
<TABLE class="title" cellpadding="0">
<TBODY>
<TR>
<TD class="noBorder" align="RIGHT"><A href="/JSFandSDO">Return to Main Menu</A></TD>
</TR>
</TBODY>
</TABLE>
</BODY>
</f:view>
</HTML><%-- /tpl:insert --%>
<%-- jsf:pagecode language="java" location="/src/pagecode/passData/CommandLink.java" --%><%-- /jsf:pagecode --%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -