我必须在JSP中显示几个链接,HTML的结构对于每个链接都是相同的,所以我使用struts2 taglib迭代器来构建它。问题是我不知道如何构建链接本身:
我的JSP
<%@ taglib prefix="s" uri="/struts-tags"%>
<head></head>
<div class="menuBotoes">
<s:iterator value="links" var="link">
<s:a namespace="link.nameSpace" action="link.action">
<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="textoLink" /></td>
</tr>
<tr class="trBaixoBotaoMenuSelect">
<td align="center" class="imagemBotaoMenuSelect" colspan="2"><s:property value="projeto" /></td>
</tr>
</table>
</s:a>
</s:iterator>
</div>
在JSP中迭代的对象是:
public enum LinksRelatorios {
1("Caixa Visita", "/relatorios/", "iniciarRelatorioCaixaVisita", "TISS"),
2("Caixa Visita Empresa", "/relatorios/", "iniciarRelatorioCaixaVisitaEmpresa", "TISS"),
3("Produtividade Internação Domiciliar", "/relatorios/", "iniciarRelatorioInternacaoDomiciliar", "TISS"),
4("Pendências", "/relatorios/", "iniciarRelatorioPendencias", "TISS"),
5("Solicitação Inicial", "/relatorios/", "iniciarRelatorioSolicitacaoInicial", "TISS"),
6("Solicitação Prorrogação", "/relatorios/", "iniciarRelatorioSolicitacaoProrrogacao", "TISS"),
7("Tempo Resposta", "/relatorios/", "iniciarRelatorioTempoResposta", "TISS");
private String textoLink;
private String nameSpace;
private String action;
private String projeto;
private LinksRelatorios(final String textoLinkParam, final String nameSpaceParam, final String actionParam,
final String projetoParam) {
this.textoLink = textoLinkParam;
this.nameSpace = nameSpaceParam;
this.action = actionParam;
this.projeto = projetoParam;
}
public String getTextoLink() {
return this.textoLink;
}
public String getNameSpace() {
return this.nameSpace;
}
public String getAction() {
return this.action;
}
public String getProjeto() {
return this.projeto;
}
}
我的行动
@Controller
@Scope("request")
public class InicioAction extends BaseAction {
private static final long serialVersionUID = -1161409943678292285L;
private static final LinksRelatorios[] links = LinksRelatorios.values();
public String inicio() {
this.addActionMessage(this.getText("msg.sucesso.saudacao.mensagem", new String[] { (String) BaseAction
.getSession().getAttribute(Constantes.PERFIL) }));
return Action.SUCCESS;
}
public String iniciarRelatoriosPorProjeto() {
return Action.SUCCESS;
}
public String iniciarRelatoriosFiltro() {
return Action.SUCCESS;
}
public static LinksRelatorios[] getLinks() {
return InicioAction.links;
}
}
我试过用过
<s:a namespace="link.nameSpace" action="link.action">
,< s:a namespace="%{link.nameSpace}" action="%{link.action}">
,<s:a namespace="#link.nameSpace" action="#link.action">
,但似乎无效。
在有人要求之前,枚举工作正常,在我的JSP中我有<s:property value="projeto" />
和<s:property value="textoLink" />
,这些是来自枚举的属性。
我已经阅读了http://struts.apache.org/release/2.3.x/docs/using-struts-2-tags.html,http://struts.apache.org/release/2.3.x/docs/a.html和http://struts.apache.org/release/2.3.x/docs/url.html中的在线官方文档,但是与PrimeFaces或RichFaces等框架相比,示例部分实际上相当差。展示。
答案 0 :(得分:1)
使用以下代码
<s:a namespace="%{#link.nameSpace}" action="%{#link.action}">
使用%{}使struts2评估{}内表达式的内容,然后将结果赋值给属性。
有关详细信息,请参阅http://struts.apache.org/release/2.0.x/docs/tag-syntax.html。