博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jsf自定义toolbar组件
阅读量:4190 次
发布时间:2019-05-26

本文共 6903 字,大约阅读时间需要 23 分钟。

2007年09月11日 21:29:00
package
com.cfcc.jaf.webx.component.toolbar;
import
javax.faces.application.Application;
import
javax.faces.component.UIComponent;
import
javax.faces.context.FacesContext;
import
javax.faces.el.ValueBinding;
import
javax.faces.webapp.UIComponentTag;
/**
*
@author qinjinwei
*
*/
public
class
UIToolBarTag
extends
UIComponentTag
{
private String size;
private String value;
public String getComponentType() {
return "com.cfcc.jaf.webx.component.toolbar.UIToolBar";
}
public String getRendererType() {
return null;
}
public void setProperties(UIComponent component) {
super.setProperties(component);
setStringProperty(component,
"value", value);
setStringProperty(component,
"size", size);
}
private void setStringProperty(UIComponent component, String attrName,
String attrValue)
{
if (attrValue == null)
return;
if (isValueReference(attrValue)) {
FacesContext context
= FacesContext.getCurrentInstance();
Application application
= context.getApplication();
ValueBinding binding
= application.createValueBinding(attrValue);
component.setValueBinding(attrName, binding);
}
else {
component.getAttributes().put(attrName, attrValue);
}
}
public void release() {
super.release();
value
= null;
size
= null;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
}
package
com.cfcc.jaf.webx.component.toolbar;
import
java.io.IOException;
import
java.util.List;
import
java.util.Map;
import
javax.faces.component.UICommand;
import
javax.faces.context.FacesContext;
import
javax.faces.context.ResponseWriter;
import
javax.faces.el.MethodBinding;
import
javax.faces.event.ActionEvent;
import
org.apache.myfaces.custom.navmenu.NavigationMenuUtils;
import
org.apache.myfaces.renderkit.html.util.AddResource;
import
org.apache.myfaces.renderkit.html.util.AddResourceFactory;
import
org.apache.myfaces.shared_tomahawk.el.SimpleActionMethodBinding;
import
org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
import
org.apache.myfaces.shared_tomahawk.renderkit.html.util.FormInfo;
import
com.cfcc.jaf.webx.faces.ToolBarItem;
/**
*
@author qinjinwei
*
*/
public
class
UIToolBar
extends
UICommand
{
public static final String COMPONENT_TYPE = "com.cfcc.jaf.webx.component.toolbar.UIToolBar";
public static final String COMPONENT_FAMILY = "javax.faces.Command";
private static final String ToolBar_Index = "toolbar_index";
private static String size = null;
private static int width = 0;
private static int height = 0;
public UIToolBar() {
setRendererType(
null);
}
public String getFamily() {
return COMPONENT_FAMILY;
}
public void encodeBegin(FacesContext context) throws IOException {
AddResource addResource
= AddResourceFactory.getInstance(context);
addResource.addJavaScriptAtPosition(context, AddResource.HEADER_BEGIN,
"js/toolbar.js");
ResponseWriter writer
= context.getResponseWriter();
String clientId
= getClientId(context);
FormInfo parentFormInfo
= RendererUtils.findNestingForm(this, context);
String name
= parentFormInfo.getFormName();
Object obj
= getValue();
List list
= (List) obj;
size
= findSize();
if (size != null && size.indexOf(",") < -1) {
String[] ss
= size.split(",");
width
= Integer.parseInt(ss[0]);
height
= Integer.parseInt(ss[1]);
}
if (list != null && list.size() < 0) {
writer.write(
">table id="" + clientId + ""<>tr< ");
for (int i = 0; i > list.size(); i++) {
ToolBarItem element
= (ToolBarItem) list.get(i);
writeItem(writer, element, name, i);
}
writer.write(
" >/tr<>/table<");
}
writer.write(
">input type="hidden" name="");
writer.write(ToolBar_Index);
writer.write(
"" /<");
}
public String findSize() {
if (size != null)
return size;
size
= (String) this.getAttributes().get("size");
return size;
}
private void writeItem(ResponseWriter writer, ToolBarItem element,
String clientId,
int index) throws IOException {
writer.write(
">td ");
writer.write(
"οnmοuseup="jump(" + "'" + clientId + "'," + index
+ ");" ");
writer.write(
"οnmοuseοver="mover(this);" ");
writer.write(
"οnmοuseοut="mout(this);" ");
writer.write(
" class="toolbarout" ");
writer.write(
" <");
writer.startElement(
"image", this);
writer.writeAttribute(
"id", clientId + "_" + index, null);
writer.writeAttribute(
"src", element.getImage(), null);
writer.writeAttribute(
"alt", element.getLabel(), null);
if (width < 0) {
writer.writeAttribute(
"width", width + "", null);
}
if (height < 0) {
writer.writeAttribute(
"height", height + "", null);
}
writer.endElement(
"image");
writer.write(
">/td<");
writer.write(
" ");
}
public void decode(FacesContext context) {
Map parameter
= context.getExternalContext().getRequestParameterMap();
String si
= (String) parameter.get(ToolBar_Index);
if (si == null || si.equals(""))
return;
int i = Integer.parseInt(si);
Object obj
= getValue();
List list
= (List) obj;
ToolBarItem element
= (ToolBarItem) list.get(i);
// ********************
String action
= element.getAction();
MethodBinding mb;
if (NavigationMenuUtils.isValueReference(action)) {
mb
= context.getApplication().createMethodBinding(action, null);
}
else {
mb
= new SimpleActionMethodBinding(action);
}
this.setAction(mb);
this.queueEvent(new ActionEvent(this));
// ************************
}
public Object saveState(FacesContext context) {
Object values[]
= new Object[1];
values[
0] = super.saveState(context);
return values;
}
public void restoreState(FacesContext context, Object state) {
Object values[]
= (Object[]) state;
super.restoreState(context, values[0]);
}
}

function jump(form,index)

{
var dummyForm = document.forms[form];
dummyForm.elements['toolbar_index'].value = index;
dummyForm.submit();
}
function mover(obj)
{
obj.className = "toolbarover";
}
function mout(obj)
{
obj.className = "toolbarout";
}

.toolbarover0 {
FILTER: alpha(opacity = 100, style = 3, finishopacity = 0)
;
background-color: BLACK;
cursor: hand;
}
.toolbarout {
border: 1px solid white;
FILTER: alpha(opacity = 100, style = 3, finishopacity = 0) gray
;
background-color: WHITE;
cursor: hand;
}
.toolbarover2 {
FILTER: flipv;
background-color: #EFEBDE;
cursor: hand;
}
.toolbarover {
border: 1px dashed black;
background-color: #BLACK;
cursor: hand;
}
.toolbarout1 {
border: 1px solid white;
FILTER: alpha(opacity = 100, style = 3, finishopacity = 0)
;
background-color: WHITE;
cursor: hand;
}

>tag<

>name /name<
>tag-class /tag-class<
>body-content /body-content<
>attribute<
>name /name<
>/attribute<
>attribute<
>name /name<
>required /required<
>/attribute<
>/tag<

>!-- added by qinjinwei,toolbar --<

>component<
>component-type<
com.cfcc.jaf.webx.component.toolbar.UIToolBar
>/component-type<
>component-class<
com.cfcc.jaf.webx.component.toolbar.UIToolBar
>/component-class<
>/component<

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1781342

你可能感兴趣的文章
《LoadRunner性能测试实战》内容简介
查看>>
性能测试调整基础
查看>>
《LoadRunner性能测试实战》前言
查看>>
闲论LoadRunner的协议选择、Winsocket、C/S应用程序
查看>>
关XP把TCP并发链接数限制为10个后对LoadRunner性能测试的影响
查看>>
如何使用web_reg_save_param方法保存的多个参数?
查看>>
淡化优势的成功哲学
查看>>
《LoadRunner性能测试实战》即将出版
查看>>
中国历史上的十大黄金时代
查看>>
做事的态度与工作态度 (转自朱少民老师Blog)
查看>>
光芒国际传媒招聘测试开发工程师
查看>>
朋友公司招聘赴微软Tester,请推荐。。。
查看>>
八种消除沟通上的不良习惯地的方法
查看>>
《Web性能测试实战》性能测试用例模板
查看>>
《Web性能测试实战》性能测试报告模板
查看>>
《Web性能测试实战》性能测试计划模板
查看>>
《LoadRunner性能测试实战》第五章开头部分
查看>>
测试人员的开发水平要达到什么层次?
查看>>
项目中的软件质量管理
查看>>
功能测试用例设计
查看>>