Pentaho Filter Portlet Bugfix

Google Buzz

I’ve noticed a bug on Pentaho Filter Portlet that when you selected one option to filter, on refresh, that would be the filter in place, but the form of that filter would mark (as checked) more than just the option you selected.

I was amazed that this bug never got fixed. Aren’t people using the Portal with Pentaho ?

This seemed like a pure XSLT bug as the filter worked fine, so I went deep on it and so that the template to see if a options is selected is wrong. It may be a honest mistake.

The problem was that when checking a form item (like a checkbox option) to see if it was selected, their were using the function “contains”. This is, if the id of the select value contains the id of the form item.

The problem with this is that if you have on id number like department_1 and department_11, of course if you chose the department_11, when checking the department_1 item, it will check it as selected.

The solution is easy: just change the xsl isSelected template, putting the = instead of contains.

The file to change is html-form-controls.xsl and it’s on your solution directory under  “system/custom/xsl”.

Before (original):

<!-- determines whether an item in alist of any sort is selected -->
<xsl:template name="isSelected">
	<xsl:param name="value_param" />
	<xsl:param name="id_param" select="''"/>

	<xsl:for-each select="//data/*">

		<xsl:choose>
			<xsl:when test="$id_param=''">
                          <!-- Preserve old behavior if ID is not there -->
		<xsl:variable name="value">
			<xsl:value-of select="." />
		</xsl:variable>
		<xsl:if test="contains($value, $value_param)">true</xsl:if>
			</xsl:when>
			<xsl:otherwise>
                                <!-- Corrected behavior - only select the value for the control -->
				<xsl:if test="local-name()=$id_param">
					<xsl:variable name="value">
						<xsl:value-of select="." />
					</xsl:variable>
					<xsl:if test="contains($value, $value_param)">true</xsl:if>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>

After fix:

<!-- determines whether an item in alist of any sort is selected -->
<xsl:template name="isSelected">
	<xsl:param name="value_param" />
	<xsl:param name="id_param" select="''"/>

	<xsl:for-each select="//data/*">

		<xsl:choose>
			<xsl:when test="$id_param=''">
                                <!-- Preserve old behavior if ID is not there -->
		<xsl:variable name="value">
			<xsl:value-of select="." />
		</xsl:variable>
		<xsl:if test="$value = $value_param">true</xsl:if>
			</xsl:when>
			<xsl:otherwise>
                                <!-- Corrected behavior - only select the value for the control -->
				<xsl:if test="local-name()=$id_param">
					<xsl:variable name="value">
						<xsl:value-of select="." />
					</xsl:variable>
					<xsl:if test="$value = $value_param">true</xsl:if>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>


 
Was it any good?

Add to Technorati Favorites

AddThis Social Bookmark Button

Add 
to Mixx!