• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

access ui components in custom valuechangelistener

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, working with jsf 1.2 n am trying to dynamically construct a group of radiobuttongroups inside an htmlgrid - so my valuechangelistener is not specified in the jsp component. my code is below

firstly i have a custom listener which I initialize as -
CustomRadioButtonValueChangeListener listener = new CustomRadioButtonValueChangeListener();

then, my java bean code has -

for(Declarations decl : (List<Declarations>)declarationsList){
Label label = new Label();
label.setId(decl.getCode() + "label");
label.setText(decl.getDescription());
label.setStyleClass("formButtonGroupListItemLabel1");

RadioButtonGroup rbg = getRadioButtonGroup();
rbg.setValue(NO);
rbg.setId((String)decl.getCode());//rbg.setLabel("Yes");
rbg.setOnChange("setModified();submit();");
rbg.addValueChangeListener(listener);

TextArea tArea = new TextArea();
tArea.setId(decl.getCode() + "TextArea");
tArea.setRows(5);
tArea.setColumns(100);
tArea.setText("");
tArea.setRequired(true);
//tArea.setDisabled(true);
declarationDetailsPanel.getChildren().add(label);
declarationDetailsPanel.getChildren().add(rbg);
declarationDetailsPanel.getChildren().add(tArea);
}

Now, what I want to do is, on click of a radio button, I want to enable/disable the corersponding textarea's.

In the custom listener I'm unable to get hold of the TextArea object that I want to control.
I tried FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(event.getComponent().getId + "TextArea"); //this should translate to "Declaration1TextArea" for the first radio button group and so on....

Can anyone help or give ideas on how to access the UI Components in this listener class.

cheers
p
 
Saloon Keeper
Posts: 27808
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any time you resort to javax.faces classes for anything other than datamodels, there's a strong possibility you're doing things the hard way.

I'm going to assume that you want partial page updating where the radio button enables/disables the textarea without actually re-rendering the entire page.

To do that, however, you need AJAX, since the default (non-AJAX) behavior is that the entire form would be submitted and the entire page would be redrawn. Plus, to make a radio button submit at all, it has to have attached JavaScript code, since a radio button isn't a submit button.

Which AJAX framework you use it up to you. Here's how it would look in RichFaces, however (more or less).


The client-side code looks like this:


Note the complete absence of JSF-specific code. It's all done with POJO stuff.

Note also, however, that this particular example doesn't do the full enable/disable, but that's because of UI concerns. A Radio button isn't a boolean control, so you can't click-on/click-off. For that you should use a checkbox. You can have 2 radio buttons and enable/disable based on which one of them is clicked, however.
reply
    Bookmark Topic Watch Topic
  • New Topic