Tuesday, 16 September 2014

Change default number of items OR Items per page in Alfresco Share


When we work with Alfresco Share, many a times we feel or do have a requirement of changing the number of items per page.
Either we want to reduce or increase the number of items in our document library/repository.
By default, 50 items will be displayed on a single document library page in alfresco share.
If you want to change it, just customize documentlist.get.html.ftl file

Steps:
1) Find the file documentlist.get.html.ftl (Location -> tomcat\webapps\share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco\components\documentlibrary\documentlist.get.html.ftl)

NOTE : To make changes, extend this file. Do not directly modify this file.

2) In the setOptions method, you will find various options already set like : showFolders, simpleView,repositoryBrowsing,useTitle,userIsSiteManager, etc.
   Add one more option "pageSize" with your value say "25".
 
   So, your file will now end with something like this (assuming you want the number of items per page as 25):
 
 
   ...
   ...
   useTitle: ${(useTitle!true)?string},
      userIsSiteManager: ${(userIsSiteManager!false)?string},
 pageSize: 25
   }).setMessages(
      ${messages}
   );
//]]></script>
</@>

3) No need to restart the alfresco server. Go to http://localhost:8080/share/service/index and click "Refresh Web Scripts" button.

4) Go to your alfresco share documentlibrary/repository and check the results.
NOTE: Hard refresh or clear browser cookies/cache if correct results do not appear.

Wednesday, 7 May 2014

Escaping special characters - especially # in ibatis query

Hello friends,
Normally we run an ibatis query smoothly when there are no special characters involved.
But in some cases,  we have special characters in the query :

select col1, col2 from table1 as t1 inner join table2 as t2 on t1.xcol# = t2.ycol# and t1.col3=t2.col4 where col4=1

Here, my column name itself contain #. So I need to tell ibatis that my column name contains # and please consider it within the column name while running query.

So when there are special characters in the query (column name, variable, etc) then you might run into some of the below errors :

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 't1.xcol' in 'on clause'
...
...
Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: java.lang.RuntimeException: Error parsing XPath '/sqlMap/select'.  Cause: com.ibatis.sqlmap.client.SqlMapException: Incorrect inline parameter map format (missmatched name=value pairs): `=t2.`ycol
...
...
Cause: java.lang.ArrayIndexOutOfBoundsException: 1
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:204)
...
...

Th following query ran successfully in mysql query browser but not when running through ibatis.

select col1, col2 from table1 as t1 inner join table2 as t2 on t1.`xcol#` = t2.`ycol#` and t1.col3=t2.col4 where col4=1

Solution (for running with ibatis):

Escape has (#) by double hash (##) and embed the column name containing # within grave accent/backtick symbol.
I faced a similar issue and modified the query as :

select col1, col2 from table1 as t1 inner join table2 as t2 on t1.`xcol##` = t2.`ycol##` and t1.col3=t2.col4 where col4=1

It worked successfully.

=================================================================

You may also get the following exception :

java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)

Solution :
Check column name in sql query. It may contain # which u need to escape

=================================================================

If webscript gets called recursively (i.e query gets executed recursively through services), then:

The transaction may be getting retried i.e RetryingTransactionHelper due to some exception caused.
Check the logs or remove the already handled exceptions in catch block.
=================================================================

Using LIKE query in iBatis : Here my column name is ITEM# so I am required to escape it using ` and # while using mysql.

select `ITEM##` from TABLE where COL1=#val1# and COL2 like #val2#  and `ITEM##` like '$ItemNo$%'

With DB2, the following may also work : (This character ` should not be required for escaping) :

select ITEM## from TABLE where COL1=#val1# and COL2 like #val2#  and ITEM## like '$ItemNo$%'
=================================================================

Dynamic AND/OR statements in ibatis :
<select id="getAllItems" resultMap="result" parameterClass="map">
       select `ITEM##` from TABLE where COL1=#val1# and COL2=0  and `ITEM##` like '$ItemNo$%'
       <iterate prepend="AND" property="propname"
  open="(" close=")" conjunction="OR">
  COL3=#propname[]#
  </iterate>
  </select>

Thursday, 20 March 2014

Customizing flash-upload dialog in Alfresco Share for 4.2.x version

Here is some useful information for Alfresco4.2.x customizers.
Normally for uploading a custom type of content (from flash-upload dialog in alfresco share), what we did till now was
making the entry of custom content type in flash-upload.get.js file and
the custom content started appearing in flash-upload dialog.

But in Alfresco4.2.x, to make the flash-uploader work with custom content type, we need to do the following :

1) Make the appropriate entry of custom content type in flash-upload.get.js file in your extension environment.
2) Edit the tomcat/conf/context.xml file.
   Add the change in context element as follows:
   <Context useHttpOnly="false"> in place of <Context>
3) Restart the server.

This is done in order to re-enable the flash uploader.

Courtesy :
http://wiki.alfresco.com/wiki/Alfresco_Community_4.2.b_Release_Notes