aspose file tools*
The moose likes JSF and the fly likes Radio slected should populate the Input text box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Radio slected should populate the Input text box" Watch "Radio slected should populate the Input text box" New topic
Author

Radio slected should populate the Input text box

meera jason
Greenhorn

Joined: Feb 21, 2010
Posts: 2
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><hutputLabel 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();

}




Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

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

Joined: Feb 21, 2010
Posts: 2
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();

}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Radio slected should populate the Input text box