jsf自定义toolbar组件

<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/46860.html" frameborder="0" width="468" scrolling="no" height="60"></iframe>
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;

/***/ /**
*
@authorqinjinwei
*
*/

public class UIToolBarTag extends UIComponentTag ... {

privateStringsize;
privateStringvalue;

publicStringgetComponentType()...{
return"com.cfcc.jaf.webx.component.toolbar.UIToolBar";
}


publicStringgetRendererType()...{
returnnull;
}


publicvoidsetProperties(UIComponentcomponent)...{
super.setProperties(component);
setStringProperty(component,
"value",value);
setStringProperty(component,
"size",size);
}


privatevoidsetStringProperty(UIComponentcomponent,StringattrName,
StringattrValue)
...{
if(attrValue==null)
return;
if(isValueReference(attrValue))...{
FacesContextcontext
=FacesContext.getCurrentInstance();
Applicationapplication
=context.getApplication();
ValueBindingbinding
=application.createValueBinding(attrValue);
component.setValueBinding(attrName,binding);
}
else...{
component.getAttributes().put(attrName,attrValue);
}

}


publicvoidrelease()...{
super.release();
value
=null;
size
=null;
}


publicStringgetValue()...{
returnvalue;
}


publicvoidsetValue(Stringvalue)...{
this.value=value;
}


publicStringgetSize()...{
returnsize;
}


publicvoidsetSize(Stringsize)...{
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;

/***/ /**
*
@authorqinjinwei
*
*/

public class UIToolBar extends UICommand ... {

publicstaticfinalStringCOMPONENT_TYPE="com.cfcc.jaf.webx.component.toolbar.UIToolBar";

publicstaticfinalStringCOMPONENT_FAMILY="javax.faces.Command";

privatestaticfinalStringToolBar_Index="toolbar_index";

privatestaticStringsize=null;

privatestaticintwidth=0;

privatestaticintheight=0;

publicUIToolBar()...{
setRendererType(
null);
}


publicStringgetFamily()...{
returnCOMPONENT_FAMILY;
}


publicvoidencodeBegin(FacesContextcontext)throwsIOException...{

AddResourceaddResource
=AddResourceFactory.getInstance(context);
addResource.addJavaScriptAtPosition(context,AddResource.HEADER_BEGIN,
"js/toolbar.js");

ResponseWriterwriter
=context.getResponseWriter();
StringclientId
=getClientId(context);

FormInfoparentFormInfo
=RendererUtils.findNestingForm(this,context);
Stringname
=parentFormInfo.getFormName();

Objectobj
=getValue();
Listlist
=(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(
""+clientId+"">");
for(inti=0;ilist.size();i++)...{

ToolBarItemelement
=(ToolBarItem)list.get(i);

writeItem(writer,element,name,i);

}

writer.write(
"
");
}


writer.write(
"");
writer.write(ToolBar_Index);
writer.write(
""/>");

}


publicStringfindSize()...{
if(size!=null)
returnsize;

size
=(String)this.getAttributes().get("size");
returnsize;
}


privatevoidwriteItem(ResponseWriterwriter,ToolBarItemelement,
StringclientId,
intindex)throwsIOException...{

writer.write(
"
" );
writer.write(
" onmouseup="jump( " + " ' " + clientId + " ', " + index
+ " );" " );

writer.write(
" onmouseover="mover(this);" " );

writer.write(
" onmouseout="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(
" " );
writer.write(
" " );

}


public void decode(FacesContextcontext) ... {

Mapparameter
=context.getExternalContext().getRequestParameterMap();
Stringsi
=(String)parameter.get(ToolBar_Index);
if(si==null||si.equals(""))
return;

inti=Integer.parseInt(si);

Objectobj
=getValue();
Listlist
=(List)obj;
ToolBarItemelement
=(ToolBarItem)list.get(i);

//********************

Stringaction
=element.getAction();

MethodBindingmb;
if(NavigationMenuUtils.isValueReference(action))...{
mb
=context.getApplication().createMethodBinding(action,null);
}
else...{
mb
=newSimpleActionMethodBinding(action);
}

this.setAction(mb);

this.queueEvent(newActionEvent(this));

//************************

http://images.csdn.net/syntaxhig
分享到:
评论
happmaoo
  • 浏览: 1286413 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

你可能感兴趣的:(apache,html,.net,JSF)