Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Selecting buttons in a RadioButtonGroup
Selecting buttons in a RadioButtonGroup [message #1841384] Thu, 13 May 2021 23:39 Go to next message
J D is currently offline J DFriend
Messages: 99
Registered: February 2021
Member
Hi there everyone,

I have an RadioButtonGroup based on the GenderCodeType in the one day tutorial.

I am trying to select buttons in the group based on the values in an EntityDo field.

This is the code I'm using

    if (employee.gender().get().equals(TEXTS.get("Male"))) {
      getGenderGroup().getButtonFor(MaleCode.ID).setSelected(true);
    } else if (employee.gender().get().equals(TEXTS.get("Female"))) {
      getGenderGroup().getButtonFor(FemaleCode.ID).setSelected(true);
    } else if (employee.gender().get().equals(TEXTS.get("X"))) {
      getGenderGroup().getButtonFor(XCode.ID).setSelected(true);
    }


However, I keep getting a java.lang.NullPointerException: null on each of the lines where I try to setSelected(true).

What am I doing wrong?

Cheers,

JD
Re: Selecting buttons in a RadioButtonGroup [message #1841403 is a reply to message #1841384] Fri, 14 May 2021 13:42 Go to previous messageGo to next message
Beat Schwarzentrub is currently offline Beat SchwarzentrubFriend
Messages: 205
Registered: November 2010
Senior Member
This should work. I recommend setting a break point and inspecting the data. You can also step into the getButtonFor() method to see which buttons are available and what their "radio value" is. If you have multiple classes of the same name in your workspace (e.g. two different GenderCodeTypes), ensure that you use the correct imports.

Two additional remarks:

  • Radio button groups are value fields, so you might be able so simplify your code to something like this: getGenderGroup().setValue(extractGenderCode(employee)).
  • I don't now exactly how your application is structured, but in general "enum" values should always be stored as technical ID and not as a display text. TEXTS.get() might return different values for users with different languages, so your "if" statements would fail if a record stored by user with language A is opened by another user with language B. That's exactly why RadioButtons (and SmartFields) always provide the key as their value, not the display text.


Regards,
Beat
Re: Selecting buttons in a RadioButtonGroup [message #1841419 is a reply to message #1841403] Sat, 15 May 2021 09:03 Go to previous message
J D is currently offline J DFriend
Messages: 99
Registered: February 2021
Member
@Beat

Thanks a lot for your reply.

My GenderCodeType.java, a simple modification of the one in the one day tutorial, looks like this:

public class GenderCodeType extends AbstractCodeType<String, String> {

  private static final long serialVersionUID = 1L;
  public static final String ID = "Gender";

  @Override
  public String getId() {
    return ID;
  }

  @Order(1000)
  public static class MaleCode extends AbstractCode<String> {

    private static final long serialVersionUID = 1L;
    public static final String ID = "M";

    @Override
    protected String getConfiguredText() {
      return TEXTS.get("Male");
    }

    @Override
    public String getId() {
      return ID;
    }
  }

  @Order(2000)
  public static class FemaleCode extends AbstractCode<String> {

    private static final long serialVersionUID = 1L;
    public static final String ID = "F";

    @Override
    protected String getConfiguredText() {
      return TEXTS.get("Female");
    }

    @Override
    public String getId() {
      return ID;
    }
  }

  @Order(3000)
  public static class XCode extends AbstractCode<String> {

    private static final long serialVersionUID = 1L;
    public static final String ID = "X";

    @Override
    protected String getConfiguredText() {
      return TEXTS.get("X");
    }

    @Override
    public String getId() {
      return ID;
    }
  }
}


Thanks for your suggestions on TEXTS.get(). But my code should work with the GenderCodeType.java above, I believe.

Cheers,

JD
Previous Topic:How REST call token can be injected in the RunContext as Principal
Next Topic:Scout Version 11.0 HelloScout App. Error by start [webapp] all. Not found eslint modules
Goto Forum:
  


Current Time: Mon Apr 15 13:11:29 GMT 2024

Powered by FUDForum. Page generated in 0.64470 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top