jsf 2 - Embedding a link (or other html) in a JSF message -


Text after "

I want to embed a link in a JSF message, is it possible?

When I try to do it, the hue HTML: The message tag avoids HTML characters. I tried to set H's escape attribute: to make the message tag false, but he did not help.

Unfortunately, the standard JSF implementation it is not possible component and renderer officially support this feature does not do. You can still make a renderer home that handles it.

Since this is a very common requirement / desire, I think everything is possible.

The first few background information: By default JSF tags are used to remove tags, which by default HTML remains. We instead delete it by & lt; H: outputText escape = "false" /> as you go with it. We want to extend the message renderer of the implementation of standard JSF and want to override the encodeEnd () method accordingly. But since MessagesRenderer include # encodeEnd () a lot (~ 180 lines of beautiful code) that we just do not like to copypaste to change one or two lines, after all, I found it better < To change Code> ResponseWriter where writeText () escaping with a custom implementation of help has been overridden to handle

So, I ended up with this Ho:

  package com.example; Import java.io.IOException; Import javax.faces.component.UIComponent; Import javax.faces.context.FacesContext; Import javax.faces.context.ResponseWriter; Import javax.faces.context.ResponseWriterWrapper; Import javax.faces.render.FacesRenderer; Import com.sun.faces.renderkit.html_basic.MessagesRenderer; @forrestrender (spacerrender = "javax.faces.messages", rendererType = "javax.faces.Messages") public class EscapableMessagesRenderer expands message sender {@Override throws public Nero encoded (FacesContext reference, UIComponent component) IOException {Final ResponseWriter OriginalResponseWriter = context getResponseWriter (); try {context.setResponseWriter (New ResponseWriterWrapper () {@Override public ResponseWriter getWrapped () {return originalResponseWriter;} @Override public void writeText (object lessons, UIComponent component, string property) throws IOException {String String = String.valueOf (text) ; avoid string find = (string) ComponentkgetAttributes () ( "Exodus") ;. that (escape = null & amp ;! & amp ;! Boolean.valueOf (escape)) {super.write (string);} Else {super .writetext (string, element, property);}}}); Super.encodeEnd (reference, component); // Now, render it! } Finally {context.setResponseWriter (original revocation); // restore the original author}}}  is  

to @FacesRenderer annotation despite this default MessagesRenderer override by implementation. I suspect there is a bug here, so I reported it. To make it work anyway, we need to go back to face-config.xml :

  & lt; Render-kit & gt; & Lt; Renderer & gt; & Lt; Component-Family & gt; Javax.faces.Messages & lt; / Component-family & gt; & Lt; Renderer type & gt; Javax.faces.Messages & lt; / Renderer type & gt; & Lt; Renderer Category & gt; Com.example.EscapableMessagesRenderer & lt; / Renderer category & gt; & Lt; / Renderer & gt; & Lt; / Render kit & gt;  

Then, to trigger it, just do it:

  & lt; H: Message saved = "wrong" />  

And it works! :)


Note: The above & lt; H: message & gt; only affects & lt; H: message & gt; To do this, just do this, but anywhere "message" "Replace with message" (Component family , Renderer type and classname).


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -