RE: preselect a radio button based on a value

Vijay Balakrishnan <[email protected]>
Newsgroups gmane.comp.java.enhydra.barracuda.general
Message-ID <[email protected]>
Hi Jacob,
 
Point 1 did not work.I need to have 2 separate id's for the radio button.
 
I did not understand Point 2.
 
But I did get it to work in a weird way as i don't get it.
 
1.
My directives were as follows:
poolAllocateAction=Dir::Get_Data.PoolAllocateModel.formAction

poolName=Dir::Get_Data.PoolAllocateModel.poolName

allocate=Dir::Get_Data.PoolAllocateModel.allocate<=======================I
use the "name" attribute here

submit=Dir::Get_Data.PoolAllocateModel.submit

cancel=Dir::Get_Data.PoolAllocateModel.cancel

2.
Here is my method:
 
private BToggleButton getRadioButton(String typeStr) {

boolean selA = false;

boolean selH = false;

BToggleButton btbComp = null;

if (typeStr != null && typeStr.equalsIgnoreCase("A")) {

selA = true;

btbComp = new BToggleButton(BInput.RADIO,"allocate","A",selA);

} else if (typeStr != null && typeStr.equalsIgnoreCase("H")) {

selH = true;

btbComp = new BToggleButton(BInput.RADIO,"allocate","H",selH);

} else if (typeStr == null) {

btbComp = new BToggleButton(BInput.RADIO,"allocate","H",false);

btbComp = new BToggleButton(BInput.RADIO,"allocate","A",true); <== I wanted
to have A show upa s selected if no value was selected.Putting 'H' after A
resulted in none being selected.

}

3. Here is my code for the templateView in the handleViewEvent:

if (allocate == null) {

allocateSelected = 0;

} else if (allocate.equalsIgnoreCase("H")) {

allocateSelected = 1;

} else {

allocateSelected = 0;

}

NodeList allocateNodeList = page.getElementsByName("allocate");

Node allocateNode = allocateNodeList.item(allocateSelected);

TemplateView allocateView = new DefaultTemplateView(allocateNode,"name",

new MapStateMap(modelProps));

 

I got it working but I am confused esp about the getRadioButton() method and
how it is working !!!!!

 

Thanks for all your help till now,

Vijay

 

 

 

 

 

-----Original Message-----
From: Jacob Kjome [mailto:[email protected]] 
Sent: Friday, June 13, 2003 10:50 AM
To: Vijay Balakrishnan
Subject: Re: [Barracuda] preselect a radio button based on a value


Hi Vijay,

barracudamvc.org seems to be down so I'm replying directly to you.


As I look at your code below, I notice that on the input buttons, you use
the "name" attribute.  Then you try to refer to those key names in your
getItem() method.  However, unless you set the "name" attribute to be the
identifier, the keys in your properties file containing the directives will
never get triggered.  You can solve this in one of 2 ways.

1.  add an "id" attribute with the same value as the "name" attribute to
each respective form element.  Doing this actually is more compatible with
XHTML so you might think stongly about using this technique for forward
compatibility reasons.

2.  set the "name" attribute to be the key in the properties flie using
TemplateView#setIDAttrName(String iidAttrName) or sending the idAttrName
into the appropriate TemplateView constructor.

Make sure to ping the list saying whether this works or not for you so we
know that the issue is resolved or not.  You may have to wait a bit for
barracudamvc.org to come back up again.  Not sure why it is down?

Jake


At 02:45 PM 6/12/2003 -0700, you wrote:



Hi,

I am trying to preselect a  radio button based on a  value.
<input type="radio" value="A" checked name="allocate">
<input type="radio" name="allocate" value="H">
I always get the the value 'A' even though I have set the value for the node
to H.

Here is how I am setting the BToggleButton in the handleViewEvent:

String allocate = (String)session.getAttribute("allocate");

      if (allocate == null) {
        allocateSelected = 0;
      } else if (allocate.equalsIgnoreCase("H")) {
        allocateSelected = 1;
      } else {
        allocateSelected = 0;
      }

      Node         allocateNode =
allocateNodeList.item(allocateSelected);<==== this has the value of "H" in
it
      TemplateView allocateView = new
DefaultTemplateView(allocateNode,"name",
          new MapStateMap(modelProps));

     bodyTemplate.setView(allocateView);
     bodyTemplate.render(new DefaultViewContext(context));
     new DefaultDOMWriter().write(page,context.getResponse());

I also have a getItem(String key) : <=== never seems to get in here
   if (key.equals("allocate")) {
        boolean       selA    = false;
        boolean       selH    = false;
        BToggleButton btbComp = null;

        char          type    = poolDTO.getType();
        String        typeStr = new Character(type).toString();

        if (typeStr != null && typeStr.equalsIgnoreCase("A")) {
          selA = true;
        } else if (typeStr != null && typeStr.equalsIgnoreCase("H")) {
          selH = true;
        }

        btbComp   = new BToggleButton(BInput.RADIO,"allocate","A",selA);

        btbComp = new BToggleButton(BInput.RADIO,"allocate","H",selH);

        return btbComp;
      } 

Any help is appreciated or any example on pre-selecting a radio button based
on an input value would be great.
Thanks,
Vijay
_______________________________________________
Barracuda mailing list
[email protected]
http://barracudamvc.org/lists/listinfo/barracuda
<http://barracudamvc.org/lists/listinfo/barracuda>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.