Skip to content

Instantly share code, notes, and snippets.

@uklance
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uklance/55f7d1900a274031ec60 to your computer and use it in GitHub Desktop.
Save uklance/55f7d1900a274031ec60 to your computer and use it in GitHub Desktop.
Tapestry5 Dialog Avoiding Nested Forms
public interface BlockContainer {
void addBlock(Block block);
}
public class Dialog {
@Environmental
private BlockContainer blockContainer;
@Inject
private ComponentResources componentResources;
@Inject
private Block mainBlock;
public void setupRender() {
blockContainer.addBlock(mainBlock);
}
public boolean beforeRenderBody() {
// don't render body, this will be done in the layout
return false;
}
}
<t:block t:id="mainBlock">
<t:form>
<!-- render the fields in the dialog body -->
<t:body />
</t:form>
</t:block>
public class Layout {
@Inject
private Environment environment;
@Inject
private TypeCoercer typeCoercer;
private List<Block> blocks;
public void setupRender() {
blocks = new ArrayList<Block>();
environment.push(BlockContainer.class, new BlockContainer() {
public void addBlock(Block block) {
blocks.add(block);
}
});
}
public RenderCommand afterRenderBody() {
environment.pop(BlockContainer.class);
RenderCommand command = new RenderCommand() {
public void render(MarkupWriter writer, RenderQueue queue) {
for (Block block : blocks) {
RenderCommand subCommand = typeCoercer.coerce(block, RenderCommand.class);
subCommand.render(writer, queue);
}
}
};
return command;
}
}
<t:form>
Main Form Field 1: <t:textfield ... />
Main Form Field 2: <t:select ... />
<t:dialog>
Dialog Field 1: <t:textfield ... />
Dialog Field 2: <t:textfield ... />
</t:dialog>
</t:form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment