1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
| public class UIMenuItem extends UIComponentBase {
/**
* Level minimum to access.
*/
private String levelMin;
/**
* ID.
*/
private String id;
/**
* StyleClass.
*/
private String styleClass;
/**
* Value;
*/
private String value;
/**
* Action.
*/
private String action;
/**
* @see javax.faces.component.UIComponent#getFamily()
*/
@Override
public String getFamily() {
return "menuItem";
}
/**
* @see javax.faces.component.UIComponentBase#encodeEnd(javax.faces.context.FacesContext)
*/
public void encodeEnd(FacesContext facesContext) throws IOException {
ResponseWriter responseWriter = facesContext.getResponseWriter();
String clientId = this.getClientId(facesContext);
this.levelMin = (String) FacesUtil.getValueOfElExp((String) this.getAttributes().get("levelMin"));
this.id = (String) FacesUtil.getValueOfElExp((String) this.getAttributes().get("id"));
this.styleClass = (String) FacesUtil.getValueOfElExp((String) this.getAttributes().get("styleClass"));
this.value = (String) FacesUtil.getValueOfElExp((String) this.getAttributes().get("value"));
String active = (String) FacesUtil.getValueOfElExp((String) this.getParent().getAttributes().get("activeStyleClass"));
if (active != null) {
if ((this.styleClass != null) && (isCurrentPage(this.id))) {
this.styleClass = this.styleClass + " " + active;
} else if ((this.styleClass == null) && (isCurrentPage(this.id))) {
this.styleClass = active;
}
}
UserController usrCtrl = (UserController) FacesUtil.getBean("userCtrl");
if (usrCtrl.getUser().getStatus() >= Integer.parseInt(this.levelMin)) {
responseWriter.startElement("li", this);
if (this.styleClass != null) {
responseWriter.writeAttribute("class", this.styleClass, "class");
}
responseWriter.startElement("a", this);
responseWriter.writeAttribute("href", "javascript:document.forms['" + this.getParent().getParent().getClientId(facesContext) + "'].submit();", "href");
responseWriter.writeAttribute("onclick", "document.getElementById('" + clientId + "').value = 'true';return true;", "onclick");
if (this.value != null) {
responseWriter.write(this.value);
}
responseWriter.endElement("a");
} else {
String disabled = (String) FacesUtil.getValueOfElExp((String) this.getParent().getAttributes().get("disabledStyleClass"));
responseWriter.startElement("li", this);
if (disabled != null) {
responseWriter.writeAttribute("class", disabled, "class");
}
responseWriter.startElement("a", this);
responseWriter.writeAttribute("href", "#", "href");
if (this.value != null) {
responseWriter.write(this.value);
}
responseWriter.endElement("a");
}
responseWriter.endElement("li");
// Input Hidden
responseWriter.startElement("input", this);
responseWriter.writeAttribute("id", clientId, "id");
responseWriter.writeAttribute("name", clientId, "name");
responseWriter.writeAttribute("type", "hidden", "type");
responseWriter.writeAttribute("value", "false", "value");
responseWriter.endElement("input");
}
/**
* @see javax.faces.component.UIComponentBase#saveState(javax.faces.context.FacesContext)
*/
public Object saveState(FacesContext context) {
Object[] values = new Object[6];
values[0] = super.saveState(context);
values[1] = this.levelMin;
values[2] = this.id;
values[3] = this.styleClass;
values[4] = this.value;
values[5] = this.action;
return values;
}
/**
* @see javax.faces.component.UIComponentBase#restoreState(javax.faces.context.FacesContext, java.lang.Object)
*/
public void restoreState(FacesContext context, Object state) {
Object[] values = (Object[]) state;
super.restoreState(context, values[0]);
this.levelMin = (String) values[1];
this.id = (String) values[2];
this.styleClass = (String) values[3];
this.value = (String) values[4];
this.action = (String) values[5];
}
/**
* @see javax.faces.component.UIComponentBase#decode(javax.faces.context.FacesContext)
*/
@SuppressWarnings("unchecked")
public void decode(FacesContext facesContext) {
String clientId = this.getClientId(facesContext);
Map parametersMap = facesContext.getExternalContext().getRequestParameterMap();
Object val = parametersMap.get(clientId);
if (val != null) {
Boolean cmd = Boolean.parseBoolean(val.toString());
if (cmd) {
this.action = (String) this.getAttributes().get("action");
String redirect = (String) FacesUtil.getValueOfElExpMethod(this.action);
facesContext.getApplication().getNavigationHandler().handleNavigation(facesContext, this.action, redirect);
}
}
}
/**
* @see javax.faces.component.UIComponentBase#getRendersChildren()
*/
public boolean getRendersChildren() {
return true;
}
/**
* Getter.
*
* @return the levelMin
*/
public String getLevelMin() {
return this.levelMin;
}
/**
* Setter.
*
* @param levelMin the levelMin to set
*/
public void setLevelMin(String levelMin) {
this.levelMin = levelMin;
}
/**
* Getter.
*
* @return the id
*/
public String getId() {
return this.id;
}
/**
* Setter.
*
* @param id the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* Getter.
*
* @return the styleClass
*/
public String getStyleClass() {
return this.styleClass;
}
/**
* Setter.
*
* @param styleClass the styleClass to set
*/
public void setStyleClass(String styleClass) {
this.styleClass = styleClass;
}
/**
* Getter.
*
* @return the value
*/
public String getValue() {
return this.value;
}
/**
* Setter.
*
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
}
/**
* Getter.
*
* @return the action
*/
public String getAction() {
return this.action;
}
/**
* Setter.
*
* @param action the action to set
*/
public void setAction(String action) {
this.action = action;
}
/**
* Check if this item is the current page.
*
* @param inId
* @return true if this item is the current page
*/
private boolean isCurrentPage(String inId) {
if (inId.compareToIgnoreCase("home") == 0) {
if (MenuUtil.isHome()) {
return true;
}
} else if (inId.compareToIgnoreCase("report") == 0) {
if (MenuUtil.isReport()) {
return true;
}
} else if (inId.compareToIgnoreCase("task") == 0) {
if (MenuUtil.isTask()) {
return true;
}
} else if (inId.compareToIgnoreCase("customer") == 0) {
if (MenuUtil.isCustomer()) {
return true;
}
} else if (inId.compareToIgnoreCase("user") == 0) {
if (MenuUtil.isUser()) {
return true;
}
} else if (inId.compareToIgnoreCase("history") == 0) {
if (MenuUtil.isHistory()) {
return true;
}
}
return false;
}
} |