Check: Try to set focus for (invalid) calendar. It never works.
I found a right solution (s. below example for encodeImplicitFocus in FocusRenderer). Important is to check whether the component satisfies INPUT selector. If yes - set the focus directly, if not - set the focus on the first focusable child.
Code: Select all
private static final String INPUT_SELECTOR =
":input:not(:button,:submit,:reset,:hidden,:disabled,[readonly='readonly'])";
protected void encodeImplicitFocus(FacesContext facesContext, Focus focus) throws IOException
{
ResponseWriter writer = facesContext.getResponseWriter();
if (isPostBack()) {
String clientId = findFirstInvalidClientId(facesContext, focus);
if (clientId != null) {
String selector = ComponentUtils.escapeJQueryId(clientId);
writer.write("var invalidEl = jQuery(\"" + selector + "\");");
writer.write("if (invalidEl.is(\"" + INPUT_SELECTOR + "\")){invalidEl.focus();}");
writer.write("else {jQuery(\"" + selector + " " + INPUT_SELECTOR + ":first\").focus();}");
} else {
focusOnFirstFocusable(facesContext, focus, writer);
}
} else {
focusOnFirstFocusable(facesContext, focus, writer);
}
}
private void focusOnFirstFocusable(FacesContext facesContext, Focus focus, ResponseWriter writer) throws IOException
{
String selector = INPUT_SELECTOR + ":first";
if (focus.getContext() != null) {
UIComponent context = focus.findComponent(focus.getContext());
if (context == null) {
throw new FacesException("Cannot find component " + focus.getContext() + " in view");
} else {
selector = ComponentUtils.escapeJQueryId(context.getClientId(facesContext)) + " " + selector;
}
}
writer.write("jQuery(document).ready(function(){jQuery(\"" + selector + "\").focus();});");
}
I have created a issue http://code.google.com/p/primefaces/iss ... ail?id=781