Skip to content

Instantly share code, notes, and snippets.

@justinwyer
Created April 13, 2011 09:15
Show Gist options
  • Save justinwyer/917246 to your computer and use it in GitHub Desktop.
Save justinwyer/917246 to your computer and use it in GitHub Desktop.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<rich:panel>
<f:facet name="header">Test</f:facet>
<h:panelGroup layout="block" style="text-align: center;">
<rich:messages id="messages" globalOnly="true"/>
</h:panelGroup>
<h:form id="form">
<rich:popupPanel id="confirmation" modal="false" show="false" height="110" onshow="#{rich:component('confirmation')}.moveTo(100,#{rich:component('confirmation')}.getLeft());">
<f:facet name="header">
<h:outputText value="Confirmation" />
</f:facet>
<h:panelGroup style="padding-top: 5px; text-align: center;" layout="block">
<h:outputText value="Are you sure ?"/>
</h:panelGroup>
<h:commandButton action="#{test.submit}" value="Yes" onclick="#{rich:component('confirmation')}.hide(); return true;">
<a4j:ajax event="click" listener="#{test.submit}" execute="@form" render="@all"/>
</h:commandButton>
<h:commandButton value="No">
<rich:componentControl target="confirmation" operation="hide" />
</h:commandButton>
</rich:popupPanel>
<h:panelGrid columns="3">
<h:outputLabel for="selectStuff" value="Stuff:">
</h:outputLabel>
<rich:select id="selectStuff" value="#{test.first}" defaultLabel="Select Stuff"
required="true" requiredMessage="Stuff must be selected.">
<f:selectItems value="#{test.stuff}" var="stuff" itemLabel="#{stuff}" itemValue="#{stuff}" />
<f:ajax event="selectitem" render="form:selectMoreStuff @this"/>
</rich:select>
<h:message for="selectStuff" styleClass="message" errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"/>
<h:outputLabel for="selectMoreStuff" value="More Stuff:">
</h:outputLabel>
<rich:select id ="selectMoreStuff" value="#{test.second}" defaultLabel="Select more stuff"
required="true" requiredMessage="More stuff must be selected.">
<f:selectItems value="#{test.moreStuff}" var="moreStuff" itemLabel="#{moreStuff}" itemValue="#{moreStuff}" />
<f:ajax event="selectitem" render="@this"/>
</rich:select>
</h:panelGrid>
<h:commandButton value="Submit">
<rich:componentControl target="confirmation" operation="show" />
</h:commandButton>
</h:form>
<rich:popupPanel id="completion" modal="true" show="#{test.show}" height="110" onshow="#{rich:component('completion')}.moveTo(100,#{rich:component('completion')}.getLeft());">
<h:form id="completionform">
<f:facet name="header">
<h:outputText value="Completed" />
</f:facet>
<h:panelGroup style="padding-top: 5px; text-align: center;" layout="block">
<h:outputText value="Click Ok"/>
</h:panelGroup>
<h:commandButton action="#{test.complete}" value="Ok">
</h:commandButton>
</h:form>
</rich:popupPanel>
</rich:panel>
</h:body>
</html>
package playground;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.ejb.Stateful;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@Named
@Stateful
@SessionScoped
public class Test
{
private String first;
private String second;
private boolean show;
public List<String> getStuff()
{
return Arrays.asList(new String[]{"Pets", "Fruit", "Sports"});
}
public List<String> getMoreStuff()
{
if (getFirst() == null)
return new ArrayList<String>();
if (getFirst().equals("Pets"))
return Arrays.asList(new String[]{"Cat", "Dog", "Rabbit"});
else if (getFirst().equals("Fruit"))
return Arrays.asList(new String[]{"Apple", "Orange", "Banana"});
else if (getFirst().equals("Sports"))
return Arrays.asList(new String[]{"Cricket", "Tennis", "Rugby"});
else
return new ArrayList<String>();
}
public void submit()
{
setShow(true);
}
public void complete()
{
System.out.println("Complete.");
setShow(false);
}
/**
* @return the first
*/
public String getFirst()
{
return first;
}
/**
* @param first the first to set
*/
public void setFirst(String first)
{
this.first = first;
}
/**
* @return the second
*/
public String getSecond()
{
return second;
}
/**
* @param second the second to set
*/
public void setSecond(String second)
{
this.second = second;
}
/**
* @return the show
*/
public boolean isShow()
{
return show;
}
/**
* @param show the show to set
*/
public void setShow(boolean show)
{
this.show = show;
}
}
@justinwyer
Copy link
Author

The Ok button in the completion popup has to be clicked twice for the Test.complete() method to be called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment