2 Replies Latest reply on Aug 25, 2008 11:38 PM by Greg Zoller

    Newbie Question: Javascript Files in Richfaces

    Greg Zoller Newbie


      I'm trying to modify the behavior of rich:inplaceSelect, specifically the I want to change the value shown in the input field after a selection is made by the user using the pull-down menu.

      I notice in the code there are two javascript files that appear to drive the actual rendering of the widget. How are parameters passed from Java to Javascript? For example I see in inplaceselect.js there are several fields that must come from the Java side at some point, presumably set as attributes on the JSF tag.

      Richfaces.InplaceSelect = Class.create(Richfaces.InplaceInput, {
       initialize : function($super, listObj, clientId, temValueKeepId, valueKeepId, tabberId, attributes, events, classes, barParams, buttonId) {

      Who calls this function (in inplaceselect.js) and how might I get a new parameter 'foobar' passed to it?

      Adding a new attribute to rich:inplaceSelect tag on the Java side is straightforward enough but somehow I need to get this attribute to these javascript files that (I think) are actually drawing the widget.

      Thanks for any info!

        • 1. Re: Newbie Question: Javascript Files in Richfaces
          Nick Belaevski Master

          Hello Greg,

          That happens in component renderers. There are renderers of two origins in Richfaces:

          1. Fully Java-coded. Such renderers are used for relatively simple components that doesn't produce complex markup. Also Java-coded renderers are used as base classes for the second origin renderers:

          2. CDK (Component Development Kit) templates. That are the JSP-like files compiled into Java code during project build.

          Javascript initialization code of inplaceSelect component comes from template, here it is: http://fisheye.jboss.org/browse/RichFaces/trunk/ui/inplaceSelect/src/main/templates/inplaceselect.jspx?r=10169. Please see lines 202-237 .

          Please note that there only a few components that are fully drawn using Javascript (calendar & dragIndicator are the only ones I can remember now). Renderers output HTML code for components and then script makes components live.

          P.S. CDK guide that might be interesting to you will appear here soon: http://www.jboss.org/jbossrichfaces/docs/ .
          You can get it here for now: http://snapshots.jboss.org/maven2/org/richfaces/docs/cdkguide/en/3.2.2-SNAPSHOT/ (un-jar the latest file)

          • 2. Re: Newbie Question: Javascript Files in Richfaces
            Greg Zoller Newbie

            Thank you so much, this file though a work in progress, contained exactly the information I needed to fill the biggest gaps in my understanding.

            So now I have completed my modification to InplaceSelect. I'm quite happy to use it myself but was wondering how I might submit the change back into the main code base (if anyone else cares about this functionality).

            What it does is this: Have you ever wanted to use a select widget in a situation where you have limited horizontal real estate--perhaps in a table of some kind? In this situation you'd love to have the pull-down display verbose descriptions of each option but when the user selects an option merely show the (presumably short) value in the field.

            Every select widget I found populated by SelectItems either let you show the value (by having null label) or a label, but not mix 'n match the two. My mod (new attribute showValueInView) allows this.

            For example a InplaceSelect widget may contain value/label pairs like this:

            "DFW", "(DFW) Dallas Regional Center"
            "RDU", "(RDU) Raleigh Mid-Eastern Center"
            "ATL", "(ATL) Atlanta South-Eastern Center"

            My modded InplaceSelect w/showValueInView=true will show the long label descriptions in the pull-down but only show the short value in the input field when an item is selected. Value sent to the backing bean is unaffected--value as usual.

            It's a little different, but trust me, if you're cramped for space this little tweak is a life-saver.