Reputation: 1
I am trying to migrate a project from Struts 2.3.x to 7.0.0, but I am having trouble retrieving attribute values from a bean using the <s:property> tag.
At first, I thought I was missing some configuration, but then I modified the Struts Sitemesh example text, and the problem persisted.
Struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
"https://struts.apache.org/dtds/struts-6.0.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<constant name="struts.ui.theme" value="simple"/>
<constant name="struts.action.extension" value=""/>
<constant name="struts.custom.i18n.resources" value="DefaultMessages"/>
<package name="default" extends="struts-default">
<default-action-ref name="index"/>
<action name="index">
<result>/WEB-INF/index.jsp</result>
</action>
<action name="hello" class="org.apache.struts.examples.sitemesh3.HelloAction">
<result name="success">/WEB-INF/hello1.jsp</result>
<result name="other">/WEB-INF/hello2.jsp</result>
<result name="error">/WEB-INF/error.jsp</result>
</action>
</package>
</struts>
**HelloBean **
package org.apache.struts.examples.sitemesh3;
public class HelloBean {
private int numero;
private String valor;
public HelloBean(int numero, String valor) {
this.numero = numero;
this.valor = valor;
}
@Override
public String toString() {
return "HelloBean{" + "numero=" + numero + ", valor=" + valor + '}';
}
public int getNumero() {
return numero;
}
public void setNumero(int numero) {
this.numero = numero;
}
public String getValor() {
return valor;
}
public void setValor(String valor) {
this.valor = valor;
}
}
HelloAction
package org.apache.struts.examples.sitemesh3;
import org.apache.struts2.ActionSupport;
import org.apache.struts2.interceptor.parameter.StrutsParameter;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
public class HelloAction extends ActionSupport {
public HelloBean hola = new HelloBean(1, "Hola mundo");
private static final Map<String, String> DECORATORS = Collections.unmodifiableSortedMap(new TreeMap<>() {{
put("1", "Decorator 1");
put("2", "Decorator 2");
put("3", "Exclude from decorating");
}});
private String decorator;
@Override
public String execute() throws Exception {
if ("1".equals(decorator)) {
return SUCCESS;
} else if ("2".equals(decorator)) {
return "other";
}
addActionError("Wrong decorator: " + decorator);
return ERROR;
}
public String getDecorator() {
return decorator;
}
@StrutsParameter
public void setDecorator(String decorator) {
this.decorator = decorator;
}
public Map<String, String> getDecorators() {
return DECORATORS;
}
public HelloBean getHola() {
return hola;
}
}
Hello2.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>SiteMesh example: Hello 2 with Decorator 2</title>
</head>
<body>
<h2>SiteMesh example: Hello 2 with Decorator 2</h1>
<h3>Decorators</h3>
<div>
<s:form action="hello" method="get">
<s:select name="decorator" list="decorators"/>
<s:submit value="Decorate"/>
</s:form>
</div>
<p>Selected decorator: <s:property value="decorator"/></p>
<p><s:property value="hola.valor"/></p>
<p><s:property value="hola"/> uno</p>
</body>
</html>
View
<html><head>
<title>SiteMesh example: Hello 2 with Decorator 2</title>
</head>
<body>
<h1>Decorator 2</h1>
<h2>SiteMesh example: Hello 2 with Decorator 2</h2>
<h3>Decorators</h3>
<div>
<form id="hello" name="hello" action="/sitemesh3/hello" method="get">
<select name="decorator" id="hello_decorator">
<option value="1">Decorator 1</option>
<option value="2" selected="selected">Decorator 2</option>
<option value="3">Exclude from decorating</option>
</select>
<input type="submit" value="Decorate" id="hello_0">
</form>
</div>
<p>Selected decorator: 2</p>
<p></p>
<p>HelloBean{numero=1, valor=Hola mundo} uno</p>
</body></html>
What coulb be the problem?
What coulb be the problem? What i am missing? Is there any example trying to do somthing like this?
Upvotes: 0
Views: 27
Reputation: 1
You can add
<constant name="struts.allowlist.enable" value="false"/>
to the struts.xml. Or see Allowlist Capability
Upvotes: 0