Skip to content

Instantly share code, notes, and snippets.

@jvanzyl
Created September 6, 2010 03:33
Show Gist options
  • Save jvanzyl/566608 to your computer and use it in GitHub Desktop.
Save jvanzyl/566608 to your computer and use it in GitHub Desktop.
package org.sonatype.idiom.site;
import java.util.logging.Logger;
import javax.inject.Inject;
import org.sonatype.idiom.site.form.Form;
import org.sonatype.idiom.site.processor.Processor;
import com.google.inject.name.Named;
import com.google.sitebricks.At;
import com.google.sitebricks.headless.Reply;
import com.google.sitebricks.headless.Service;
import com.google.sitebricks.http.Get;
import com.google.sitebricks.http.Post;
@At( "/form/:productId" )
@Service
public class FormService
extends AbstractService
{
@Inject
private Logger logger;
private Form form = new Form();
@Inject @Named("loopfuse")
private Processor loopfuse;
@Inject @Named("mailer")
private Processor mailer;
@Inject @Named("download")
private Processor downloadLinkProvider;
@Get
public Reply<String> get( @Named( "productId" ) String product )
{
return Reply.with( renderTemplate( "FormPage.html" ) ).type( "application/xhtml+xml" );
}
@Post
public Reply<String> post( @Named( "productId" ) String product )
{
//
// The form will now be populated and we can store and process the
// form information.
//
form.productId = product;
//
// Perform any processing of the form data. We might want to submit to an
// external system, collect the submission in a database, email the user
// a link, etc.
//
downloadLinkProvider.process( form );
loopfuse.process( form );
mailer.process( form );
//
// Need to respond with a page for the user showing the results
// of the form submission
//
return Reply.with( renderTemplate( "FormPage.html" ) ).type( "application/xhtml+xml" );
}
public void setFirstName( String firstName ) { form.firstName = firstName; }
public void setLastName( String lastName ) { form.lastName = lastName; }
public void setEmail( String email ) { form.email = email; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment