• Post Reply Bookmark Topic Watch Topic
  • New Topic

Choose All option in <h:selectOneRadio

 
Amul Sree
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a requirement to create 3 radio buttons with Values 0, 1 and both. The problem is choosing the all option, in all option, i should list all the values with active flag value of both 0 and 1. Active Flag is tinyint value in table and byte type in bean class.

Here is my xhtml code and backing bean code.

<h:selectOneRadio value="#{faPrincipiaCntrprtyList.activeFlag}">
<f:selectItem itemLabel="Active" itemValue="1"/>
<f:selectItem itemLabel="InActive" itemValue="0" />
<f:selectItem itemLabel="All" itemValue="?"/>
</h:selectOneRadio>


Bean class code:

@Name("faPrincipiaCntrprtyList")
@Scope(ScopeType.CONVERSATION)
public class FaPrincipiaCntrprtyList extends
FaPrincipiaCntrprtyQuery<FaPrincipiaCntrprty> {

/**
*
*/
private static final long serialVersionUID = 1L;

private byte activeFlag = 1;

private static final String EJBQL = "select faPrincipiaCntrprty from FaPrincipiaCntrprty faPrincipiaCntrprty";

private static final String[] RESTRICTIONS = { "lower(faPrincipiaCntrprty.cntrprtyCode) like lower(concat(#{faPrincipiaCntrprtyList.faPrincipiaCntrprty.cntrprtyCode},'%'))",
"faPrincipiaCntrprty.activeFlag = #{faPrincipiaCntrprtyList.activeFlag}",
};

private FaPrincipiaCntrprty faPrincipiaCntrprty = new FaPrincipiaCntrprty();

public FaPrincipiaCntrprtyList() {
setEjbql(EJBQL);
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setMaxResults(10);
}

public byte getActiveFlag() {
return activeFlag;
}
public void setActiveFlag(byte activeFlag) {
this.activeFlag = activeFlag;
}

public FaPrincipiaCntrprty getFaPrincipiaCntrprty() {
return faPrincipiaCntrprty;
}
}


Thanks in advance!
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Helpful hint: use the "Code" button on our message editor to insert code tags around your sample pre-formatted text (java code, XML, etc.). It makes them much easier for people to read.

You requirement is defective. Radio buttons differ from check boxes in that you can select none, 1 or many check boxes in a group, but you can select one and only one radio button at a time.

The name "radio button" itself comes from an analogy with the controls on old-time automobile radios, although there were other devices (including some home radios) that used the same mechanism. You can only tune a radio to one station (frequency) at a time. The radio buttons made tuning easier by providing pushbutton presets for the frequencies you wanted to "speed dial", to to speak. Instead of spinning the tuning knob, you pressed the button you'd reserved for the station you wanted to listen to.

Most radio button controls were made such that once pressed, the selection button stayed pressed. However, if you pressed another button to switch to another station, the previous button would pop back out. So you could tell just by looking at the buttons which station had been selected.

The JSF SelectOneRadiobutton control works the same way. All related buttons in a group have the same value property. The actual value is determined by whichever button is last "pressed". There's no mechanism for storing multiple values as you would have to if multiple buttons could be pressed.

For that, you need the checkbox controls.
 
Amul Sree
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim!

But I am trying to add IN clause in backing bean. I am not sure if it works or not, since iam very new to Seam.

"faPrincipiaCntrprty.activeFlag IN #{faPrincipiaCntrprtyList.activeFlagList}"
 
Tim Holloway
Bartender
Posts: 18408
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As usual, I didn't see something important when I first read your post.

What you really want, it seems is 3 button choices:

o Active items
o Inactive items
o All items (active and inactive)

First, don't bother with tinyInt for stuff like this. Any storage efficiency you gain is probably going to be lost by the extra overhead that the JVM has to go through to convert the tinyInt to/from a regular int. Leave that for your database model, not the UI view model.

Secondly, did you really think that it would be possible to assign an INTEGER a value of (0, 1, or "?"). Try something like 0, 1, 2 instead. Or else use a character to hold the value instead of an int.

I never really got into Seam back when it was popular. So I'm not sure about some of its capabilities. Using JPA in the backing bean, I'd probably use a querybuilder. You don't want to code complex logic in the View Template EL, if that's what you were looking to do. Whether it's Seam or straight JSF, debugging EL is a so it's better to simply put Java code in a backing bean property.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!