Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Display Value of a SelectItem

    Hi. I want to know how I can obtain the display value of a SelectItem. I am trying to do it using selectitem.getDisplayValue(); but it just doesn't work for me. I can easily obtain the Value using selectitem.getValue(); but the display value ("the value that is shown to the user"), I just can't get access to that.

    This is an example of the code I have.

    Code:
    final SelectItem tallaSelect = new SelectItem(){
    protected Criteria getPickListFilterCriteria(){
    String idModelo = (String) modeloSelect.getDisplayValue();
    Criteria criteria = new Criteria("id_modelo", idModelo);
    return criteria;
    				}
    			};

    #2
    Hi acuellar,

    have you tried to set the value field using SelectItem.setValueField() before to invoke SelectItem.getValueField()? The snippet of code you inserted is not clear: the setting of the values is not shown. Can you please provide a more complete example of what you have?

    Regards,

    Salvatore

    Comment


      #3
      Hi Turiddu, thank you so much for your help. Indeed, I have defined the setValueField. Here is the code there I have.

      I already tried using the getDisplayField() but it just don't work for me. As I said before, the SelectItem.getValue() works great but the SelectItem.getDisplayValue just doesn't work and I need to use the display value.

      This is a more descriptive snippet of my code.

      Best regards.

      Code:
      final SelectItem modeloSelect = new SelectItem();
      			modeloSelect.setName("modeloSelect");
      			modeloSelect.setTitle("Modelo");
      			modeloSelect.setDisplayField("id");
      			modeloSelect.setValueField("id_modelobase");
      			modeloSelect.setOptionDataSource(datasourceModelo);
      			modeloSelect.addChangedHandler(new ChangedHandler() {
      
      				@Override
      				public void onChanged(ChangedEvent event) {
      					form.clearValue("tallaSelect");
      				}
      			});
      
      final SelectItem tallaSelect = new SelectItem() {
      				protected Criteria getPickListFilterCriteria() {
      					String idModelo = (String) modeloSelect.getDisplayValue();
      					Criteria criteria = new Criteria("id_modelo", idModelo);
      					return criteria;
      				}
      			};
      			tallaSelect.setName("tallaSelect");
      			tallaSelect.setTitle("Talla");
      			tallaSelect.setDisplayField("talla");
      			tallaSelect.setValueField("id");
      			tallaSelect.setOptionDataSource(datasourceTalla);

      Comment


        #4
        Hi again,

        I faced a similar situation few days ago. Your SelectItem is connected to a DataSource so the displayField should be a DataSource field. In this case if you invoke SelectItem.getSelectedRecord() you will get the values of all the fields of the selected item (among them you will find the display field name).
        Just for clarify:
        Code:
        ...
        Record currentSelection = yourSelectItem.getSelectedRecord();
        String displayValue = currentSelection.getAttribute(displayValueField);
        I hope this can fix your problem.

        Regards,

        Salvatore

        Comment


          #5
          Hi Turiddu, I used what you wrote and it work!!!, but it send me a NullPointerException message. What can I do to solve this?

          This is how I have it.

          Best regards

          Code:
          final SelectItem tallaSelect = new SelectItem() {
          	protected Criteria getPickListFilterCriteria() {
          	Record currentSelection = modeloSelect.getSelectedRecord();
          	String displayValue = currentSelection.getAttribute("id");
                  String idModelo = displayValue;
          					
          	Criteria criteria = new Criteria("id_modelo", idModelo);
          	return criteria;
          	}

          Comment


            #6
            Post the full null pointer exception your getting.

            Comment


              #7
              Uncaught exception escaped : java.lang.NullPointerException
              null
              See the Development console log for details.
              Register a GWT.setUncaughtExceptionHandler(..) for custom uncaught exception handling.

              This is the message on the developer console.

              WARN:ResultSet:isc_ResultSet_3 (created by: isc_PickListMenu_2):getRange(-1, 0): negative indices not supported, clamping start to 0
              Last edited by acuellar; 18 Jun 2010, 09:57.

              Comment


                #8
                What does the development console show you? My guess is the getSelectedRecord() is causing it.

                Comment


                  #9
                  WARN:ResultSet:isc_ResultSet_3 (created by: isc_PickListMenu_2):getRange(-1, 0): negative indices not supported, clamping start to 0

                  Comment

                  Working...
                  X