return child;
}
//xxx by nick - denis - do not catch exception, rethrow them
public void handleFacets(FacesContext context, UITogglePanel component) throws IOException {
UITogglePanel panel = (UITogglePanel)component;
List<String> stateOrderList = component.getStateOrderList();
String state = (String) component.getValue();
if (state == null) {
String initialState = component.getInitialState();
if (initialState != null) {
state = initialState;
} else {
if (!stateOrderList.isEmpty()) {
state = (String) stateOrderList.get(0);
} else {
throw new FacesException("The \"initialState\" attribute of the togglePanel component should be set if \"stateOrder\" attribute is empty!");
}
}
}
ResponseWriter out = context.getResponseWriter();
String switchType = panel.getSwitchType();
if (UITogglePanel.CLIENT_METHOD.equals(switchType)) {
// Client
String panelId = panel.getClientId(context);
StringBuffer divIds = new StringBuffer();
boolean first = true;
for (Iterator<String> iterator = stateOrderList.iterator(); iterator.hasNext();) {
String stateName = (String) iterator.next();
UIComponent child = getFacet(component, stateName);
if(!first) {
divIds.append("\", \"");
}
divIds.append(stateName);
first = false;
String id = panel.getClientId(context) + "_" + stateName;
out.startElement("div", component);
out.writeAttribute("id", id, null);
out.writeAttribute("style", "display: " + (stateName.equals(state) ? "inherit": "none"), null);
renderChild(context, child);
out.endElement("div");
}
String idInput = panel.getClientId(context) + "_input";
out.startElement("div", component);
out.writeAttribute("style", "display: none;", null);
out.startElement("input", component);
out.writeAttribute("type", "hidden", null);
out.writeAttribute(HTML.autocomplete_ATTRIBUTE, "off", null);
out.writeAttribute("id", idInput, null);
out.writeAttribute("name", panel.getClientId(context), null);
out.writeAttribute("value", state, null);
out.endElement("input");
out.endElement("div");
String script = MessageFormat.format(CLIENT_SCRIPT,
panelId, divIds.toString(), state);
out.write(script);
// } else if(UITogglePanel.AJAX_METHOD.equals(switchType)) {
// // Ajax
// UIComponent child = getFacet(component, state);
// if(child != null) {
// out.startElement("div", component);
// renderChild(context, child);
// out.endElement("div");
// }
} else {
// Server or AJAX
UIComponent child = getFacet(component, state);
if(child != null) {
out.startElement("div", component);
renderChild(context, child);
out.endElement("div");
}
}
panel.setValue(state);
}