Author: fdesbois Date: 2012-03-26 19:02:58 +0200 (Mon, 26 Mar 2012) New Revision: 3209 Url: http://chorem.org/repositories/revision/pollen/3209 Log: - Resolve issue with VoteToChoice save - Add message support in session (not working yet) Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-03-26 17:02:51 UTC (rev 3208) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/PollenSession.java 2012-03-26 17:02:58 UTC (rev 3209) @@ -48,6 +48,10 @@ /** Key to store the {@link PollenSession} instance in the session's map. */ protected static final String SESSION_PARAMETER = "pollenSession"; + public static final String SESSION_TOKEN_MESSAGES = "messages"; + + public static final String SESSION_TOKEN_ERRORS = "errors"; + public static PollenSession get(ServletRequest servletRequest) { HttpSession httpSession = ((HttpServletRequest) servletRequest).getSession(true); PollenSession pollenSession = (PollenSession) httpSession.getAttribute(SESSION_PARAMETER); Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-26 17:02:51 UTC (rev 3208) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/PollenActionSupport.java 2012-03-26 17:02:58 UTC (rev 3209) @@ -44,6 +44,8 @@ import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.List; @@ -229,4 +231,48 @@ String result = getDateTimeFormat().format(date); return result; } + + @Override + public void addActionMessage(String message) { + List<String> messages = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES); + if (messages == null) { + messages = Lists.newArrayList(message); + getPollenSession().putDynamicData(PollenSession.SESSION_TOKEN_MESSAGES, messages); + } else { + messages.add(message); + } + } + + @Override + public void addActionError(String message) { + List<String> messages = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_ERRORS); + if (messages == null) { + messages = Lists.newArrayList(message); + getPollenSession().putDynamicData(PollenSession.SESSION_TOKEN_ERRORS, messages); + } else { + messages.add(message); + } + } + + @Override + public Collection<String> getActionErrors() { + List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_ERRORS); + if (result != null) { + getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_ERRORS); + } else { + result = Collections.emptyList(); + } + return result; + } + + @Override + public Collection<String> getActionMessages() { + List<String> result = getPollenSession().getDynamicData(PollenSession.SESSION_TOKEN_MESSAGES); + if (result != null) { + getPollenSession().removeDynamicData(PollenSession.SESSION_TOKEN_MESSAGES); + } else { + result = Collections.emptyList(); + } + return result; + } } Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-26 17:02:51 UTC (rev 3208) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/AbstractVoteAction.java 2012-03-26 17:02:58 UTC (rev 3209) @@ -152,12 +152,9 @@ return vote; } - public VoteToChoice getVoteToChoice(int index) { - return getVote().getChoiceVoteToChoice().get(index); - } - public boolean getVoteValueAsBoolean(int index) { - Integer value = getVoteToChoice(index).getVoteValue(); + VoteToChoice voteToChoice = getVote().getChoiceVoteToChoice().get(index); + Integer value = voteToChoice.getVoteValue(); return value == 1; } @@ -488,7 +485,7 @@ protected void loadVotes() { // TODO no pagination for the moment, need to retrieve the correct page depends on current pollAccount - votes = getPoll().getVote(); + votes = getPoll().getVote(); // Current vote vote = getVoteService().getVote(getPoll(), getVotes(), getPollAccount()); Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-26 17:02:51 UTC (rev 3208) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/java/org/chorem/pollen/ui/actions/poll/VoteForPoll.java 2012-03-26 17:02:58 UTC (rev 3209) @@ -24,7 +24,9 @@ package org.chorem.pollen.ui.actions.poll; import com.opensymphony.xwork2.Preparable; +import org.chorem.pollen.bean.PollUri; import org.chorem.pollen.business.persistence.Vote; +import org.chorem.pollen.business.persistence.VoteToChoice; /** * Votes to a poll. @@ -37,7 +39,8 @@ private static final long serialVersionUID = 1L; public void setVoteValueAsBoolean(int index, boolean value) { - getVoteToChoice(index).setVoteValue(value ? 1 : 0); + VoteToChoice voteToChoice = getVote().getChoiceVoteToChoice().get(index); + voteToChoice.setVoteValue(value ? 1 : 0); } @Override @@ -58,6 +61,20 @@ getPollService().addVoteToPoll(getPoll(), voteCreated); } + // Display updateUrl if user is not logged + if (!isUserLoggued()) { + + String pollId = getPoll().getPollId(); + String accountId = getPollAccount().getAccountId(); + PollUri pollUri = PollUri.newPollUri(pollId, accountId); + + String updateUrl = getVoteService().getUpdateVoteUrl(pollUri); + addActionMessage(_("pollen.information.vote.createdWithUpdateUrl", updateUrl)); + + } else{ + + addActionMessage(_("pollen.information.vote.created")); + } return SUCCESS; } Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-26 17:02:51 UTC (rev 3208) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_en_GB.properties 2012-03-26 17:02:58 UTC (rev 3209) @@ -193,6 +193,8 @@ pollen.information.user.created=User %s created. pollen.information.user.deleted=User %s deleted. pollen.information.user.updated=User %s updated. +pollen.information.vote.created= +pollen.information.vote.createdWithUpdateUrl= pollen.information.your.are.loggued=You are logged. pollen.label.contact.administrator=Send an email to an administrator pollen.label.pollEditPage=The link below leads to the page to modify your poll. Save it to be able to modify your poll later if you need it or to close it \: Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-26 17:02:51 UTC (rev 3208) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/i18n/pollen-ui-struts2_fr_FR.properties 2012-03-26 17:02:58 UTC (rev 3209) @@ -200,6 +200,8 @@ pollen.information.user.created=L'utilisateur %s a été créé. pollen.information.user.deleted=L'utilisateur %s a été supprimé. pollen.information.user.updated=L'utilisateur %s a été mis à jour. +pollen.information.vote.created=Vote enregistré +pollen.information.vote.createdWithUpdateUrl=Vote enregistré, vous pourrez le modifier à l'adresse suivante <a href\="%1$s">%1$s</a> pollen.information.your.are.loggued=Vous êtes connecté. pollen.label.contact.administrator=Contacter un administrateur pollen.label.pollEditPage=Le lien ci-dessous mène à la page de modification du sondage. Enregistrez-le pour pouvoir modifier votre sondage au besoin ou le clore \: Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-26 17:02:51 UTC (rev 3208) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/resources/struts.xml 2012-03-26 17:02:58 UTC (rev 3209) @@ -39,7 +39,7 @@ <constant name="struts.action.extension" value=",,"/> <constant name="struts.locale" value="fr_FR"/> <constant name="struts.i18n.reload" value="false"/> - <constant name="struts.configuration.xml.reload" value="false"/> + <constant name="struts.configuration.xml.reload" value="true"/> <constant name="struts.ui.theme" value="css_xhtml"/> <constant name="struts.multipart.maxSize" value="209715200"/> <constant name="struts.enable.SlashesInActionNames" value="true"/> @@ -71,9 +71,9 @@ <interceptor-stack name="pollenBasicStack"> <interceptor-ref name="i18n"/> <interceptor-ref name="basicStack"/> - <interceptor-ref name="store"> +<!-- <interceptor-ref name="store"> <param name="operationMode">STORE</param> - </interceptor-ref> + </interceptor-ref>--> </interceptor-stack> <!-- params stack with params--> @@ -107,9 +107,9 @@ <interceptor-ref name="workflow"> <param name="excludeMethods">input,back,cancel,browse</param> </interceptor-ref> - <interceptor-ref name="store"> +<!-- <interceptor-ref name="store"> <param name="operationMode">STORE</param> - </interceptor-ref> + </interceptor-ref>--> </interceptor-stack> </interceptors> @@ -137,9 +137,9 @@ <result>/WEB-INF/jsp/home.jsp</result> <interceptor-ref name="i18n"/> <interceptor-ref name="basicStack"/> - <interceptor-ref name="store"> +<!-- <interceptor-ref name="store"> <param name="operationMode">RETRIEVE</param> - </interceptor-ref> + </interceptor-ref>--> </action> <!-- change lang--> @@ -153,9 +153,9 @@ <interceptor-ref name="paramRemover"> <param name="paramNames">request_locale</param> </interceptor-ref> - <interceptor-ref name="store"> +<!-- <interceptor-ref name="store"> <param name="operationMode">STORE</param> - </interceptor-ref> + </interceptor-ref>--> </action> </package> Modified: branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp =================================================================== --- branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-26 17:02:51 UTC (rev 3208) +++ branches/pollen-1.2.6-struts2/pollen-ui-struts2/src/main/webapp/WEB-INF/jsp/poll/vote.jsp 2012-03-26 17:02:58 UTC (rev 3209) @@ -270,24 +270,24 @@ <s:if test="!isChoiceHidden(#choice)"> <th> <s:if test="normalVoteCounting"> - <s:checkbox name="voteValueAsBoolean[%{#status.index}]" - value="%{voteValueAsBoolean[#status.index]}" theme="simple"/> + <s:checkbox name="vote.choiceVoteToChoice[%{#status.index}].voteValue" + value="%{vote.choiceVoteToChoice[#status.index].voteValue}" theme="simple"/> </s:if> <s:if test="percentageVoteCounting"> - <s:textfield name="voteToChoice[%{#status.index}].voteValue" - value="%{voteToChoice[#status.index].voteValue}" + <s:textfield name="vote.choiceVoteToChoice[%{#status.index}].voteValue" + value="%{vote.choiceVoteToChoice[#status.index].voteValue}" required="true" size="3" theme="simple"/> <%--t:validate="required, min=0, max=100"/>%--%> </s:if> <s:if test="condorcetVoteCounting"> - <s:textfield name="voteToChoice[%{#status.index}].voteValue" - value="%{voteToChoice[#status.index].voteValue}" + <s:textfield name="vote.choiceVoteToChoice[%{#status.index}].voteValue" + value="%{vote.choiceVoteToChoice[#status.index].voteValue}" id="condorcetInput" size="3" theme="simple"/> <%--t:nulls="zero" t:validate="min=0, max=99"/>--%> </s:if> <s:if test="numberVoteCounting"> - <s:textfield name="voteToChoice[%{#status.index}].voteValue" - value="%{voteToChoice[#status.index].voteValue}" + <s:textfield name="vote.choiceVoteToChoice[%{#status.index}].voteValue" + value="%{vote.choiceVoteToChoice[#status.index].voteValue}" size="3" theme="simple"/> </s:if> </th>