How to define facelets.Encoding in JSF2? - jsf

In JSF sources I found the logic of defining character encoding via facelets.Encoding attribute, which can be available in FacesContext.getAttributes()
See FaceletViewHandlingStrategy#getResponseEncoding method for details. How can I define this attribute for instance of FacesContext? I tried to define it via context-param in web.xml, but it's not working. And also I didn't find any reference about it in JSF documentation.
The main reason why I want do this, it is overriding of javax.faces.request.charset value. I don't want define a special filter for my application the order to define not UTF-8 encoding. Because my application contains a lot of WAR packages inside of big EAR.

Related

Change composite-component's namespace

I have a small library (JAR) containing some custom JSF-components. Some of them are composite-components which are completely (or partly) implemented in XHTML files which reside under META-INF/resources/my-components. To use these components from other XHTML-files I have to use the XML-namespace http://xmlns.jcp.org/jsf/composite/my-components.
Other related components in this library are implemented as POJOs using #FacesComponent (and #FacesRenderer). To use these components, I have to use the XML-namespace which is defined at the component's #FacesComponent-annotation (attribute namespace). At this point I can choose whatever I want (like http://my-company.com/my-components).
Since I have not found any possibility to change the namespace-prefix of my composite components, and I do not want to set my POJO's namespace to something like jcp.org (I'm not sure if this is even possible), I have to use two different namespaces to use my components coming from the same library.
But since the namespaces are different only because of an implementation-detail and maybe one component will be realized in a different way in the future, this is not what I want.
So the question is: is there a way to specify the full namespace for my composite-components? Of course, I want to use the same ones which are used for my other components (http://my-company.com/my-components in the example).
Just specify the composite library name in your *.taglib.xml file, below the namespace declaration.
<namespace>http://my-company.com/my-components</namespace>
<composite-library-name>my-components</composite-library-name>

How to debug spring-integration

We are quite happy with spring-integration except when things do not work as expected. Then it is really difficult to find out what is going on (we are using xml configuration). Can someone point me to the java components behind the spring integration components in order to debug them. For instance: If I have a headerValueRouter, where can I set a breakpoint to find out what is the actual value of the header inside the message, just before the component is doing the routing. Maybe there is even a list int:component->java class?
True. The list exists, but it isn't so direct, as you may expect. Each xml component goes to some parser. And the last one configure the Spring Integration component(s).
You can find the mapping from source code of any AbstractIntegrationNamespaceHandler implementation.
Actually, we try to reflect xml-tag names with Java class names. So <header-value-router> -> HeaderValueRouterParser -> HeaderValueRouter.

Naming conventions for `<component-family>` and `<renderer-type>` while creating custom JSF components

I am learning to create custom JSF components and have been successful in creating simple ones. One thing I would like to know is that whether there are any naming conventions to be followed while defining <component-family> and <renderer-type> for your component?
For e.g. for combo box the <component-family> is javax.faces.SelectOne. It looks like a Java class but I was unable to find any such class in JSF API.
They do indeed not necessarily represent class names. They are just identifiers. The javax.faces prefix hints in this case merely that it's part of standard JSF API. The same prefix is used everywhere else in standard JSF API. PrimeFaces components use org.primefaces prefix, OmniFaces components use org.omnifaces prefix, etcetera.
You're fully free in choosing your own for your component library. You should only gurarantee that it shouldn't possibly conflict with a 3rd party one which may be mixed by the enduser. Like as with package structure of Java classes, it'd make sense if you choose for com.naveen prefix or whatever what/who represents the owner/developer of the component library.
The same approach as Java packages (and Internet domain names) is a very sensible way of guaranteeing uniqueness (you know, identifiers are supposed to be unique).
See also:
How do I determine the renderer of a built-in component
What is the relationship between component family, component type and renderer type?
Java packages com and org

Options available for reading a Dynamic Property in a Composite Application

It is possible to open a Lotus Notes Composite Application (CA) using a syntax like this:
cai:///uniqueappid/uniquepageid?hint
According to a wiki-article -
Passing context to components when opening composite applications - you can pass a Dynamic property to a Composite Application and let the components in the CA read it.
The article has an example like this:
String[] values = data.getPreference("com.ibm.portal.app.input.NiklasTest");
Which should be able to read the parameter from a URL formatted like this:
cai:///uniqueappid/uniquepageid?hint&NiklasTest=xxxxx
I am looking for what my options are in order to get a handle on such a property.
Coding a java component. It seems likely that this would work.
Coding an xPage component. Would it be able to get a handle on the Dynamic
Property?
Coding a Portlet component. Would it be able to get a
handle on the Dynamic Property?
Coding a NSF form- or page-based
component. Are there LotusScript or #functions that can get a handle
on the Dynamic Property?
I am not looking for the best soloution. I am looking for a list of options that are known to work. Basically weeding out in my list above.
I know nothing of Composite Applications, and what exactly is a Dynamic Property, but in an XPage you can simply use param.NiklasTest in order to get the xxxxx from the URL.
In a application where we needed to pass parameters (and be able to open the CA multible times).
The (easy) solution was to build the .ca file on the fly (and embed the parameters) and then launch it.
You can build the template for the .ca file with the designer
IBM Wiki

Adding a Reference to System.Web

I am trying to create some cookies as I cannot fetch the cookies and a normal way so I will run through the whole header and just create the cookie manually. However whenever I try to use Response.Cookies and HttpCookie I get an error:
The name Response does not exist in the current content
and
The type or namespace name 'HttpCookie' could not be found (are you missing a using directive or an assembly reference?).
I read around and understood I will need to reference
System.Web
So I am clicking on Project -> Add Reference -> .NET and select System.Web. Then I add using System.Web;.
And still I am unable to access them.
From what code are you trying to access the item?
There are essentially two steps that need to be taken to reference a class:
Add a reference to the class' assembly in the project.
Add a using directive to the class' namespace in the code file.
It sounds like you're performed the first step. What about the second? That's what this error means:
The type or namespace name 'HttpCookie' could not be found (are you missing a using directive or an assembly reference?).
To perform step 2 above, you actually have a couple of options:
Fully-qualify the class name. So, instead of using HttpCookie you would use System.Web.HttpCookie.
Add a using directive to the code file. At the top of the file (and this would need to be done for any file which uses classes in this namespace), you would add using System.Web. Then you could just reference HttpCookie directly.
Additionally, the first part of your question brings up a separate issue entirely:
The name Response does not exist in the current context
This again goes back to my question about where you're accessing this value. When you're writing code in, say, the code-behind for an ASPX page, you have access to the various bits of ASP.NET web contexts by default. These are provided by the base Page class. Things like Request and Response are readily available.
However, if you're trying to access these objects from outside of that context (such as from a custom class or another assembly), you'll need to reference that context manually. This can be done by using a factory on the System.Web.HttpContext class:
Request becomes System.Web.HttpContext.Current.Request
Response becomes System.Web.HttpContext.Current.Response
This is because Request and Response aren't actual classes. They're properties on the current web context which are of type HttpRequest and HttpResponse. Those properties are mapped for you when you're in the same context, but outside of that context you'd need to reference them fully as demonstrated above.
One thing to note is that it's not generally considered good practice to have dependencies on the web context outside of where it's already available. So if you're creating a custom class or another assembly then you might want to take a step back and think about the design.
If your custom classes depend on the existence of a current instance of HttpContext then that code can never be used outside of a fully-aware web application context. So the code is less re-usable. So, depending on what you need from that context, you can re-factor the code to not need the context itself but only to require that the necessary items from the context be provided.
This isn't necessary to get you past your current issue, but it's something to keep in mind going forward.

Resources