Author: tchemit Date: 2012-06-18 09:54:19 +0200 (Mon, 18 Jun 2012) New Revision: 3502 Url: http://chorem.org/repositories/revision/pollen/3502 Log: refs #618: Stay on same url for poll form Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java Modified: trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java =================================================================== --- trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-17 13:23:21 UTC (rev 3501) +++ trunk/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractPollForm.java 2012-06-18 07:54:19 UTC (rev 3502) @@ -37,6 +37,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.struts2.interceptor.ParameterAware; +import org.apache.struts2.interceptor.ServletRequestAware; import org.chorem.pollen.bean.PollDateChoice; import org.chorem.pollen.bean.PollImageChoice; import org.chorem.pollen.bean.PollUri; @@ -65,6 +66,7 @@ import org.chorem.pollen.ui.converters.DateConverter; import org.nuiton.util.StringUtil; +import javax.servlet.http.HttpServletRequest; import java.io.File; import java.io.IOException; import java.util.Collection; @@ -82,7 +84,7 @@ * @author fdesbois <desbois@codelutin.com> * $Id$ */ -public abstract class AbstractPollForm extends PollenActionSupport implements Preparable, ParameterAware, FileUploadAware { +public abstract class AbstractPollForm extends PollenActionSupport implements Preparable, ParameterAware, FileUploadAware, ServletRequestAware { private static final long serialVersionUID = 1L; @@ -188,6 +190,13 @@ private PollUri pollUri; + /** + * The incoming request (some stuff are store in it from security filters). + * + * @since 1.4 + */ + private transient HttpServletRequest request; + public abstract boolean isClone(); protected abstract Poll savePoll(Poll poll) throws PollNotFoundException; @@ -195,82 +204,86 @@ public abstract boolean isEdit(); @Override + public void setServletRequest(HttpServletRequest request) { + this.request = request; + } + + @Override public void prepare() throws Exception { prepareFormPage(); - if (parameters.containsKey("poll.title")) { + if (isGetMethod()) { - if (log.isInfoEnabled()) { - log.info("Starts prepare form..."); - } + // do not prepare when coming as GET + return; + } - // we are after a submit + // we are after a submit - String pollUid = getNonEmptyParameterValue("poll.pollId"); - String userId = getNonEmptyParameterValue("userId"); - if (StringUtils.isBlank(userId)) { + String pollUid = getNonEmptyParameterValue("poll.pollId"); + String userId = getNonEmptyParameterValue("userId"); + if (StringUtils.isBlank(userId)) { - // try to take the one from current user - UserAccount userAccount = getPollenUserAccount(); - if (userAccount != null) { - userId = userAccount.getTopiaId(); - } + // try to take the one from current user + UserAccount userAccount = getPollenUserAccount(); + if (userAccount != null) { + userId = userAccount.getTopiaId(); } - UserAccount userAccount = null; - if (StringUtils.isNotBlank(userId)) { - // load use account to use - userAccount = getPollService().getEntityById( - UserAccount.class, userId); - } + } + UserAccount userAccount = null; + if (StringUtils.isNotBlank(userId)) { + // load use account to use + userAccount = getPollService().getEntityById( + UserAccount.class, userId); + } - // get a copy (or a fresh new poll) - poll = getPollService().getPollEditable(pollUid, userAccount, false); + // get a copy (or a fresh new poll) + poll = getPollService().getPollEditable(pollUid, userAccount, false); - // If vote is started, prepare choices and votingLists is useless - // because they can't be updated. - if (!isVoteStarted()) { + // If vote is started, prepare choices and votingLists is useless + // because they can't be updated. + if (!isVoteStarted()) { - // Retrieve choiceType from parameters, the poll object will be updated after prepare - String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType"); - ChoiceType pollChoiceType = ChoiceType.valueOf(choiceTypeParam); - poll.setChoiceType(pollChoiceType); + // Retrieve choiceType from parameters, the poll object will be updated after prepare + String choiceTypeParam = getNonEmptyParameterValue("poll.choiceType"); + ChoiceType pollChoiceType = ChoiceType.valueOf(choiceTypeParam); + poll.setChoiceType(pollChoiceType); - // build poll choices + // build poll choices - switch (pollChoiceType) { + switch (pollChoiceType) { - case TEXT: - choices = buildTextChoices(); - break; - case DATE: - choices = buildDateChoices(); - break; - case IMAGE: - choices = buildImageChoices(); - break; - } - PollType pollType; - String pollTypeParam = getNonEmptyParameterValue("poll.pollType"); - pollType = PollType.valueOf(pollTypeParam); - switch (pollType) { + case TEXT: + choices = buildTextChoices(); + break; + case DATE: + choices = buildDateChoices(); + break; + case IMAGE: + choices = buildImageChoices(); + break; + } + PollType pollType; + String pollTypeParam = getNonEmptyParameterValue("poll.pollType"); + pollType = PollType.valueOf(pollTypeParam); + switch (pollType) { - case FREE: + case FREE: - // empty voting list - votingLists = Maps.newTreeMap(); - break; - case RESTRICTED: + // empty voting list + votingLists = Maps.newTreeMap(); + break; + case RESTRICTED: - // restricted voting list - votingLists = buildVotingLists(pollType); - break; - case GROUP: + // restricted voting list + votingLists = buildVotingLists(pollType); + break; + case GROUP: - // group voting lists - votingLists = buildVotingLists(pollType); - break; - } + // group voting lists + votingLists = buildVotingLists(pollType); + break; } } } @@ -278,8 +291,6 @@ @Override public String input() throws Exception { - prepareFormPage(); - UserAccount userAccount = getPollenUserAccount(); String pollUid = pollUri == null ? null : pollUri.getPollId(); PollService service = getPollService(); @@ -413,6 +424,12 @@ @InputConfig(methodName = "inputAfterValidationError") public String execute() throws Exception { + if (isGetMethod()) { + + // input method + return input(); + } + // Save choices and votingLists only if vote is not started if (!isVoteStarted()) { //TODO-tchemit comment me 2012-06-04 A merge would be nicer but more complex to code @@ -489,9 +506,18 @@ return SUCCESS; } + protected boolean isGetMethod() { + return "GET".equalsIgnoreCase(request.getMethod()); + } + @Override public void validate() { + if (isGetMethod()) { + + // input method + return; + } validateInformations(); validateOptions();
participants (1)
-
tchemit@users.chorem.org