This content has been marked as final.
Show 3 replies
-
1. Re: a4j:loadBundle and f:loadBundle problem with facelet
ishabalov Apr 16, 2007 4:27 PM (in response to andrew.rw.robinson)Can you share your code with us? It will be great if we can incorporate this into future releases.
-
2. Re: a4j:loadBundle and f:loadBundle problem with facelet
andrew.rw.robinson Apr 18, 2007 2:52 PM (in response to andrew.rw.robinson)New code for the taglib file:
<tag> <tag-name>loadBundle</tag-name> <component> <component-type>example.Bundle</component-type> <handler-class> example.LoadBundleHandler </handler-class> </component> </tag>
New code for the faces-config.xml:<component> <component-type>example.Bundle</component-type> <component-class> example.AjaxLoadBundle </component-class> </component>
LoadBundleHandler.java:/** * */ package example; import java.io.IOException; import java.util.ResourceBundle; import javax.el.ELException; import javax.faces.FacesException; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import org.ajax4jsf.ajax.ResourceBundleMap; import com.sun.facelets.FaceletContext; import com.sun.facelets.tag.TagAttribute; import com.sun.facelets.tag.TagAttributeException; import com.sun.facelets.tag.jsf.ComponentConfig; import com.sun.facelets.tag.jsf.ComponentHandler; /** * @author arobinson */ public class LoadBundleHandler extends ComponentHandler { private final TagAttribute basename; private final TagAttribute var; /** * @param config */ public LoadBundleHandler(ComponentConfig config) { super(config); this.basename = this.getRequiredAttribute("basename"); this.var = this.getRequiredAttribute("var"); } /** * @see com.sun.facelets.tag.jsf.ComponentHandler#applyNextHandler(com.sun.facelets.FaceletContext, * javax.faces.component.UIComponent) */ @Override @SuppressWarnings("unchecked") protected void applyNextHandler(FaceletContext ctx, UIComponent c) throws IOException, FacesException, ELException { ResourceBundle bundle = null; try { String name = this.basename.getValue(ctx); ClassLoader cl = Thread.currentThread().getContextClassLoader(); Locale locale = null; UIViewRoot viewRoot = ctx.getFacesContext().getViewRoot(); if (viewRoot != null) locale = viewRoot.getLocale(); if (locale == null) locale = Locale.getDefault(); bundle = ResourceBundle.getBundle(name, locale, cl); } catch (Exception e) { throw new TagAttributeException(this.tag, this.basename, e); } ResourceBundleMap map = new ResourceBundleMap(bundle); FacesContext faces = ctx.getFacesContext(); faces.getExternalContext().getRequestMap().put(this.var.getValue(ctx), map); super.applyNextHandler(ctx, c); } }
AjaxLoadBundle.java:/** * */ package example; import java.io.IOException; import javax.faces.FacesException; import javax.faces.context.FacesContext; /** * * * @author arobinson */ public class AjaxLoadBundle extends org.ajax4jsf.ajax.html.AjaxLoadBundle { public final static String COMPONENT_TYPE = "com.outlooksoft.Bundle"; /** * @see javax.faces.component.UIComponentBase#processDecodes(javax.faces.context.FacesContext) */ @Override public void processDecodes(FacesContext context) { super.processDecodes(context); // ensure that the bundle is available through all phases try { encodeBegin(context); } catch (IOException ex) { throw new FacesException(ex); } } }
-
3. Re: a4j:loadBundle and f:loadBundle problem with facelet
alexsmirnov Apr 18, 2007 7:12 PM (in response to andrew.rw.robinson)we will text this case and add to the codebase is everything is OK.
a4j:loadBundle is only workaround for JSF 1.1. You can use facelets with JSF 1.2 and define bundles in faces-config.xml