I'm building Portlets using Spring Portlet MVC 3.02 and deploying them on WebSphere Portal V7. I have a form submission where one combo box requires to sent an Spanish character. Something like this:
<form:select id="${ns}imTheField" path="imTheField" cssStyle="width:120px;">
<option value="AtTheEndTheresASpanishCharacterÑ">
AtTheEndTheresASpanishCharacterÑ
</option>
</form:select>
The "Ñ" character looks nice in the Screen. That combo value maps to the command attribute imTheField by Spring Binding process. After form submission and in the handler method, this is what I get when I log that command attribute:
theCommand.getImTheField: AtTheEndTheresASpanishCharacterÃ
Which is not the character that came from the form. This is getting me trouble as when there are errors in form submission I have to show the form again with the previous values, which now I don't have because of that issue.
Any ideas? This is what I get from Chrome debugging at form submission:
Request Headers
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:es
Form Data
imTheField:AtTheEndTheresASpanishCharacterÑ
Response Headers
Content-Language:es
Content-Type:text/html; charset=UTF-8
Note that the field imTheField looks nicely formatted. Maybe is an issue with the Accept-Charset request header?
see: http://floatingcube.blogspot.co.uk/2008/10/special-characters-in-spring-mvc.html
You may need to use a filter as spring is using ISO-8859-1 rather than UTF-8
Related
How would I go about achieving the following
I have some HTML data triggered from an Evernote new note action
I need to pass this HTML string to a website via an http post with form variables
I then need to catch the resulting web page text in a variable to use in my next action.
For clarity the website simply takes some HTML and converts it to markdown passing it back out as the body of the resulting page
Regards in advance
Dan
Sweet! So I've got this working. In my example, text is some html I pulled out of a dummy previous step:
The output is:
Which has the markdown as a key. If you want to tweak other data based on the api params, you can do that as GET params below html
Let me know if you've got any other questions!
I have rich:popupPanel which contains t:dataList under one column of t:dataTable. This dataList has h:commandLink which has f:param inside it. It was working fine for richfaces 3.3 but after migration to richfaces 4, it stopped working. To mention the fact that I was using rich:modalPanel in place of rich:popupPanel over there. I went through quite a few links:
https://community.jboss.org/thread/202583
commandButton/commandLink/ajax action/listener method not invoked or input value not updated
but of no help :(. Am I missing something? Currently, bean is session-scoped and I am using getter to fetch the data model as its not possible for me to put it in constructor.
Please let me know, if someone has idea about it.
PS: Rendered HTML equivalent looks like this. It has request parameter varPath but in backing bean we get it as null.
<a onclick="return myfaces.oam.submitForm('actionForm','actionForm:j_id0',null, [['varPath','/Link']]);" href="#" tabindex="-1" accesskey="">/Link</a>
Figured out that changing the encType of form to "application/x-www-form-urlencoded" from "multipart/form-data" resolves this issue. Strange though! Not sure why it didn't work with multipart encryption.
First of all, it's not an encryption, but an encoding. The difference is pretty huge. "Encrypting" is a way of changing the value in such way which is not predictable without having kind of a security key (cipher key, seed, etc). "Encoding" is a way of changing the value in such way that it's acceptable by the data transfer mechanism and/or that it's recognizeable/parseable by the other side without loss of any data. The values are not made unreadable or something, they are just arranged somewhat specific and differently.
Coming back to your concrete problem, the multipart/formdata encoding is usually only used when you need to be able to send (upload) a file along with the form, using for example <input type="file"> or the RichFaces <rich:fileUpload> component. The standard application/x-www-form-urlencoded form encoding, which basically specifies that the request parameters should be sent URL-encoded in this format
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
name1=value1&name2=value2&name3=value3
isn't suitable for passing file contents around. For that the multipart/form-data encoding should be used which basically look like this:
Content-Type: multipart/form-data;boundary=SOME_BOUNDARY
--SOME_BOUNDARY
content-disposition: form-data;name="name1"
content-type: text/plain;charset=UTF-8
value1
--SOME_BOUNDARY
content-disposition: form-data;name="name2"
content-type: text/plain;charset=UTF-8
value2
--SOME_BOUNDARY
content-disposition: form-data;name="name3"
content-type: text/plain;charset=UTF-8
value3
--SOME_BOUNDARY--
This format allows room for enclosing complete file contents in the request body.
In a JSF 2.0/2.1 web application, multipart/form-data requests are normally processed by a custom Filter. In case of RichFaces 3, this is normally processed by the org.ajax4jsf.Filter which is missing in RichFaces 4.
Note that the application/x-www-form-urlencoded is already the default encoding type of HTML forms. So you don't need to explicitly specify it yourself. Just omit the enctype attribute altogether:
<h:form>
</h:form>
and you should be all set.
Figured out that changing the encType of form to "application/x-www-form-urlencoded" from "multipart/form-data" resolves this issue. Strange though! Not sure why it didn't work with multipart encryption.
Would still like to know the explanation behind this, if anyone knows about this.
Using a4j:commandLink instead of h:commandLink pass parameters correctly which resolved this issue. No need for custom filters just for parameters.
CommandButton should be placed in a form tag. Sounds like you have nested form or you have no form.
I am developing an JSF 2.0 application for IBM Webshere 7.0 and I want to prevent user submitting a form using the GET method for security reason i.e user will not be able to submit a form appending the form values to the Query String.
Is there any simple solution for this or I need to build filter to prevent this ?
When you use JSF <h:form> it does a POST request be default. Even though a Query string is sent, since the submission method is POST, the result is not sent as a query string, that is, it is not added to the action URL of the form. Rather, the string is sent as the body of the HTTP request and the doPost() method of the FacesServlet will be invoked.
See also:
Proper way to call servlet from Facelets?
http://en.wikipedia.org/wiki/Query_string
I'm slowly moving my rails website from a traditional rails round-trip-for-each-view application to one that will eventually be single page ember.js based. As part of this migration, I'm doing it in steps and not migrating the whole app in one go to a single page app but section by section at first.
I'm stumped on one problem that seems general. When I use the same controller for JSON views as well as HTML views, pressing back in Chrome occasionally shows me the JSON view instead of the HTML view.
For instance, I have an endpoint /portfolio/13, which is the entry point into one of these section ember.js apps and which causes Ember Data to pull the JSON for Portfolio with the id of #13 over the same endpoint with application/json as the Accept: header. Pressing back after forward navigating to deeper page will get the JSON representation of the page instead of the HTML.
Do I need to force Ember Data to use the format parameter such that the JSON version is at a different URL? If so, how does one do that?
What am I doing wrong?
Try adding this somewhere in your Javascript:
$.ajaxSetup({cache: false});
It should fix the problem. However, something is wrong here, because by default browsers don't cache JSON. Probably, this is because of the wrong content type, that is, Rails is serving JSON as HTML.
Are you having some headers set as "application/json" in your rails app? Could you trace the network response headers and see the content-type: value?
Is the "whole" page displaying as JSON? ( meaning not parsing HTML )
I had this problem once using sinatra and I had a ( very stupid ) :
before do
content_type 'application/json'
end
If you want your browser to display correctly, it has to be 'text/html' for all your HTML pages.
It might be your problem at some places in your rails app. ( But why haven't you had this problem before ember? )
I am using Rails 3.2.3 and Ruby 1.9.3.
I have a model called called Post that accepts a title and a description.
The front-end of the site receives information submitted through the back-end through an ajax request. When I fill out the form with, let's say
title: foo
content: foobar
and submit it, I am able to view data through the front-end without a problem.
However, whenever I submit non-utf8 data through the form, for example (mind the fancy quotes):
title: foo
content: “foobar”
When I try to render the form I get the following error:
ActionView::Template::Error (incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string))
My .js.erb file looks like this:
$("#my_post").html('<%= escape_javascript(render :partial => 'post') %>');
I realize this is an issue with encoding, but I'm not sure how I should handle it the best way. I thought of several options:
Strip out non-utf8 by using the iconv library -- do this via a before_save filter for every single model in my application
Specifying at the top of the js that the document contains utf-8 (not sure this would work)
Using accept-charset="UTF-8" in my form to force the browser to avoid submission of non-utf-8 content.
I'm not even sure these solutions would help and the most efficient way to do this would be.
Thanks!
I suspect that you're not using the form helpers because you mention the question of adding accept-charset="UTF-8" to your form.
The form helpers will add the accept-charset attribute as well as the snowman parameter which together should ensure you get UTF-8 data from the browser.
See the Rails Form helpers guide.
You need to look carefully to see if
You're actually sending non-UTF-8 data to your app, or
You're sending UTF-8 data, but it is not being recognized by Ruby/Rails
To see which it is, you need to examine the data on the "wire." (What's being sent on the Internet.) Use a peeking tool such as Wireshark or a proxy spy such as Fiddler
Curly quotes can be sent using 8859 or UTF-8.
Recommendation You should set the HTML page to be UTF-8. Any Ajax sent from scripts on the page should then also use UTF-8. See http://www.utf8.com/
Added (Re: comment about how Rails sets form's character encoding)
The issue for Ajax character encoding is how was the page's encoding set. A blog post. So be sure to set the page's UTF-8 encoding in your page template.