• 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

Radio slected should populate the Input text box

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am new to JSF, I need to populate input text box with the label of the radio selected.
Following is extract from my code, my issue is that the Text Box is not getting populated with the value selected,please help.

<p><h:selectOneRadio id="formatSelectRadio"

value="#{test.formatName}"

valueChangeListener="#{test.formatOptionChangeListener}"

onclick="submit()"

immediate="true">

<f:selectItem id="summaryOption" itemLabel="Summary Student Information"

itemValue="Summary Student Information" />

<f:selectItem id="extendedOption" itemLabel="Extended Student Information"

itemValue="Extended Student Information" />

</h:selectOneRadio></p>


<p><h:outputLabel for="fileName"

value="Enter your file name " /> <h:inputText

id="fileName" value="#{test.fileName}">

</h:inputText></p>


//////// BAcking bean ////////

public String getFileName() {

return fileName;

}


public void setFileName(String fileName) {

this.fileName = fileName;

}



public final void formatOptionChangeListener(final ValueChangeEvent event) {

if (LOG.isDebugEnabled()) {

LOG.debug("Firing formatOptionChangeListener...");

}


HtmlSelectOneRadio radio = (HtmlSelectOneRadio) FacesContext.getCurrentInstance().getViewRoot().findComponent("dataForm:formatSelectRadio");

if (radio.getValue().toString().equals("Summary Student Information")) {

setFileName("Summary Student Information");

System.out.println("FILENAME 2 " + getFileName());

} else if (radio.getValue().toString().equals("Extended Student Information")) {

setFileName("Extended Student Information");

System.out.println("FILENAME 3 " + getFileName());

}

// return getFileName();

}




 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to put your code in a code tag to make it easier to read before I start looking at it.

 
meera jason
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The changes made where for the inputText instaed of value attribute changed it to binding

<h:inputText id="fileName" binding="#{studentFilter.fileName}"> </h:inputText>

Changed the Backing bean getter setter appropriately

public HtmlInputText getFileName() {
return fileName;
}

public void setFileName(HtmlInputText fileName) {
this.fileName = fileName;
}

Changed the listener method to skip rest of the lifecycle using FacesContext.getCurrentInstance().renderResponse();


public final void formatOptionChangeListener(final ValueChangeEvent event) {
if (LOG.isDebugEnabled()) {
LOG.debug("Firing formatOptionChangeListener...");
}

if (event.getNewValue().equals(SUMMARY)) {
fileName.setValue(SUMMARY);
} else if (event.getNewValue().equals(EXTENDED)) {
fileName.setValue(EXTENDED);
}
FacesContext.getCurrentInstance().renderResponse();

}
 
No holds barred. And no bars holed. Except this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic