1

I have the following:

select name="nroPartido" style="color:#F5FFFA; background-color: #CC9900; font-weight: bold;">
<%
        //se crean las listas
        java.util.ArrayList<Partido> lista = Pronosticos.getInstance().getMiLista();
                int nro = 0;
        for (Partido p : lista) {              
                out.println("<option value=\"" + nro + "\">" + p.getLocal() +"-" +p.getVisitante() + "</option>");
                nro++;
        }
%>
</select>

So when I click the button the value of nro will be the value of the var nroPartido that is in the pronosticoAction class:

package acciones;


import com.opensymphony.xwork2.ActionSupport;

public class pronosticoAction extends ActionSupport {

    private int nroPartido;


    public String execute() {
        System.out.println(nroPartido);
        return SUCCESS;
    }


    public int getNroPartido() {
        return nroPartido;
    }


    public void setNroPartido(int nroPartido) {
        this.nroPartido = nroPartido;
    }






}

Then what i want to do is print that number in a JSP page. So i do the following:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Detalles partido</title>
</head>
<body>

    <h1>Chosen number</h1>

<h4>
    You select number: <s:property value="nroPartido" />
</h4>
</body>
</html>

The problem is that it only shows this:

enter image description here

If someone could help me will be very useful Thanks!

Wojciech Wirzbicki
  • 3,887
  • 6
  • 36
  • 59
Joseph
  • 45
  • 6

1 Answers1

0

The following line is wrong, both syntactically and conceptually:

<s:property value="nroPartido"></<s:property>

there is an extra < , and the <s:property/> tag should self-closed, like a void element in XHTML:

<s:property value="nroPartido" />

That said, you should consider building your Select without using scritplets at all, by either iterating the options with <s:iterator>, or by using <s:select/> that is often the right way. You can find an example on how to do it in this answer.

EDIT

You also forgot to include the taglib directive for Struts2 tags:

<%@ taglib prefix="s" uri="/struts-tags" %>

To use the Struts 2 tags on the view page, you must include a tag library directive. Typically, the taglib directive is <%@ taglib prefix="s" uri="/struts-tags" %>. So the prefix for all the Struts 2 tags will be "s". If you want to actually read the Struts 2 tag TLD file, you'll find it in the META-INF folder of the Struts 2 core jar.

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • Hi @AndreaLigios thanks for answering. I made that change and it doesn't appear the number. I edit my code with your correction. – Joseph Feb 16 '15 at 15:27
  • 1
    Yes you are right! I use it in other JSP but in this I didn't put it. Thanks for your help – Joseph Feb 16 '15 at 15:39