[Logo] Enterprise Client Community
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
t:combobox -> String and/or Object  XML
Forum Index -> Development
Author Message
wocher

Power User
[Avatar]

Joined: 14/04/2008 13:10:19
Messages: 49
Location: Ravensburg
Offline

current only a string are allowed.
the user select one entry and this string return.
by multilanguage so i must translate this strings to find out what the user selected.
e.g. a enum.

when the combobox taken a object and the .toString() gives the text to shown.
or the combo object taken objects that implements a interface

eg.

public interace ComboboxValue {

/**
* Show the text for the combobox enttry
*/
public String getText ();

/**
* Sow a description for the combobox entry
*/
public String getDescription();

}

„Ein Haus ohne Bücher ist arm, auch wenn schöne Teppiche seinen Boden und kostbare Tapeten und Bilder die Wände bedecken.“
Hermann Hesse, Dichter, Schriftsteller und Maler * 02. 07. 1877 - Calw † 09. 08. 1962 - Montagnola, Schweiz

Rainer Wocher Quentia Development GmbH (Sotware Developer)
[ICQ]
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

Hi,

the COMBOBOX receives items which are id and text based (both strings). The id is the language independent string that is passed to the VALUE property, the text is the one displayed by default in the combo box. So there is a normal separation between "id" and "language dependent" text.

At the end there needs to be a translation from object to id and from id to object, because the frontend is running on a different system than the backend. No chance to pass pointer references... ;-)

Of course you could build an own class within your managed bean, that is dealing with this aspect: currently you pass a VALUE (e.g. "#{d.xyz.department}") and a VALIDVALUESBINDING (e.g. "#{d.xyz.departmentValues}"). Now you could build up one class providing both and dealing with the transaltion as you request it: in this case then VALUE would bind to #{d.xyz.cbdep.value} and the VALIDVALUESBINDING to #{d.xyz.cbdeb.valdidvalues}. Inside the class behin "cbdep" you could implement a generic class for managing what you want to do.

Is this understand-able....? I am not 100% sure. Pls give me feedback...

Björn




Björn Müller, CaptainCasa GmbH
CaptainCasa

Power User
[Avatar]

Joined: 21/11/2007 12:23:06
Messages: 5519
Offline

...I wrote a mini example to explaint what I mean...:

This is the client side layout:
Code:
 <f:view>
 <h:form>
 <f:subview id="workplace_democomboobjectsg_37">
 <t:rowbodypane id="g_1" >
   <t:row id="g_2" >
     <t:label id="g_3" text="Department" width="120" />
     <t:combobox id="g_4" validvaluesbinding="#{wp.DemoComboObjects.cbDepartment.vvb}" value="#{wp.DemoComboObjects.cbDepartment.value}" width="200" />
   </t:row>
   <t:rowdistance id="g_5" height="10" />
   <t:row id="g_6" >
     <t:coldistance id="g_7" width="120" />
     <t:button id="g_8" actionListener="#{wp.DemoComboObjects.onOutputSelection}" text="Output Information" />
   </t:row>
 </t:rowbodypane>
 <t:rowstatusbar id="g_9" />
 <t:pageaddons/>
 </f:subview>
 </h:form>
 </f:view>
 



And this is the server side code:

Code:
 package workplace;
 
 import java.io.Serializable;
 
 import javax.faces.event.ActionEvent;
 
 import org.eclnt.editor.annotations.CCGenClass;
 import org.eclnt.jsfserver.defaultscreens.Statusbar;
 import org.eclnt.jsfserver.elements.util.ValidValuesBinding;
 
 @CCGenClass (expressionBase="#{wp.DemoComboObjects}")
 
 public class DemoComboObjects implements Serializable
 {
     // ------------------------------------------------------------------------
     // inner classes
     // ------------------------------------------------------------------------
     
     public interface IWithText
     {
         public String getText();
     }
     
     public class Department 
         implements Serializable, IWithText
     {
         String i_text;
         public String getText() { return i_text; }
         public void setText(String text) { i_text = text; }
         public Department(String text) { i_text = text; }
     }
     
     /**
      * The id that is passed to the client side is the index of the 
      * object within the array.
      */
     public class ComboCounterPart
     {
         IWithText[] i_objects;
         int i_selObjectIndex = -1;
         ValidValuesBinding i_vvb = new ValidValuesBinding();
         public ComboCounterPart(IWithText[] objects)
         {
             i_objects = objects;
             for (int i=0; i<objects.length; i++)
                 i_vvb.addValidValue(""+i,objects[i].getText());
         }
         public ValidValuesBinding getVvb() { return i_vvb; }
         public String getValue() 
         {
             if (i_selObjectIndex < 0)
                 return null;
             else
                 return "" + i_selObjectIndex;
         }
         public void setValue(String value)
         {
             i_selObjectIndex = (new Integer(value)).intValue();
         }
         public IWithText getSelectedObject()
         {
             if (i_selObjectIndex < 0)
                 return null;
             else
                 return i_objects[i_selObjectIndex];
         }
     }
     
     // ------------------------------------------------------------------------
     // members
     // ------------------------------------------------------------------------
     
     ComboCounterPart m_cbDepartment;
     
     // ------------------------------------------------------------------------
     // constructors
     // ------------------------------------------------------------------------
     
     public DemoComboObjects()
     {
         Department[] deps = new Department[]
         {
             new Department("Sales"),
             new Department("Marketing"),
             new Department("Production"),
             new Department("Board")
         };
         m_cbDepartment = new ComboCounterPart(deps);
     }
     
     // ------------------------------------------------------------------------
     // public usage
     // ------------------------------------------------------------------------
     
     public ComboCounterPart getCbDepartment() { return m_cbDepartment; }
     
     public void onOutputSelection(ActionEvent event)
     {
         if (m_cbDepartment.getSelectedObject() != null)
             Statusbar.outputMessage("The selected object is: " + m_cbDepartment.getSelectedObject().getText());
         else
             Statusbar.outputMessage("No selection yet.");
     }
 }
 


The class "ComboBoxCounterPart" is the transferr-er between Objects and Strings. Hope, this makes things clearer...

Björn

Björn Müller, CaptainCasa GmbH
 
Forum Index -> Development
Go to:   
Powered by JForum 2.1.6 © JForum Team