Combobox / Listener Question
red247 Apr 24, 2008 3:35 PMI have been trying to get a listener to work for a richfaces combobox using SEAM.
The following is the combobox code, which is trying to trigger the listener:
<aj4:region id="selectView" rerender="treeView">
<h:form>
<rich:comboBox
id="selectedView"
value="#{display.state}"
onSelect="this.form.submit()"
valueChangeListener="#{display.switchView}"
reRender="treeView">
<f:selectItem itemValue="Alarms"/>
<f:selectItem itemValue="Alarm Definitions"/>
<f:selectItem itemValue="Locations"/>
</rich:comboBox>
</h:form>
</aj4:region>
The next set of code is the EJB interface, which defines the method to catch the event.
import javax.ejb.Local;
import javax.faces.event.ValueChangeEvent;
@Local
public interface Display {
public void display();
public void destroy();
public String getState();
public void setState(String state);
public void switchView(ValueChangeEvent event);
}
Then the remainder is the bean implementation to handle the event.
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.faces.event.ValueChangeEvent;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.log.Log;
@Stateful
@Name("display")
@Scope(ScopeType.SESSION)
public class DisplayBean implements Display {
private static final String DEFAULT_VIEW_STATE = "Locations";
@Logger
private Log log;
@In
FacesMessages facesMessages;
// private String value;
private String state = DEFAULT_VIEW_STATE;
public void display()
{
//implement your business logic here
log.info("display.display() action called with: #{display.value}");
facesMessages.add("display #{display.value}");
}
public String getState(){
return state;
}
public void setState( String state ){
this.state = state;
}
@Destroy @Remove
public void destroy() {}
public void switchView(ValueChangeEvent event) {
log.info("listener triggered");
log.info("New value: " + event.getNewValue().toString() );
}
}
When the page is rendered, the combobox and the rest of the display show up properly. But when I select a different value, nothing happens. Any help you could provide would be greatly appeciated.
Regards,
M.