Added ShowValueInView attribute to InplaceSelect  (see desc for details)
------------------------------------------------------------------------

                 Key: RF-4302
                 URL: https://jira.jboss.org/jira/browse/RF-4302
             Project: RichFaces
          Issue Type: Patch
            Reporter: Greg Zoller
             Fix For: 3.2.2


(code mods made to 3.2.2.BETA5)

Have you ever wanted a select widget that would allow for verbose labels in the 
pull-down but show only the (shorter) value in the input field after the user 
makes a selection?  This is a big deal if you need editable selection fields in 
a data table or other space-constrained display.  Before the addition of this 
feature you had the option only of seeing labels or values (by not specifying 
labels in your SelectItems), but not the ability to mix both.

For example I have a table that includes a field holding a code, selectable 
from an InplaceSelect widget.  There's not enough real estate to explain what 
the code is though.  With my new ShowValueInView attribute set true I can show 
the user verbose, descriptive labels in the pull-down but only the code (the 
value) when they make their selection.  Cool.

I'm not sure how to make an official patch, so here's a list of the modded 
files (just 3):

inplaceselect.xml --  Added new <property> clause:
                <property>
                        <name>showValueInView</name>
                        <classname>boolean</classname>
                        <description>
                                If true show the SelectItem labels in the 
InplaceSelect's pull-down list but display the value in the field in view mode 
once an item is selected
                        </description>
                    <defaultvalue>false</defaultvalue>
                </property>     

inplaceselect.js -- Added  1 'if' statement to ApplyTmpValue:
        applyTmpValue : function() {
                if (this.comboList.activeItem) {
                        var userLabel = 
this.comboList.activeItem.innerHTML.unescapeHTML();
                        this.currentItemValue = this.comboList.activeItem.value;

                        if( this.attributes.showValueInView == true ) {
                                userLabel = this.currentItemValue;
                        }
                        this.tempValueKeeper.value = userLabel;
                        this.comboList.selectedItem = this.comboList.activeItem;
                }
        },

inplaceselect.jspx -- modifed 2 sections:
(1) -- scriptlet near top of file, added 1 'if' statement:
<jsp:scriptlet>
                <![CDATA[
                         
                Object value = component.getSubmittedValue(); 
                if(value == null) {
                        value = component.getAttributes().get("value");
                        value = getConvertedStringValue(context, 
component,value);
                }       
                String fieldLabel = getSelectedItemLabel(context, component);
                String fieldValue = (String)value;
                if( 
((Boolean)component.getAttributes().get("showValueInView")).booleanValue() == 
true ) {
                        fieldLabel = fieldValue;
                }

(2) Around line 218 or so...added showValueInView attribute to list passed to 
Richfaces.InplaceSelect constructor
                                                                         new 
Richfaces.InplaceSelect(new Richfaces.InplaceSelectList('list#{clientId}', 
'listParent#{clientId}', true, 
                                                                                
                                                                                
                                 Richfaces.InplaceSelect.CLASSES.COMBO_LIST, 
'#{component.attributes["listWidth"]}', 
'#{component.attributes["listHeight"]}',  #{this:getItemsTextAsJSArray(context, 
component,items)}, null, 
                                                                                
                                                                                
                                '#{clientId}inplaceTmpValue', 
'shadow#{clientId}', 0, 0, #{encodedFieldValue}), 
                                                                                
                                                        '#{clientId}', 
'#{clientId}inplaceTmpValue', 
                                                                                
                                                        
'#{clientId}inplaceValue', '#{clientId}tabber',
                                                                                
                                                         {defaultLabel : 
'#{component.attributes["defaultLabel"]}', 
                                                                                
                                                          showControls : 
#{component.attributes["showControls"]},
                                                                                
                                                          editEvent : 
'#{component.attributes["editEvent"]}',
                                                                                
                                                          verticalPosition : 
'#{component.attributes["controlsVerticalPosition"]}',
                                                                                
                                                          horizontalPosition : 
'#{component.attributes["controlsHorizontalPosition"]}',
                                                                                
                                                          inputWidth : 
'#{component.attributes["selectWidth"]}',
                                                                                
                                                          minInputWidth : 
'#{component.attributes["minSelectWidth"]}',
                                                                                
                                                          maxInputWidth : 
'#{component.attributes["maxSelectWidth"]}',
                                                                                
                                                          openOnEdit: 
#{component.attributes["openOnEdit"]},
                                                                                
                                                          showValueInView: 
#{component.attributes["showValueInView"]},
                                                                                
                                                          closeOnSelect: true}, 
                                                                                
                                                         {oneditactivation : 
#{this:getAsEventHandler(context, component, "oneditactivation")}, 
                                                                                
                                                         onviewactivation : 
#{this:getAsEventHandler(context, component, "onviewactivation")}, 
                                                                                
                                                         oneditactivated : 
#{this:getAsEventHandler(context, component, "oneditactivated")}, 
                                                                                
                                                         onviewactivated : 
#{this:getAsEventHandler(context, component, "onviewactivated")},
                                                                                
                                                         onchange : 
#{this:getAsEventHandler(context, component, "onchange")}}, 
                                                                                
                                                        
Richfaces.InplaceSelect.CLASSES, 
                                                                                
                                                        ['#{clientId}bar', 
'#{clientId}ok', '#{clientId}cancel', '#{clientId}buttons', 
'#{clientId}btns_shadow'], '#{clientId}inselArrow');


That's it!
I hope others will find this little tweak as useful as I did.  So far I haven't 
found any other select-type widget that allows this hibrid approach.

My apologies if this isn't the right way to submit code.  First time :-)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        
_______________________________________________
richfaces-issues mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/richfaces-issues

Reply via email to