Jakarta ee Struts2-如何为六个几乎相同的JSP编写模板?
我有六个几乎相同的JSP,它们之间的区别在于,它们中的每一个都迭代一个被拆分为第一个属性的枚举 枚举: 六个JSP之一: 这些JSP之间的区别在第七行。我在上面描述的枚举上迭代,但是每个JSP在我的操作中创建的列表上迭代,该列表按照枚举的第一个参数拆分枚举,换句话说,第一个JSP只会带来它的第一个属性等于1的枚举项,第二个JSP将只带来第一个属性等于1的枚举条目,并且继续 有什么建议吗 编辑:拆分枚举的操作:Jakarta ee Struts2-如何为六个几乎相同的JSP编写模板?,jakarta-ee,struts2,enums,Jakarta Ee,Struts2,Enums,我有六个几乎相同的JSP,它们之间的区别在于,它们中的每一个都迭代一个被拆分为第一个属性的枚举 枚举: 六个JSP之一: 这些JSP之间的区别在第七行。我在上面描述的枚举上迭代,但是每个JSP在我的操作中创建的列表上迭代,该列表按照枚举的第一个参数拆分枚举,换句话说,第一个JSP只会带来它的第一个属性等于1的枚举项,第二个JSP将只带来第一个属性等于1的枚举条目,并且继续 有什么建议吗 编辑:拆分枚举的操作: 这些方法中的每一个都将在六个JSP中的每一个中调用。我想知道在运行时应该调用哪个方法。
这些方法中的每一个都将在六个JSP中的每一个中调用。我想知道在运行时应该调用哪个方法。正如@DaveNewton所建议的那样,我将所有GetSegmentOSOrVertical Anything包装到一个方法中,该方法验证URL中传递的参数,并找出应该使用哪个枚举条目 这些方法现在以这种方式编码:
我不确定我是否理解这个问题。如果唯一不同的是将列表传递给JSP,那么为什么需要更多的JSP?@DaveNewton如何为每种情况引用正确的列表?有时列表是segmentosVerticalSaude,有时是segmentosVerticalAuto,有时是SegmentOSVerticalAP等等……既然您知道要调用哪个JSP页面,那么就使用这些知识来确定要传递给单个JSP的列表并迭代该列表。顺便说一句,代码中到处都有过度工程的味道。。。尽量保持简单,它本身会变得复杂。之所以这样叫是因为你这么叫它。叫它同样的东西。如果您不是调用它的人,请将它包装成具有相同名称的东西,或者创建一个基于JSP的自定义标记,您可以将列表传递到每个单独的JSP页面中,或者使用它,然后从每个单独的JSP页面中使用它。也许我应该添加更多代码来更清楚地了解我的问题。
public enum Segmento {
INTERNACAO_DOMICILIAR(Vertical.1, "/relatorios/saude/tiss/internacao/domiciliar", "Internação Domiciliar", Projeto.TISS, Arrays.asList(LinksRelatorios.CAIXA_VISITA, LinksRelatorios.CAIXA_VISITA_EMPRESA, LinksRelatorios.PRODUTIVIDADE_INTERNACAO_DOMICILIAR, LinksRelatorios.PENDENCIAS, LinksRelatorios.SOLICITACAO_INICIAL, LinksRelatorios.SOLICITACAO_PRORROGACAO, LinksRelatorios.TEMPO_RESPOSTA)),
INTERNACAO_CONCIERGE(Vertical.2, "/relatorios/saude/tiss/internacao/concierge", "Internação Concierge", Projeto.TISS, Arrays.asList(LinksRelatorios.INTERNACOES_CONCIERGE)),
OPERADOR_WEB(Vertical.3, "/relatorios/saude/tiss/operadorweb", "Operador Web", Projeto.TISS, Arrays.asList(LinksRelatorios.ATENDIMENTO_ANALITICO, LinksRelatorios.ATENDIMENTO_SINTETICO, LinksRelatorios.TEMPO_ANALISE_ANALITICO, LinksRelatorios.TEMPO_ANALISE_SINTETICO, LinksRelatorios.SLA));
private Vertical vertical;
private String namespace;
private String descricao;
private Projeto projeto;
private List<LinksRelatorios> links;
private Segmento(final Vertical verticalParam, final String namespaceParam, final String descricaoParam,
final Projeto projetoParam, final List<LinksRelatorios> linksParam) {
this.vertical = verticalParam;
this.namespace = namespaceParam;
this.descricao = descricaoParam;
this.projeto = projetoParam;
this.links = linksParam;
}
public Vertical getVertical() {
return this.vertical;
}
public String getNamespace() {
return this.namespace;
}
public String getDescricao() {
return this.descricao;
}
public Projeto getProjeto() {
return this.projeto;
}
public List<LinksRelatorios> getLinks() {
return this.links;
}
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<head>
<script type="text/javascript" src="<s:url value="/includes/js/botoes/links.js" />"></script>
</head>
<div class="menuBotoes">
<s:iterator value="segmentosVerticalSaude" var="segmento">
<table cellpadding="0" cellspacing="0" class="tableBotaoMenu">
<tr class="trCimaBotaoMenuSelect">
<td align="center" class="imagemBotaoMenuSelect"><img src="<s:url value="/includes/imagens/global/botoes/grafico.png" />" /></td>
<td align="left" class="descricaoBotaoMenuSelect"><s:property value="descricao" escapeHtml="false" /></td>
</tr>
<tr class="trBaixoBotaoMenuSelect">
<td align="center" class="imagemBotaoMenuSelect"><s:property value="projeto.sigla" escapeHtml="false" /></td>
<td align="left" class="descricaoBotaoMenuSelect">
<select>
<option value="">-- Selecione um relatório --</option>
<s:iterator value="links" var="link">
<option value="<s:url namespace="%{#segmento.namespace}" action="%{#link.action}" />"><s:property value="textoLink" escapeHtml="false" /></option>
</s:iterator>
</select>
</td>
</tr>
</table>
</s:iterator>
</div>
public static List<Segmento> getSegmentosVerticalSaude() {
return BaseAction.getSegmentosPorVertical(Vertical.SAUDE);
}
public static List<Segmento> getSegmentosVerticalAuto() {
return BaseAction.getSegmentosPorVertical(Vertical.AUTOMOVEIS);
}
public static List<Segmento> getSegmentosVerticalCapitalizacao() {
return BaseAction.getSegmentosPorVertical(Vertical.CAPITALIZACAO);
}
public static List<Segmento> getSegmentosVerticalDental() {
return BaseAction.getSegmentosPorVertical(Vertical.DENTAL);
}
public static List<Segmento> getSegmentosVerticalPrevidencia() {
return BaseAction.getSegmentosPorVertical(Vertical.PREVIDENCIA);
}
public static List<Segmento> getSegmentosVerticalResidencial() {
return BaseAction.getSegmentosPorVertical(Vertical.RESIDENCIAL);
}
private static List<Segmento> getSegmentosPorVertical(final Vertical vertical) {
final List<Segmento> segmentosSaude = new ArrayList<Segmento>();
for (final Segmento segmento : Segmento.values()) {
if (vertical == segmento.getVertical()) {
segmentosSaude.add(segmento);
}
}
return segmentosSaude;
}
public static List<Segmento> getSegmentos() {
return BaseAction.getSegmentosPorVertical(Vertical.findVerticalByIdentificador(BaseAction
.getParameter("vertical")));
}
private static List<Segmento> getSegmentosPorVertical(final Vertical vertical) {
final List<Segmento> segmentos = new ArrayList<Segmento>();
for (final Segmento segmento : Segmento.values()) {
if (vertical == segmento.getVertical()) {
segmentos.add(segmento);
}
}
return segmentos;
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<head>
<script type="text/javascript" src="<s:url value="/includes/js/botoes/links.js" />"></script>
</head>
<div class="menuBotoes">
<div align="right">
<s:a namespace="/filtros/verticais" action="iniciarFiltroVerticais">
<img src="<s:url value="/includes/imagens/global/botao-voltar.png" />" width="59" height="26" alt="Voltar para a tela de seleção de relatórios por verticais." />
</s:a>
</div>
<s:iterator value="segmentos" var="segmento">
<table cellpadding="0" cellspacing="0" class="tableBotaoMenu">
<tr class="trCimaBotaoMenuSelect">
<td align="center" class="imagemBotaoMenuSelect"><img src="<s:url value="/includes/imagens/global/botoes/grafico.png" />" /></td>
<td align="left" class="descricaoBotaoMenuSelect"><s:property value="descricao" escapeHtml="false" /></td>
</tr>
<tr class="trBaixoBotaoMenuSelect">
<td align="center" class="imagemBotaoMenuSelect"><s:property value="projeto.sigla" escapeHtml="false" /></td>
<td align="left" class="descricaoBotaoMenuSelect">
<select>
<option value="">-- Selecione um relatório --</option>
<s:iterator value="links" var="link">
<option value="<s:url namespace="%{#segmento.namespace}" action="%{#link.action}" />"><s:property value="textoLink" escapeHtml="false" /></option>
</s:iterator>
</select>
</td>
</tr>
</table>
</s:iterator>
<div align="right" style="clear: both;">
<s:a namespace="/filtros/verticais" action="iniciarFiltroVerticais">
<img src="<s:url value="/includes/imagens/global/botao-voltar.png" />" width="59" height="26" alt="Voltar para a tela de seleção de relatórios por verticais." />
</s:a>
</div>
</div>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<head></head>
<div class="menuBotoes">
<s:iterator value="verticais" var="vertical">
<s:a namespace="/filtros" action="iniciarFiltroSegmentos?vertical=%{#vertical.identificador}" cssClass="%{#vertical.classeCSSLink}">
<span class="<s:property value="classeCSSSpan" />"><s:property value="textoLink" escapeHtml="false" /></span>
</s:a>
</s:iterator>
</div>
public enum Vertical {
SAUDE(1, "botoesMenu", "verticalSaude", "Saúde"),
AUTOMOVEIS(2, "botoesMenu disabled", "verticalAutomoveis", "Automóveis"),
CAPITALIZACAO(3, "botoesMenu disabled", "verticalCapitalizacao", "Capitalização"),
DENTAL(4, "botoesMenu disabled", "verticalDental", "Dental"),
RESIDENCIAL(5, "botoesMenu disabled", "verticalResidencial", "Residencial"),
PREVIDENCIA(6, "botoesMenu disabled", "verticalPrevidencia", "Previdência");
private int identificador;
private String classeCSSLink;
private String classeCSSSpan;
private String textoLink;
private Vertical(final int identificadorParam, final String classeCSSLinkParam, final String classeCSSSpanParam,
final String textoLinkParam) {
this.identificador = identificadorParam;
this.classeCSSLink = classeCSSLinkParam;
this.classeCSSSpan = classeCSSSpanParam;
this.textoLink = textoLinkParam;
}
public int getIdentificador() {
return this.identificador;
}
public String getClasseCSSLink() {
return this.classeCSSLink;
}
public String getClasseCSSSpan() {
return this.classeCSSSpan;
}
public String getTextoLink() {
return this.textoLink;
}
public static Vertical findVerticalByIdentificador(final int identificadorParam) {
for (final Vertical vertical : Vertical.values()) {
if (vertical.getIdentificador() == identificadorParam) {
return vertical;
}
}
return null;
}
public static Vertical findVerticalByIdentificador(final String identificadorParam) {
if (StringUtils.isBlank(identificadorParam)) {
return null;
}
return Vertical.findVerticalByIdentificador(Integer.parseInt(identificadorParam));
}
}