KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a JSF 2.0 application which allows the user to change the site's language which should affect both texts and images. Currently the locale is set in a session bean and each page has with locale set from this session bean. It works great for texts. But I have trouble with images. Currently we are using images like this: <h:graphicImage name="flag.gif" library="img"> This leads to generation of the following HTML code returned to the user agent: <img src="/AppRoot/faces/javax.faces.resource/flag.gif?ln=img" .... /> Let's assume that the user requests the page in English. The GET request for the image above is processed by ResourceHandler.handleResourceRequest(). It uses ViewHandler.calculateLocale() to identify the correct locale prefix. I have implemented my own ViewHandler with calculateLocale() that retrieves the locale from the user's session. As a result it correctly creates a resource instance which points to "/resources/english/img/flag.gif" . Then the user changes his/her locale to french. When the page is reloaded, the same image URL is rendered and requested. This time ViewHandler.calculateLocale() returns Locale.FRENCH to the ResourceHandler which results in the creation of resource with path "/resources/french/img/flag.gif" . Before streaming the image, according to the specification, the ResourceHandler.handleResourceRequest() must do the following: •Call Resource.userAgentNeedsUpdate(javax.faces.context.FacesContext). If this method returns false, HttpServletRequest.SC_NOT_MODIFIED must be passed to HttpServletResponse.setStatus(), then handleResourceRequest must immediately return. It detects that the resource is not updated since the previous browser request - not taking into account that the previous request to this "logical" URL lead to different "physical" resource on
Tags (comma-separated)
Save Edits
Cancel