在设计程序的时候遇到这样一个问题。如果你要删除一条数据的时候,当你点击删除的时候,先要求要弹出一个窗口,问你是否要删除,然后点击确定的时候才把之前的数据删除掉。如果点击取消,那么就取消删除。

在richfaces等都找不到有这样功能的组建,所以就要自己来写一个有这样功能的组建呢。要自己写一个组建,可以分为3步。
第一步:在WEB-INF中的web.xml文件中,加入
<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/myTag.module.xml</param-value>
</context-param>
第二步:在WEB-INF目录下创建myTag.module.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://www.goldeninfo.net/myTag</namespace>
<tag>
<tag-name>sureRemove</tag-name>
<source>../components/sureRemove.xhtml</source>
</tag>
</facelet-taglib>
需要注意的几点是:
<namespace>http://www.goldeninfo.net/myTag</namespace>是你在页面上引用的路径,
<tag-name>sureRemove</tag-name>是组建的名字,
<source>../components/sureRemove.xhtml</source>是要引用的页面。

第三步:创建sureRemove.xhtml模板
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:s="http://jboss.com/products/seam/taglib"
xmlns:a4j="http://richfaces.org/a4j">
<a4j:loadStyle src="/img/images/style.css" />
<c:if test="#{empty msg}">
<c:set var="msg" value="确定要删除该信息吗??"/>
</c:if>
<c:if test="#{empty title}">
<c:set var="title" value="删除对话框"/>
</c:if>
<c:if test="#{empty value}">
<c:set var="value" value="删除"/>
</c:if>
<c:if test="#{empty rendered}">
<c:set var="rendered" value="true"/>
</c:if>
<c:choose>
<c:when test="#{type eq 'link'}" >
<c:set var="link_rendered" value="#{rendered and true}"/>
</c:when>
<c:when test="#{type eq 'button'}" >
<c:set var="button_rendered" value="#{rendered and true}"/>
</c:when>
<c:otherwise>
<c:set var="link_rendered" value="#{rendered and true}"/>
</c:otherwise>
</c:choose>
<a4j:commandLink value="#{value}" oncomplete="#{rich:component('delPanel')}.show()" rendered="#{link_rendered}"/>
<a4j:commandButton value="#{value}" oncomplete="#{rich:component('delPanel')}.show()" rendered="#{button_rendered}"/>
<rich:modalPanel id="delPanel" autosized="true" width="180" styleClass="mp1">
<f:facet name="header">
<h:outputText value="#{title}" />
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/img/guanbi.gif" style="cursor: pointer" onclick="#{rich:component('delPanel')}.hide();"/>
</h:panelGroup>
</f:facet>
<span class="mpMessage" />
<a4j:region id="globalMPRegion3">
<s:div id="globalMPInclude3" styleClass="modalPanelContent">
<table width="100%">
<tbody>
<tr>
<td colspan="2" align="center"><h:outputText value="#{msg}" /></td>
</tr>
<tr>
<td align="center" width="50%">
<a4j:commandButton value="确定" action="#{bean[action]}" oncomplete="#{rich:component('delPanel')}.hide();" reRender="#{reRender}" eventsQueue="queue">
<ui:insert/>
</a4j:commandButton>
</td>
<td align="center" width="50%">
<a4j:commandButton value="取消" onclick="#{rich:component('delPanel')}.hide();return false;" eventsQueue="queue"/>
</td>
</tr>
</tbody>
</table>
</s:div>
</a4j:region>
</rich:modalPanel>
</ui:composition>
在***.xhtml页面上,先用引入这个组件名
xmlns:mt=http://www.goldeninfo.net/myTag
,在页面上这样调用
<mt:sureRemove type="link" rendered="true" action="delete"
bean="#{pages.HomePage}">
其中bean是指那个组建名,action是方法名.
type为组件的外形。如果type的值为link,那么组建的显示外形是和链接一样的形状,如果type的值为button,那么组建的现实外形是和按钮一样的形状。

- 大小: 6.9 KB

- 大小: 17.7 KB