How can I store dropdown selections of a JSP page in its session bean?
There is a bunch of dropdown boxes on the pages, a few text boxes and a
submit button that is supposed to submit to self. The page instantiates a
stateful session scoped bean. This part works, as the dropdown boxes
options are being populated from the bean's method calls.
Now I need to store the selected items in the bean and read them upon form
submission (the idea is that users will be gradually configuring the
selections to arrive at desired configuration). And this is not working.
The code is as follows:
In the JSP page:
<jsp:useBean id="Config" scope="session"
class="configurator.ejbConfigurator"/>
<select id="size" name="size">
<c:forEach var="SizeItem" items="${Config.sizeList}">
<option value="${SizeItem}" ${SizeItem == Config.size ? "selected"
: ""}><c:out value="${SizeItem}" /></option>
</c:forEach>
</select>
<input id="btnsub" name="btnsub" type="submit" value="Preview">
In the bean:
@Named
@Stateful
@SessionScoped
public class ejbConfigurator implements Serializable,ejbConfiguratorLocal {
private SizeEnum size;
@Override
public ArrayList<String> getSizeList() {
ArrayList<String> result = new ArrayList<>();
result.add("40x60");
result.add("60x80");
return result;
}
@Override
public String getSize() {
switch (size){
case _40X60:
return "40x60";
case _60X80:
return "60x80";
default:
return "";
}
}
@Override
public boolean setSize(final String size) {
if (size.equals("40x60")) {
this.size = SizeEnum._40X60;
return true;
}
if (size.equals("60x80")) {
this.size = SizeEnum._60X80;
return true;
}
return false;
}
}
always generates the first option '40x60' item with 'selected' as should
be the case if the bean was just created, but not after selecting '60x80'
and submitting.
What do I need to do to save the selections in the bean upon submit?
Thank you all!
No comments:
Post a Comment