DAe pessoal tudo bom
tenho um form que tem a action=salvar
ja dentro desse form tenho outra ação que é deletar porem é um link e não submete o form como um todo
como posso submeter todo o formulario independente da ação…
DAe pessoal tudo bom
tenho um form que tem a action=salvar
ja dentro desse form tenho outra ação que é deletar porem é um link e não submete o form como um todo
como posso submeter todo o formulario independente da ação…
Poderiam ser dois submits. Apontando para method diferentes.
Não sei se é legal fazer isso mais vc pode usar um input button com um evento onclick para uma function js assim:
function Deletar ()
{
document.form.action = “Processa.jsp”;
document.form.submit();
}
[quote=rdgms]Não sei se é legal fazer isso mais vc pode usar um input button com um evento onclick para uma function js assim:
function Deletar ()
{
document.form.action = “Processa.jsp”;
document.form.submit();
}
[/quote]
eu já implementei algo semelhante a isso em um projeto, vc pode ter n ações em uma única form, funcionou perfeitamente. Se vc Sorriso se interessar posta ai que falo detalhe a detalhe como fazer. :idea:
// Funcao que busca tranportes
function mostraTransportes(value){
init();
PartTransport.getTransport(value, reply);
}
// Retorno assincrono da funcao que retonar lista de transportes
var reply = function(data){
DWRUtil.removeAllOptions("transports");
// Coloca opcao 'selecione' no combo
var option = document.createElement('option');
var text = document.createTextNode('<bean:message key="application.msg.select" />');
option.value = "0";
option.appendChild(text);
// Combo
var combo = document.getElementById('transports');
combo.appendChild(option);
DWRUtil.addOptions("transports", data, "value", "label");
}
</script>
<html:form action="participantData/registerTransport.do">
<html:hidden name="ptForm" property="id" styleId="idParticipant"/>
<table width="97%" cellpadding="0" align="center">
<tbody>
<tr>
<td height="32" class="titulo"><bean:write name="ptForm" property="person"/></td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<jsp:include flush="true" page="/common/abas.jsp" />
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0"
class="Borda-Tabela">
<tbody>
<tr>
<td width="50%" bgcolor="#dadada" align="right" class="textoTabela">
<bean:message key="participantTransport.add.activity" bundle="participantTransport" />
</td>
<td width="50%" bgcolor="#f2f2f2">
<table width="524">
<tbody>
<tr>
<td width="125" height="20" class="textoMenu">
<bean:message key="participantTransport.type" bundle="participantTransport" />
</td>
<td width="387" class="textoMenu">
<bean:message key="participantTransport.transport" bundle="participantTransport" />
</td>
</tr>
<tr>
<td width="125" height="53">
<table width="179">
<tbody>
<tr>
<td width="55" class="texto">
<bean:message key="participantTransport.go" bundle="participantTransport" />
</td>
<td width="60" class="texto">
<html:radio property="type" value="0" onclick="mostraTransportes(this.value)"/>
</td>
</tr>
<tr>
<td class="texto">
<bean:message key="participantTransport.back" bundle="participantTransport" />
</td>
<td class="texto">
<html:radio property="type" value="1" onclick="mostraTransportes(this.value)"/>
</td>
</tr>
</tbody>
</table>
</td>
<td width="387">
<html:select property="transportForm" styleClass="textField"
styleId="transports" style="width: 300px;">
</html:select>
</td>
</tr>
<tr>
<td colspan="5">
<html:submit property="action" styleClass="btn"><bean:message key="application.add"/> </html:submit>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td bgcolor="#dadada" align="right" class="textoTabela">
<bean:message key="application.data.atualizacao"/>
</td>
<td bgcolor="#f2f2f2" class="textoTabela">
DAta Atualização
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td height="10">
<table width="100%" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td class="texto">
<strong>
<bean:message key="participantTransport.list.transport.event" bundle="participantTransport" />
</strong>
</td>
</tr>
<tr>
<td height="10">
<table style="border: thin none ;" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr class="texto">
<td width="20%" class="textoMenu" align="center">
<bean:message key="participantTransport.transport" bundle="participantTransport" />
</td>
<td width="20%" class="textoMenu" align="center">
<bean:message key="participantTransport.boarding" bundle="participantTransport" />
</td>
<td width="20%" class="textoMenu" align="center">
<bean:message key="participantTransport.type" bundle="participantTransport" />
</td>
<td width="20%" class="textoMenu" align="center">
<bean:message key="participantTransport.to" bundle="participantTransport" />
</td>
<td width="20%" class="textoMenu" align="center">
<bean:message key="participantTransport.from" bundle="participantTransport" />
</td>
<td width="20%" class="textoMenu" align="center">
<bean:message key="application.delete.object" />
</td>
</tr>
</tboby>
</table>
<table style="border: thin none ;" width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<logic:iterate name="ptForm" property="listTransport" id="transp" >
<tbody>
<html:hidden name="transp" property="id" styleId="idTransport"/>
<tr class="texto">
<td width="18%" class="textoTabela" align="center">
<bean:write name="transp" property="transporter"/>
<bean:write name="transp" property="transportDocument"/>
</td>
<td width="19%" class="textoTabela" align="center">
<bean:write name="transp" property="hour" format="dd/MM/yyyy HH:mm"/>
</td>
<td width="18%" class="textoTabela" align="center">
<logic:equal name="transp" property="type" value="SAIDA" >
<bean:message key="participantTransport.go" bundle="participantTransport" />
</logic:equal>
<logic:notEqual name="transp" property="type" value="SAIDA" >
<bean:message key="participantTransport.back" bundle="participantTransport" />
</logic:notEqual>
</td>
<td width="19%" class="textoTabela" align="center">
<bean:write name="transp" property="to"/>
</td>
<td width="18%" class="textoTabela" align="center">
<bean:write name="transp" property="from"/>
</td>
<td width="6%" align="center">
<html:hidden name="transp" property="id" styleId="idTransport"/>
<html:link action="participantData/deleteTransport.do" paramId="delete"
paramName="transp" paramProperty="id"
style="text-decoration: none;"
onclick="submitForm()">
<img src="../images/trash.gif" border="0">
</html:link>
</td>
</tr>
</tboby>
</logic:iterate>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table cellspacing="2" cellpadding="2" align="right">
<tbody>
<tr>
<td><input type="hidden" value="insert" name="insert" />
<table>
<tbody>
<tr>
<td><input type="button" name="action"
onclick="window.location = '../person/loadForm.do'"
value="<bean:message key="application.button.register.person" />"
class="btn" style="width: 122px;" />
</td>
<td><input type="button" value="<bean:message key="application.export" />"
style="width: 122px;" class="btn" name="button" />
</td>
</tr>
<tr>
<td colspan="2"><input class="btn" type="button"
value="<bean:message key="application.close" />"
onclick="window.location = '../participantManagement/loadForm.do'"
style="width: 250px;" /></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</html:form>
Bom note que tem 2 actions sendo que no deletar preciso do campo hiden que guarda pra mim o id do participante
porem não consigo submeter a pagina inteira pra recuperar este id só me vem o id do transporte…
O que proponho é que tenha em sua jsp uma função JS como a seguinte
function setCommand(cmdTxt){
document.formCompras.compras_action.value = cmdTxt;
document.formCompras.submit();
}
essa função altera a ação que foi chamada passando um nome de método para ser executado.
todas as ações seram enviada por esse cara
ele deve estar mapeado no seu struts-config.xml
<action path="/cad_compra" type="br.uniminas.pgi.action.ComprasAction"
name="ComprasForm" scope="session" validate="true" input="/Compras.jsp"
parameter="compras_action">
<forward name="compras_action" path="/Compras.jsp"></forward>
</action>
dessa forma todos as ações que forem enviadas para ele seram tratadas dentro da classe ComprasAction
assim como no seu código terá tb uma hidden que aponta para o cara selecionado.
ao chamar a ação vc deve passar qual método deve se executado da seguinte maneira
<select name="SELECTED_PECA" size="1" onchange="setCommand('carrega_peca_edit')">
<option value="-1" >PEÇAS</option>
<c:forEach var="pecas" items="${PECAS_LIST}">
<option value="${pecas.id}">${pecas.nomePeca}</option>
</c:forEach>
</select>
assim chamo o método carrega_peca_edit que vc pode ver logo abaixo
nota: a classe a ser extendida e DispatchAction
[code]
public class ComprasAction extends DispatchAction {
public ActionForward carrega_peca_edit(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
…
}[/code]
assim vc pode ter varias ações em uma mesma form
se não ficou claro posta ai
abração !!!
Brother bem complecadinhu isso ai né. fiz de um jeito passei o parametro na url não sei se é o melhor mas por favor me de sua opinião
Como o código que vc está passando não é um senha creio não ter problema algum, somente se o usuário puder alterar esse valor de “bobeira” ai sim isso se tornará um problema, caso contrário não. A solução que propus é meio chatinha mas uma vez implementado um método fica bem prático de fazer e proporciona um número indeterminado de ações em um única form.
Se deu certo ai blz bora para outras hehehe abração e bom trabalho!