Reputation: 238
I have a search box on my index page, it is supposed to return a message if no result was found or redirect to result page if it succeeded.
Currently, if results were found it redirects to the new page, and if not will stay on the same page (index) but it does not show the message, just add the mymessage
parameter to the page address as following
www.address.com/index.jsp?mymessage=Sorry,No+results+were+found.
Index
.......
<s:property value="mymessage"/>
SearchBox
public String search(){
....
if(found)
return "success";
else
return "failed;
}
struts.xml
<package name="Search" extends="default" namespace="/Search">
<action name="*" method="{1}" class="com.myproject.myclasses.Search">
<result name="success" type="tiles">search</result>
<result name="failed" type="redirectAction">
<param name="actionName">index</param>
<param name="namespace">/</param>
<param name="mymessage">${mymessage}</param>
</result>
</action>
</package>
Upvotes: 1
Views: 236
Reputation: 1834
I think <s:property> expects a getter getMyMessage() on your action class to populate values can you try <s:property value="#request.mymessage" />
OR
Why can't you use action errors?
public String search(){
....
if(found) {
return "success";
}
else {
addActionError("No results found");
return "failed;
}
}
Now in the index.jsp add the following,
<s:if test="hasActionErrors()">
<s:iterator value="actionErrors">
<s:property escape="false"/>
</s:iterator>
</s:if>
Upvotes: 1