[richfaces-issues] [JBoss JIRA] Created: (RF-10929) Full control over displayed label in InplaceSelect
Val Blant (JIRA)
jira-events at lists.jboss.org
Fri Apr 15 19:13:33 EDT 2011
Full control over displayed label in InplaceSelect
--------------------------------------------------
Key: RF-10929
URL: https://issues.jboss.org/browse/RF-10929
Project: RichFaces
Issue Type: Patch
Security Level: Public (Everyone can see)
Affects Versions: 3.3.3.Final
Reporter: Val Blant
This patch is somewhat related to this one - https://issues.jboss.org/browse/RF-4302, but it takes that improvement a step further.
In the patch above, Greg introduced a new attribute (_showValueInView_) to enable the component to display the value as the label. This is very useful, but I think it doesn't take it far enough. There are situations where it would be useful to have complete control over the label displayed once the selection is made.
For example, I have some data which looks like this:
||Value||In-list Label||Label after selection||
|1234|1 - Farming Expenses|1|
|3453|2 - Farming Income|2|
|4564|3 - Other Expenses|3|
I don't think there is a way to do this with the current functionality of _InplaceSelect_.
I didn't want to modify RichFaces, so in order to solve this problem I extended _InplaceSelect_ to make a _FilteredLabelInplaceSelect_ which takes one extra argument called _filterDisplayLabelMethod_ that takes a _MethodExpression_ that points to a method which takes a _SelectItem_ and returns the desired label string.
Like this:
{code:title=Usage}
<agrishare-jsf:inplaceSelect
value="#{backingBean.targetMeasurementDetailOid}"
filterDisplayLabelMethod="#{backingBean.filterLabelDisplayValue}">
<f:selectItems value="#{backingBean.targetMeasurementDetails}" />
</agrishare-jsf:inplaceSelect>
{code}
{code:title=Backing Bean}
public String filterLabelDisplayValue(SelectItem item) {
String label = item.getLabel();
if ( label != null && label.contains("-") ) {
StringTokenizer t = new StringTokenizer(label);
if ( t.hasMoreTokens() ) {
label = t.nextToken();
}
}
return label;
}
{code}
So, this component achieves server side label filtering with just a few changes. I didn't modify existing RichFaces code, but it would be very easy to apply my changes to the existing component (for those that know their way around your building procedure :)). In fact, it would take even less code, b/c I had to work around some inconveniences that would not be present if I was modifying the component directly. I don't know how to make a proper patch for you, so I'm submitting my code as a separate component in case you decide to use it to augment the existing _InplaceSelect_.
|HtmlFilteredLabelInplaceSelect|Component that holds the new attribue|
|FilteredLabelInplaceSelectHandler|Sets the label filter MethodExpression on HtmlFilteredLabelInplaceSelect|
|FilteredLabelInplaceSelectRenderer|Renders some javascript that augments the existing client side code|
|filteredLabelInplaceSelect.js|Overrides applyTmpValue() and findLabel() so they know how to get at the filtered label|
\\
I hope this will be useful and my apologies for not submitting a proper patch (no time to learn how at the moment).
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the richfaces-issues
mailing list