focus.jspx 1.82 KB
<?xml version="1.0" encoding="UTF-8"?>
<f:root 
    xmlns:f="http://jsf.exadel.com/template"
    xmlns:vcp=" http://jsf.exadel.com/vcp"
    xmlns:ui=" http://jsf.exadel.com/ui"
    xmlns:x=" http://jsf.exadel.com/vcp"
    xmlns:u="http://jsf.exadel.com/util"
    xmlns:h="http://jsf.exadel.com/header"
    component="org.richfaces.component.UIFocus"
    baseclass="org.ajax4jsf.renderkit.HeaderResourcesRendererBase"
    class="org.richfaces.renderkit.html.FocusRenderer">

    <f:clientid var="clientId"/>
    <c:set var="for" value="#{component.forComponentId}"/>
    <c:set var="priority" value="#{component.attributes['priority']}"/>
    <h:scripts>new org.ajax4jsf.javascript.PrototypeScript(),/org/richfaces/renderkit/html/scripts/focus.js</h:scripts>

    <jsp:scriptlet>
<![CDATA[
    Integer priority = (Integer)variables.getVariable("priority");
    if(priority == null) {
        priority = component.getDefaultPriority();
    }

    variables.setVariable("priority",priority);
    String sid = (String) variables.getVariable("for");
    String target;
    if (sid != null && ! "".equals(sid)) {
        try {
            UIComponent forcomp = getUtils().findComponentFor((UIComponent)component,sid);
            if (forcomp != null) {
                    target = forcomp.getClientId(context);
            } else {
                target = sid;
            }
         }catch(IllegalArgumentException e) {
            target = sid;
         }
         String suffix = component.getSuffix();
         if(suffix != null && !"".equals(suffix)) {
             target += suffix;
         }
    } else {
        target = component.getParent().getClientId(context);
    }
    variables.setVariable("for",target);
]]>
    </jsp:scriptlet>

    <script type="text/javascript">
        Richfaces.FocusManager.setFocus("#{for}",#{priority});
    </script>
</f:root>