1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.formengine.modules.sample.web;
35
36 import fr.paris.lutece.plugins.formengine.modules.sample.business.jaxb.ObjectFactory;
37 import fr.paris.lutece.plugins.formengine.modules.sample.business.jaxb.Sample;
38 import fr.paris.lutece.plugins.formengine.modules.sample.service.output.SampleIdGenerator;
39 import fr.paris.lutece.plugins.formengine.service.output.IdGenerator;
40 import fr.paris.lutece.plugins.formengine.web.SharedConstants;
41 import fr.paris.lutece.plugins.formengine.web.SubForm;
42 import fr.paris.lutece.portal.service.template.AppTemplateService;
43 import fr.paris.lutece.portal.service.util.AppPropertiesService;
44 import fr.paris.lutece.util.html.HtmlTemplate;
45
46 import org.apache.commons.lang.StringUtils;
47
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpSession;
50
51
52
53
54
55 public class MiddleSubForm extends SubForm
56 {
57 private static String _strXslFileForm = ".xsl.file.form.middle";
58 private static final String SUMMARY_MESSAGE = "Renseigner votre nom et votre chiffre";
59
60
61
62
63 @Override
64 public String doAction( String strActionName, HttpServletRequest request )
65 {
66 String strNextSubForm = StringUtils.EMPTY;
67
68 if ( strActionName == null )
69 {
70 strNextSubForm = this.getName( );
71 }
72 else if ( strActionName.equals( Constants.ACTION_NAME_NEXT ) )
73 {
74 this.fillFields( request );
75
76 if ( this.validateFields( request ) )
77 {
78 doSetData( request );
79 strNextSubForm = this.getNextSubForm( ).getName( );
80
81 HttpSession session = request.getSession( true );
82 session.setAttribute( Constants.SESSION_ATTRIBUTE_SAVE_BIS, Constants.SESSION_ATTRIBUTE_SAVE_VALUE );
83 }
84 else
85 {
86 strNextSubForm = this.getName( );
87 }
88 }
89 else if ( strActionName.equals( Constants.ACTION_NAME_PREVIOUS ) )
90 {
91 strNextSubForm = this.getPreviousSubForm( ).getName( );
92 }
93 else if ( strActionName.equals( Constants.ACTION_NAME_ENREGISTREMENT ) )
94 {
95 this.fillFields( request );
96 doSetData( request );
97
98 HttpSession session = request.getSession( true );
99 session.setAttribute( Constants.SESSION_ATTRIBUTE_SAVE, Constants.SESSION_ATTRIBUTE_SAVE_VALUE );
100 strNextSubForm = this.getName( );
101 }
102
103 this.getParentForm( ).setIsAccessToSubFormAllowed( request, strNextSubForm, true );
104
105 return strNextSubForm;
106 }
107
108
109
110
111 @Override
112 protected String displaySummary( HttpServletRequest request )
113 {
114 StringBuilder sbResult = new StringBuilder( SUMMARY_MESSAGE );
115 HttpSession session = request.getSession( true );
116
117 if ( StringUtils.isBlank( (String) session.getAttribute( SharedConstants.SESSION_ATTRIBUTE_WARNING_ERROR_WS ) ) )
118 {
119 if ( StringUtils.isNotBlank( (String) session.getAttribute( Constants.SESSION_ATTRIBUTE_SAVE ) ) )
120 {
121 HtmlTemplate template = AppTemplateService.getTemplate( Constants.TEMPLATE_MESSAGE_SAVE,
122 request.getLocale( ) );
123 sbResult.append( template.getHtml( ) );
124 session.removeAttribute( Constants.SESSION_ATTRIBUTE_SAVE );
125 }
126 }
127
128 return sbResult.toString( );
129 }
130
131
132
133
134 @Override
135 protected String getXslFormElementsFileName( )
136 {
137 return AppPropertiesService.getProperty( Constants.SHARED_PROPERTY_PREFIX + _strXslFileForm );
138 }
139
140
141
142
143
144 private void doSetData( HttpServletRequest request )
145 {
146 Sample sample = (Sample) getParentForm( ).getFormDocument( request );
147
148 if ( sample == null )
149 {
150
151 ObjectFactory factory = new ObjectFactory( );
152 sample = factory.createSample( );
153 }
154
155 IdGenerator idGenerator = new SampleIdGenerator( );
156
157 sample.setIdentifiant( idGenerator.getNewId( this.getParentForm( ) ) );
158
159 if ( StringUtils.isNotBlank( request.getParameter( Constants.PARAMETER_FORM_NAME ) ) )
160 {
161 sample.setNom( request.getParameter( Constants.PARAMETER_FORM_NAME ) );
162 }
163
164 if ( StringUtils.isNotBlank( request.getParameter( Constants.PARAMETER_FORM_NUMERO ) ) )
165 {
166 sample.setNumero( Integer.valueOf( request.getParameter( Constants.PARAMETER_FORM_NUMERO ) ).intValue( ) );
167 }
168
169 this.getParentForm( ).setFormDocument( request, sample );
170 }
171 }