Bonjour,
je travaille avec l'outil androMDA (il permet de générer une application à partir d'un modèle).
j'ai une interface qui contient:
- un element text (ou je peux inserer un string : il s'appelle nomPhase).
- un bouton de nom : creer
je veux que quand je clique sur le bouton "creer", un enregistrement soit ajouté à la table phase de ma BDD.
toutes les autres parties sont prêtes : hibernate, struts, ...
OU puis-je insérer du code pour programmer ce bouton !!!!
merci d'avance .
Après avoir générer mon app, j'ai trouvé les fichiers suivants:
** creation-de-phase.jsp
*********************************************************<%@ include file="/taglib-imports.jspf" %>
<breadcrumbs:resize size="5"/>
<breadcrumbs:add value="creation.de.phase.title"/>
<tiles:insert definition="main.layout">
<tiles:put name="title" type="string">
<bean:message key="creation.de.phase.title"/>
</tiles:put>
<tiles:put name="style" type="string">
<link rel="stylesheet" type="text/css" media="screen" href="<html:rewrite page="/org/andromda/timesheet/web/creationprojet/phase/creation-de-phase.css"/>"></link>
</tiles:put>
<%@ include file="/org/andromda/timesheet/web/creationprojet/phase/creation-de-phase-javascript.jspf" %>
<tiles:put name="body" type="string">
<div>
<tiles:insert definition="breadcrumbs.tile" flush="false">
<tiles:put name="current.page.title" type="string" value="creation.de.phase.title"/>
</tiles:insert>
<h1><bean:message key="creation.de.phase.title"/></h1>
</div>
<%@ include file="/org/andromda/timesheet/web/creationprojet/phase/creation-de-phase-creer.jspf" %>
<div id="pageHelpSection">
<blockquote>
<bean:message key="required.fields.asterisk"/>
<a href="" id="pageHelp" style="display:inline;" onclick="openWindow('<html:rewrite action="/org/andromda/timesheet/web/creationprojet/phase/CreationDePhaseHelp"/>','onlinehelp',true,false,760,540); return false;">
<bean:message key="online.help.href"/>
</a>
<html:img page="/layout/help.gif" style="display:inline;"/>
</blockquote>
</div>
</tiles:put>
</tiles:insert>
** creation-de-phase-creer.jspf
*****************************************************
*********************************************************<%@ include file="/taglib-imports.jspf" %>
<div id="creer" class="action">
<h3><bean:message key="creer"/></h3>
<div class="trigger">
<html:form styleId="creationPhaseCreationDePhaseCreerForm" action="/CreationPhase/CreationDePhaseCreer" method="post" onsubmit="return validateCreationDePhaseCreerForm(this);">
<table>
<tbody>
<tr class="nomPhase">
<td class="label"><nobr><bean:message key="nom.phase"/> <div class="important">*</div></nobr></td>
<td class="field">
<c:set var="value" value="${form.nomPhase}"/>
<input type="text" name="nomPhase" value="${value}" onmouseover="hints.show('nom.phase.title')" onmouseout="hints.hide()" id="creerNomPhase"/>
</td>
</tr>
<tr>
<td>
<html:submit onmouseover="hints.show('Creer une phase')" onmouseout="hints.hide()" styleId="form_submit">
<bean:message key="creer"/>
</html:submit>
</td>
</tr>
</tbody>
</table>
</html:form>
</div>
</div>
<br class="clr"/>
** creation-de-phase-javascript.jspf
***************************************************
<tiles:put name="javascript" type="string">
<script type="text/javascript" language="Javascript1.1" src="<html:rewrite action="/formValidation"/>"></script>
<html:javascript formName="creationPhaseCreationDePhaseCreerForm" method="validateCreationDePhaseCreerForm" dynamicJavascript="true" staticJavascript="false" htmlComment="true" cdata="false"/>
<script type="text/javascript" language="Javascript1.1" src="<html:rewrite page="/layout/hints.js"/>"></script>
<script type="text/javascript" language="Javascript1.1">
//<!--
var HINTS_ITEMS = {
'nom.phase.title':'<formatting:escape language="javascript"><bean:message key="nom.phase.title"/></formatting:escape>',
'Creer':'<formatting:escape language="javascript"><bean:message key="creer.title"/></formatting:escape>',
'Creer_no':'<formatting:escape language="javascript"><bean:message key="creer.title.notallowed"/></formatting:escape>',
'Creer_reset':'<formatting:escape language="javascript"><bean:message key="creer.title.reset"/></formatting:escape>',
'Creer_noreset':'<formatting:escape language="javascript"><bean:message key="creer.title.reset.not.allowed"/></formatting:escape>',
'calendar.popup':'<formatting:escape language="javascript"><bean:message key="calendar.popup"/></formatting:escape>'
};
var hints = new THints (HINTS_CFG, HINTS_ITEMS);
//-->
</script>
</tiles:put>
****************************************************
** CreationPhaseFormImpl.java
*********************************************
// license-header java merge-point
package org.andromda.timesheet.web.creationprojet.phase;
public class CreationDePhaseCreerFormImpl
extends org.apache.struts.validator.ValidatorForm
implements java.io.Serializable
{
/**
* The serial version UID of this class. Needed for serialization.
*/
private static final long serialVersionUID = -16049176751L;
private java.lang.String nomPhase;
private java.lang.Object[] nomPhaseValueList;
private java.lang.Object[] nomPhaseLabelList;
public CreationDePhaseCreerFormImpl()
{
}
/**
* Resets the given <code>nomPhase</code>.
*/
public void resetNomPhase()
{
this.nomPhase = null;
}
public void setNomPhase(java.lang.String nomPhase)
{
this.nomPhase = nomPhase;
}
/**
*
*/
public java.lang.String getNomPhase()
{
return this.nomPhase;
}
public java.lang.Object[] getNomPhaseBackingList()
{
java.lang.Object[] values = this.nomPhaseValueList;
java.lang.Object[] labels = this.nomPhaseLabelList;
if (values == null || values.length == 0)
{
return values;
}
if (labels == null || labels.length == 0)
{
labels = values;
}
final int length = java.lang.Math.min(labels.length, values.length);
java.lang.Object[] backingList = new java.lang.Object[length];
for (int i=0; i<length; i++)
{
backingList[i] = new LabelValue(labels[i], values[i]);
}
return backingList;
}
public java.lang.Object[] getNomPhaseValueList()
{
return this.nomPhaseValueList;
}
public void setNomPhaseValueList(java.lang.Object[] nomPhaseValueList)
{
this.nomPhaseValueList = nomPhaseValueList;
}
public java.lang.Object[] getNomPhaseLabelList()
{
return this.nomPhaseLabelList;
}
public void setNomPhaseLabelList(java.lang.Object[] nomPhaseLabelList)
{
this.nomPhaseLabelList = nomPhaseLabelList;
}
public void setNomPhaseBackingList(java.util.Collection items, java.lang.String valueProperty, java.lang.String labelProperty)
{
if (valueProperty == null || labelProperty == null)
{
throw new IllegalArgumentException("CreationDePhaseCreerFormImpl.setNomPhaseBackingList requires non-null property arguments");
}
this.nomPhaseValueList = null;
this.nomPhaseLabelList = null;
if (items != null)
{
this.nomPhaseValueList = new java.lang.Object[items.size()];
this.nomPhaseLabelList = new java.lang.Object[items.size()];
try
{
int i = 0;
for (java.util.Iterator iterator = items.iterator(); iterator.hasNext(); i++)
{
final java.lang.Object item = iterator.next();
this.nomPhaseValueList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, valueProperty);
this.nomPhaseLabelList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, labelProperty);
}
}
catch (Exception ex)
{
throw new java.lang.RuntimeException("CreationDePhaseCreerFormImpl.setNomPhaseBackingList encountered an exception", ex);
}
}
}
/**
* @see org.apache.struts.validator.ValidatorForm#reset(org.apache.struts.action.ActionMapping,javax.servlet.http.HttpServletRequest)
*/
public void reset(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
{
}
public java.lang.String toString()
{
org.apache.commons.lang.builder.ToStringBuilder builder =
new org.apache.commons.lang.builder.ToStringBuilder(this);
builder.append("nomPhase", this.nomPhase);
return builder.toString();
}
/**
* Allows you to clean all values from this form. Objects will be set to <code>null</code>, numeric values will be
* set to zero and boolean values will be set to <code>false</code>. Backinglists for selectable fields will
* also be set to <code>null</code>.
*/
public void clean()
{
this.nomPhase = null;
this.nomPhaseValueList = null;
this.nomPhaseLabelList = null;
}
/**
* Override to provide population of current form with request parameters when validation fails.
*
* @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
*/
public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
{
final org.apache.struts.action.ActionErrors errors = super.validate(mapping, request);
if (errors != null && !errors.isEmpty())
{
// we populate the current form with only the request parameters
Object currentForm = request.getSession().getAttribute("form");
// if we can't get the 'form' from the session, try from the request
if (currentForm == null)
{
currentForm = request.getAttribute("form");
}
if (currentForm != null)
{
final java.util.Map parameters = new java.util.HashMap();
for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements()
{
final String name = String.valueOf(names.nextElement());
final String[] values = request.getParameterValues(name);
if (values.length == 1)
{
parameters.put(name, values[0]);
}
else
{
parameters.put(name, values);
}
}
try
{
org.apache.commons.beanutils.BeanUtils.populate(currentForm, parameters);
}
catch (java.lang.Exception populateException)
{
// ignore if we have an exception here (we just don't populate).
}
}
}
return errors;
}
public final static class LabelValue
{
private java.lang.Object label = null;
private java.lang.Object value = null;
public LabelValue(Object label, java.lang.Object value)
{
this.label = label;
this.value = value;
}
public java.lang.Object getLabel()
{
return this.label;
}
public java.lang.Object getValue()
{
return this.value;
}
public java.lang.String toString()
{
return label + "=" + value;
}
}
}
********************************************************
** CreationDePhaseCreerFormImpl.java
***************************************************
merci beaucoup !!// license-header java merge-point
package org.andromda.timesheet.web.creationprojet.phase;
public class CreationDePhaseCreerFormImpl
extends org.apache.struts.validator.ValidatorForm
implements java.io.Serializable
{
/**
* The serial version UID of this class. Needed for serialization.
*/
private static final long serialVersionUID = -16049176751L;
private java.lang.String nomPhase;
private java.lang.Object[] nomPhaseValueList;
private java.lang.Object[] nomPhaseLabelList;
public CreationDePhaseCreerFormImpl()
{
}
/**
* Resets the given <code>nomPhase</code>.
*/
public void resetNomPhase()
{
this.nomPhase = null;
}
public void setNomPhase(java.lang.String nomPhase)
{
this.nomPhase = nomPhase;
}
/**
*
*/
public java.lang.String getNomPhase()
{
return this.nomPhase;
}
public java.lang.Object[] getNomPhaseBackingList()
{
java.lang.Object[] values = this.nomPhaseValueList;
java.lang.Object[] labels = this.nomPhaseLabelList;
if (values == null || values.length == 0)
{
return values;
}
if (labels == null || labels.length == 0)
{
labels = values;
}
final int length = java.lang.Math.min(labels.length, values.length);
java.lang.Object[] backingList = new java.lang.Object[length];
for (int i=0; i<length; i++)
{
backingList[i] = new LabelValue(labels[i], values[i]);
}
return backingList;
}
public java.lang.Object[] getNomPhaseValueList()
{
return this.nomPhaseValueList;
}
public void setNomPhaseValueList(java.lang.Object[] nomPhaseValueList)
{
this.nomPhaseValueList = nomPhaseValueList;
}
public java.lang.Object[] getNomPhaseLabelList()
{
return this.nomPhaseLabelList;
}
public void setNomPhaseLabelList(java.lang.Object[] nomPhaseLabelList)
{
this.nomPhaseLabelList = nomPhaseLabelList;
}
public void setNomPhaseBackingList(java.util.Collection items, java.lang.String valueProperty, java.lang.String labelProperty)
{
if (valueProperty == null || labelProperty == null)
{
throw new IllegalArgumentException("CreationDePhaseCreerFormImpl.setNomPhaseBackingList requires non-null property arguments");
}
this.nomPhaseValueList = null;
this.nomPhaseLabelList = null;
if (items != null)
{
this.nomPhaseValueList = new java.lang.Object[items.size()];
this.nomPhaseLabelList = new java.lang.Object[items.size()];
try
{
int i = 0;
for (java.util.Iterator iterator = items.iterator(); iterator.hasNext(); i++)
{
final java.lang.Object item = iterator.next();
this.nomPhaseValueList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, valueProperty);
this.nomPhaseLabelList[i] = org.apache.commons.beanutils.PropertyUtils.getProperty(item, labelProperty);
}
}
catch (Exception ex)
{
throw new java.lang.RuntimeException("CreationDePhaseCreerFormImpl.setNomPhaseBackingList encountered an exception", ex);
}
}
}
/**
* @see org.apache.struts.validator.ValidatorForm#reset(org.apache.struts.action.ActionMapping,javax.servlet.http.HttpServletRequest)
*/
public void reset(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
{
}
public java.lang.String toString()
{
org.apache.commons.lang.builder.ToStringBuilder builder =
new org.apache.commons.lang.builder.ToStringBuilder(this);
builder.append("nomPhase", this.nomPhase);
return builder.toString();
}
/**
* Allows you to clean all values from this form. Objects will be set to <code>null</code>, numeric values will be
* set to zero and boolean values will be set to <code>false</code>. Backinglists for selectable fields will
* also be set to <code>null</code>.
*/
public void clean()
{
this.nomPhase = null;
this.nomPhaseValueList = null;
this.nomPhaseLabelList = null;
}
/**
* Override to provide population of current form with request parameters when validation fails.
*
* @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
*/
public org.apache.struts.action.ActionErrors validate(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest request)
{
final org.apache.struts.action.ActionErrors errors = super.validate(mapping, request);
if (errors != null && !errors.isEmpty())
{
// we populate the current form with only the request parameters
Object currentForm = request.getSession().getAttribute("form");
// if we can't get the 'form' from the session, try from the request
if (currentForm == null)
{
currentForm = request.getAttribute("form");
}
if (currentForm != null)
{
final java.util.Map parameters = new java.util.HashMap();
for (final java.util.Enumeration names = request.getParameterNames(); names.hasMoreElements()
{
final String name = String.valueOf(names.nextElement());
final String[] values = request.getParameterValues(name);
if (values.length == 1)
{
parameters.put(name, values[0]);
}
else
{
parameters.put(name, values);
}
}
try
{
org.apache.commons.beanutils.BeanUtils.populate(currentForm, parameters);
}
catch (java.lang.Exception populateException)
{
// ignore if we have an exception here (we just don't populate).
}
}
}
return errors;
}
public final static class LabelValue
{
private java.lang.Object label = null;
private java.lang.Object value = null;
public LabelValue(Object label, java.lang.Object value)
{
this.label = label;
this.value = value;
}
public java.lang.Object getLabel()
{
return this.label;
}
public java.lang.Object getValue()
{
return this.value;
}
public java.lang.String toString()
{
return label + "=" + value;
}
}
}
Partager