I am using Stripes framework and I have a problem I just cannot solve.
I have a page in the folder "creatures" called "add.jsp" which adds a creature (some entity in my model) into the DB. I use this form in that page:
add.jsp
<s:layout-render name="/layout.jsp" title="Creatures">
<s:layout-component name="menu">
<ul class="navcontainer" id="main-navigation">
<li><s:link href="/regions.jsp">Region</s:link></li>
<li class="current"><s:link href="/creatures/show.jsp">Creatures</s:link></li>
<li><s:link href="/types.jsp">Creature types</s:link></li>
<li><s:link href="/weapons.jsp">Weapons</s:link></li>
</ul>
</s:layout-component>
<s:layout-component name="main_content">
<div class="main-content">
<div class="content">
<img src="../images/banner.png" alt="Banner" id="banner"/>
<h1>Create a new creature</h1>
<s:link href="/creatures/show.jsp">Back</s:link>
<s:form beanclass="cz.muni.fi.pa165.creatures.web.CreaturesActionBean">
<%@include file="/forms/createCreature.jsp"%>
<s:submit name="create" value="Create"/>
</s:form>
</div>
</div>
</s:layout-component>
so that is pretty it, i also include form itself and I have a submit button with name="create" which should map on the method "create" in the action bean right?
Ok so I have that class which looks like this:
@UrlBinding("/creatures/{$event}")
public class CreaturesActionBean implements ActionBean {
final static Logger logger =
Logger.getLogger(CreaturesActionBean.class.getName());
private ActionBeanContext context;
@SpringBean
protected CreatureService creatureService;
@ValidateNestedProperties(value = {
@Validate(on = {"create"}, field = "name", required = true, maxlength=256),
@Validate(converter=LongTypeConverter.class , on = {"create"},
field = "weight", required = false, minvalue=1, maxvalue=1000),
@Validate(converter=LongTypeConverter.class , on = {"create"},
field = "height", required = false, minvalue=1, maxvalue=1000)
})
private CreatureDTO creatureDTO;
public void setCreatureDTO(CreatureDTO creatureDTO) {
this.creatureDTO = creatureDTO;
}
public CreatureDTO getCreatureDTO() {
return this.creatureDTO;
}
public Resolution create() {
logger.log(Level.INFO, "add() creature={}", creatureDTO);
creatureService.create(creatureDTO);
return new RedirectResolution(this.getClass(), "all");
}
@DefaultHandler
public Resolution all() {
logger.log(Level.INFO, "getting all creatures");
return new ForwardResolution("/creatures/show.jsp");
}
So it means that when there is a submit with name "create", in that action bean the create method is executed and the creatureDTO is saved and so on.
BUT
That "create" method in the action bean is not executed at all and i am redirected to the page called
http://localhost:8080/pa165/creatures/
Application context is pa165 and after redirecting to that page after I click submit button, I see the listing of all files in that directory (add.jsp and so in, the all files in the creature dir) and that method is not executed at all.
I want to be redirected to the page creatures/show.jsp which I handle by line
return new RedirectResolution(this.getClass(), "all");
which means that I will be redirected throught all method there
Why it does not work?
Do you output validation results anywhere? (<stripes:errors> tag) The 'create' method not being executed at all could suggest form submissions do not pass validation. Maybe a field name not matching or something like that.
Your problem is that the URL binding should not be the same as the folder structure. Just change the binding for something like @UrlBinding("/mycreatures/{$event}"). I had the same problem and this worked like a charm. See this link for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With