簡體   English   中英

Struts2-如何使用 <s:a> 之前不知道我將要使用的操作?

[英]Struts2 - How can I use <s:a> without previously knowing the action that I'll use?

我必須在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.htmlhttp://struts.apache.org/release/2.3 .x / docs / a.htmlhttp://struts.apache.org/release/2.3.x/docs/url.html,但與構建了PrimeFaces或RichFaces之類的框架相比,示例部分實際上還很差自己的展示櫃。

使用下面的代碼

<s:a namespace="%{#link.nameSpace}" action="%{#link.action}">

使用%{}使struts2評估{}內表達式的內容,然后將結果分配給該屬性。

有關更多詳細信息,請參考http://struts.apache.org/release/2.0.x/docs/tag-syntax.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM