HTML and CSS Reference
In-Depth Information
Listing 9-12.
processDrop Method of RightCountry Managed Bean
public void processDrop(DropEvent event) {
Place place = (Place) event.getDragValue();
String dropValue = (String) event.getDropValue();
switch (dropValue) {
case "Egypt":
egyptPlaces.add(place);
places.remove(place);
break;
//...
}
if (places.size() == 0) {
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage("Congratulations! You are done."));
initialize();
}
}
You may notice that after all of the elements in the drag source panel are consumed (dropped to their
corresponding suitable targets), a Faces message is created to show the user
"Congratulations! you are
done."
and the page information is reset using
initialize()
method; this Faces message will be displayed by
<rich:notifyMessages>
, which is shown in Listing 9-13.
Like the Egypt drop target, the other drop targets for Germany and Brazil work the same way. Listing 9-13 shows
the complete code of the
Right Country
application page.
Listing 9-13.
Right Country Application Page
<html xmlns="
http://www.w3.org/1999/xhtml
"
xmlns:rich="
http://richfaces.org/rich
"
xmlns:a4j="
http://richfaces.org/a4j
"
xmlns:f="
http://java.sun.com/jsf/core
"
xmlns:h="
http://java.sun.com/jsf/html
"
>
<h:head>
<title>Welcome to the Right Country application</title>
<h:outputStylesheet library="css" name="rightCountry.css" />
</h:head>
<h:body>
<rich:dragIndicator id="ind" acceptClass="accept" rejectClass="reject"
draggingClass="default">
Drag the place to the right country
</rich:dragIndicator>
<h:form id="form">
<h2>Drag the places to the right country</h2>
<h:panelGrid columnClasses="column" columns="4"
styleClass="containerPanel">
<rich:panel styleClass="dropSourcePanel">