Archive for category Tricks
Use ServerXMLHTTP through a proxy
The other day, I was trying to use the ServerXMLHTTP object. For information, this object was created to allow you to establish server-to-server HTTP connections.
The code I firstly wrote looked like the following:
Dim oXMLHTTP
Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
oXMLHTTP.open "POST", sURL, false
oXMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oXMLHTTP.send sParams
Response.Write oXMLHTTP.responseText
with sURL the URL to call and sParams the parameters to send with the URL.
The problem was that oXMLHTTP.responseText didn’t return anything. Or to be exact, it returned an empty string, which was obviously not the expected response…
After some investigation, it appeared that the problem was because the server was seating behind a proxy. All this is good and well, but the question now is how to tell the application to use the proxy?
First of all, the ServerXMLHTTP object has a setProxy method:
http://msdn.microsoft.com/en-us/library/ms760236(v=VS.85).aspx
So I tried to add the following line to the previous code:
oXMLHTTP.setProxy 2, "myProxyServer:80", ""
Unfortunately, this didn’t fix the problem. It looks like this line is simply ignored. If somebody knows why, please tell me! ![]()
So the solution I finally adopted was to configure the proxy through the proxycfg tool.
There are two ways of using this tool:
- Import the proxy settings from the current user’s Microsoft Internet Explorer manual settings using the command
proxycfg.exe -u - Configure the proxy settings manually using the command
proxycfg -p myProxyServer:80
This last solution works for me and I hope it will help a few people. ![]()
PS: I found the following page when writing this article: http://support.microsoft.com/kb/289481/. It would have been so good to find it during my investigation but anyway.
limitToList attribute prevents flashing
If you have some elements (or even the whole page) that flash/twinkle using RichFaces, it probably means that these elements are AJAX-rendering. The question is by whom and how to fix it?
A lot of tags in RichFaces can AJAX-render elements such as:
<a4j:form>
<a4j:jsFunction name="updateName" reRender="showname">
<a4j:actionparam name="param1" assignTo="#{userBean.name}" />
</a4j:jsFunction>
</a4j:form>
On the above example, the JavaScript function updateName will AJAX-render the element which has the ID showname.
In some cases, you would have some elements that would AJAX-render without asking them to do so!
I still didn’t figure it out why.
(if anybody has an idea, please don’t hesitate to tell me!)
But, I found a way to prevent this!
You simply can add the following attribute to your tag:
limitToList="true"
You even can add it to the tags that don’t have a reRender attribute.
For example:
<a4j:form>
<a4j:poll id="poll" interval="1000" limitToList="true" />
</a4j:form>
Why GROUP_CONCAT returns BLOB?
Last week, when using the GROUP_CONCAT() function on a MySQL database, I got an unexpected result.
Indeed, instead of getting my result as VARCHAR types, I got it as BLOB types! For information, a BLOB is a binary large object that can hold a variable amount of data:
http://dev.mysql.com/doc/refman/5.0/en/blob.html
Because BLOB values are treated as binary strings, it is not easy to use. This is why we would prefer to have VARCHAR values.
So the question is how to get around this frustrating problem?
The answer is, for once, very simple! ![]()
You simply need to:
- Open your my.ini or my.cnf file;
- Change the value of the
group_concat_max_lensystem variable to 512 (no ‘k’ suffix); - Restart the mysql service
To verify if the value has been successfully updated, execute the following command in your mysql client:
mysql> show variables like "%concat%"; +----------------------+-------+ | Variable_name | Value | +----------------------+-------+ | group_concat_max_len | 512 | +----------------------+-------+ 1 row in set (0.00 sec)
Note that you cannot set the value of group_concat_max_len to less than 1Kb using the MySQL Administrator GUI. Which means that the only way to set this system variable to 512 (which is less than 1Kb) is to edit your MySQL configuration file as described above.
Deploy your app to the root context
This is an easy trick which I am sure most of you already know.
Let’s take a Java application called MyAddressBook. Its generated war file could be called myaddressbook.war.
By default, when you deploy this web application to Tomcat, the URL to access it will be http://localhost:8080/myaddressbook/. And if you point a domain name such as ‘addressbook.com’ to this server, the URL would be http://addressbook.com/myaddressbook/.
I don’t know for you but I don’t like to systematically have the subfolder ‘myaddressbook’ after my domain. But maybe I am too picky!
The idea is to deploy our application in the Tomcat root context.
You have two ways of doing this:
- Define a
ROOT.xmlfile in yourconf/Catalina/localhostfolder, or; - Rename your war file to
ROOT.war.
Note that the case is important, it has to be ROOT in UPPERCASE!
Once this is done, you will be able to call your application via the URL http://localhost:8080/
or http://addressbook.com/. Way better!
Be careful of SKIP_COMMENTS
Posted by smoreau in Tricks on 01 Dec 2009
In the early days, we used to hide JavaScript code from old browsers that do not support JavaScript.
The way of doing this was to put a one-line HTML-style comment without the closing characters immediately after the opening
<script>tag and put//-->at the end of the script.For example:
<script type="text/javascript"> <!-- alert('Test'); //--> </script>However if you are using this trick with the initialization parameter
facelets.SKIP_COMMENTSset to true, the code between<!--and//-->won’t even be sent to the client!It simply means that the code above won’t open an alert window because it has been skipped during the page rendering.
Here is what the client will receive:
You have two solutions to avoid this situation:
SKIP_COMMENTSparameter to false (the default is true). This can’t really hurt, your page will just be heavier depending on how much HTML comments you put on your page;For information, below is the code to put in your web.xml file to set the
SKIP_COMMENTSparameter to false:<context-param> <param-name>facelets.SKIP_COMMENTS</param-name> <param-value>false</param-value> </context-param>Facelets, JavaScript, old browsers, SKIP_COMMENTS
No Comments