Last active
August 29, 2015 14:05
-
-
Save uklance/55f7d1900a274031ec60 to your computer and use it in GitHub Desktop.
Tapestry5 Dialog Avoiding Nested Forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface BlockContainer { | |
void addBlock(Block block); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<t:block t:id="mainBlock"> | |
<t:form> | |
<!-- render the fields in the dialog body --> | |
<t:body /> | |
</t:form> | |
</t:block> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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