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