select Item and invoke information to display on same page
My question is I have constructed a list of books into selectOneListBox. And everytime I select an item it will display the information of tha book beside the listbox on the same page.
My concern is the information jsp should be generated dynamically upon selection. How will the back bean work to display the infromation after it has retrieve the data from a server?
[381 byte] By [
Intel3a] at [2007-11-27 10:59:40]

# 1
You can use the 'rendered' attribute to display/hide components.
Basic example:<h:panelGrid columns="2" rendered="#{myBean.selectedBook != null}">
<h:outputText value="Title" />
<h:outputText value="#{myBean.selectedBook.title}" />
<h:outputText value="Author" />
<h:outputText value="#{myBean.selectedBook.author}" />
<h:outputText value="Price" />
<h:outputText value="#{myBean.selectedBook.price}" />
</h:panelGrid>
# 2
Here is my code sample:
testing.jsp:
<tr>
<td>
<table style="width: 100%">
<tr>
<td >
<f:view>
<h:form>
<h:selectOneListbox valueChangeListener="#{Tester.listen}"
size="7" required="yes" onchange="this.form.submit()">
<f:selectItem itemLabel="one" itemValue="1" />
<f:selectItem itemLabel="two" itemValue="2" />
<f:selectItem itemLabel="three" itemValue="3" />
<f:selectItem itemLabel="four" itemValue="4" />
</h:selectOneListbox>
</h:form>
</f:view>
</td>
<td>
<h:panelGrid columns="2" rendered="#{Tester.selected != null}">
<h:outputText value="Test" />
<h:outputText value="#{Tester.myTest}" />
</h:panelGrid>
</td>
</tr>
</table>
</td>
</tr>
Tester.java
public void listen(ValueChangeEvent e){
check = true;
System.out.println("hello world");
myTest = "OMG I hope this works";
FacesContext face = FacesContext.getCurrentInstance();
face.renderResponse();
}
public boolean selected()
{
return check;
}
where myTest is a String variable
How do i get the rendering to work and the facescontext to refresh my page when the valueChangeListener is triggered. So that the components are now displaying rather then hiding.
Should I do it another way that when listener is triggered I display another jsp page containing the information. Would this way be better? How can this be done?
# 3
rendered="#{Tester.selected != null}"
You're comparing a boolean datatype against null. Also the backing bean's method 'selected()' has a wrong name.
Fix it as follows:rendered="#{myBean.selected}"
public boolean isSelected() {
return selected;
}