Question

I have a <s:select list="links" headerKey="" headerValue="-- Select a link --" name="reportLinks" id="reportLinks" listValue="linkText" listKey="linkValue" /> and I would like the options to be generated with its value attribute equals to the link that is mapped in an enum.

The enum:

public enum LinksRelatorios {

    1("One", "/reports", "inicializeReportOne", "PROJECT"),
    2("Two", "/reports", "inicializeReportTwo", "PROJECT"),
    3("Three", "/reports", "inicializeReportThree", "PROJECT"),
    4("four", "/reports", "inicializeReportFour", "PROJECT"),
    5("Five", "/reports", "inicializeReportFive", "PROJECT"),
    6("Six", "/reports", "inicializeReportSix", "PROJECT"),
    7("Seven", "/reports", "inicializeReportSeven", "PROJECT");

    private String linkText;
    private String nameSpace;
    private String action;
    private String project;

    private LinksRelatorios(final String textoLinkParam, final String nameSpaceParam, final String actionParam, final String projectParam) {
        this.linkText = linkTextParam;
        this.nameSpace = nameSpaceParam;
        this.action = actionParam;
        this.project = projectParam;
    }

    public String getLinkText() {
        return this.linkText;
    }

    public String getNameSpace() {
        return this.nameSpace;
    }

    public String getAction() {
        return this.action;
    }

    public String getProjeto() {
        return this.project;
    }

What I want to do is that every option has the value of a <s:url namespace="namespace" action="action" /> for example.

The <s:url> tag generates a URL with the project context and the action extension for me and that's why I need it, so as not to hard coded this informations in the enum.

My action is correct and I can get the enum without a problem, I tested using <s:iterator>.

The action:

@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 static LinksRelatorios[] getLinks() {
        return InicioAction.links;
    }
}

I've searched over google and SO, but couldn't find any results.

I've read the online official docs in 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 and http://struts.apache.org/release/2.3.x/docs/url.html but the examples sections is actually pretty poor comparing to frameworks such as PrimeFaces or RichFaces that have built theirs own showcases.

Was it helpful?

Solution

I don't think what I was trying to do is possible using just struts tags.

So I just did what's below:

<select id="linksInternacaoDomiciliar" name="linksInternacaoDomiciliar">
    <s:iterator value="links" var="link">
        <option value="<s:url namespace="%{#link.nameSpace}" action="%{#link.action}" />"><s:property value="textoLink"/></option>
    </s:iterator>
</select>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top