如何在没有javascript / jquery的情况下使用Struts2单击链接时,如何添加表单字段

时间:2015-08-04 13:12:13

标签: javascript jsp struts2

如果仅使用Struts2,没有javascript / jquery的jsp点击链接,我怎么能添加表单字段。 我希望当我点击同一页面中的addCompte链接jsp时,添加更多关于compte的字段以及已存在的客户端字段。

我想留在同一个jsp页面,当用户点击链接更多关于帐户显示的字段时。问题是用户点击我应该使用哪个表达式的链接

这是我的client.jsp代码:

<body>
<h1>Show de Clients</h1>

<s:form action="updateClient"> 
<s:textfield name="nom" label="Nom"/>
<s:textfield name="prenom" label="Prenom"/>
<s:textfield name="age" label="Age"/>
<s:textfield name="codeClient" label="CodeClient"/>

<s:url var="addCompteURL" action="addCompteToClient">
    <s:param name="codeClient" value="%{codeClient}"></s:param>
    <s:hidden name="moreCompte" value="yes" label="hide"></s:hidden>
</s:url> <s:a href="%{addCompteURL}" onclick="">addCompte</s:a>

<s:if test="%{moreCompte!=null}">
    <s:textfield name="numeroCompte" label="NumeroCompte"/>
    <s:textfield name="solde" label="Solde"/>
    <s:textfield name="dateCreation" label="DateCreation"/>
            <s:submit  action="addCompteToClient"
                value="addCompteToClient"       align="center">
        </s:submit>
        </s:if>

        <s:else>
        <s:submit action="updateClient" value="update client"
                        align="center">
        </s:submit>
        </s:else>

</s:form> 
</body>

这是我的动作代码ClientAction.java:

public class ClientAction extends ActionSupport{
private int codeClient;
private String nom;
private String prenom;
private int age;
private String adresse;
private String numeroCompte;
private double solde;
private Date dateCreation;
private Client client;
List<Client> clientList;
ServiceMetier serviceMetier= new ServiceMetierImpl();


public int getCodeClient() {
    return codeClient;
}
public void setCodeClient(int codeClient) {
    this.codeClient = codeClient;
}

public String getNom() {
    return nom;
}
public void setNom(String nom) {
    this.nom = nom;
}
public String getPrenom() {
    return prenom;
}
public void setPrenom(String prenom) {
    this.prenom = prenom;
}
public int getAge() {
    return age;
}
public void setAge(int age) {
    this.age = age;
}
public String getAdresse() {
    return adresse;
}
public void setAdresse(String adresse) {
    this.adresse = adresse;
}

public String getNumeroCompte() {
    return numeroCompte;
}
public void setNumeroCompte(String numeroCompte) {
    this.numeroCompte = numeroCompte;
}
public double getSolde() {
    return solde;
}
public void setSolde(double solde) {
    this.solde = solde;
}
public Date getDateCreation() {
    return dateCreation;
}
public void setDateCreation(Date dateCreation) {
    this.dateCreation = dateCreation;
}

public Client getClient() {
    return client;
}
public void setClient(Client client) {
    this.client = client;
}
public List<Client> getClientList() {
    System.out.println("methode getClienList");
    return clientList;
}
public void setClientList(List<Client> clientList) {
    System.out.println("methode setClientList");
    this.clientList = clientList;
}
public String init(){
//      clientList = serviceMetier.getAllClient();
    System.out.println("methode init ");
    return SUCCESS;
}
public String afficher(){
    clientList=serviceMetier.getAllClient();
//      client=serviceMetier.getClient(9);
    System.out.println("methode afficher "+clientList);
    return SUCCESS;
}
public String ajouter(){
    System.out.println("methode afficher "+clientList);
    BanqueFactory banque=new BanqueFactory();
    Compte compte=banque.buildCompte();
    compte.setNumeroCompte(numeroCompte);
    compte.setSolde(solde);
    compte.setDateCreation(dateCreation);
    Client client=banque.buildClient();
    client.setCodeClient(codeClient);
    client.setNom(nom);
    client.setPrenom(prenom);
    client.setAge(age);
    client.setAdresse(adresse);
    client.addCompte(compte);
    serviceMetier.createClient(client);
    clientList=serviceMetier.getAllClient();

    return SUCCESS;
}
public String addCompte(){
    System.out.println("methode addCompte");
    /*
    BanqueFactory banque=new BanqueFactory();
    Compte compte=banque.buildCompte();
    compte.setNumeroCompte(numeroCompte);
    compte.setSolde(solde);
    compte.setDateCreation(dateCreation);
    Client client=banque.buildClient();
    client.setCodeClient(codeClient);
    client.setNom(nom);
    client.setPrenom(prenom);
    client.setAge(age);
    client.setAdresse(adresse);
    client.addCompte(compte);
    serviceMetier.updateClient(client);
//      if(codeClient>0){
//      serviceMetier.updateClient(codeClient);
//      codeClient=0;
//      }

 */
    client=serviceMetier.getClient(codeClient);

    return SUCCESS;
}
public String update(){
    client=serviceMetier.getClient(codeClient);
    if(nom!=null){
        client.setNom(nom);
    }
    if(prenom!=null){
        client.setPrenom(prenom);
    }
    if(age!=0){
        client.setAge(age);
    }
    if(adresse!=null){
        client.setAdresse(adresse);
    }
    serviceMetier.updateClient(client);
    return SUCCESS;
}
public String delete(){
    System.out.println("methode delete");
//      if(codeClient>0){
    serviceMetier.deleteClient(codeClient);
//      codeClient=0;
//      }
    clientList=serviceMetier.getAllClient();
    return SUCCESS;
}


}

这是我的struts.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="ApplicationResources" />
<package name="default" extends="struts-default" namespace="/">
    <action name= "login" class="org.presentation.action.Account">
    <result name="reussite" type="redirectAction">listClient</result>
    <result name="echec">logging.jsp</result>
    </action>
    <action name="clientInit" class="org.presentation.action.ClientAction"
        method="init">
        <result name="success">index.jsp</result>
    </action>
    <action name= "addClient" class="org.presentation.action.ClientAction"
    method="ajouter">
    <result name="success">clientShow.jsp</result>
    </action>
    <action name="listClient" class="org.presentation.action.ClientAction"
        method="afficher">
        <result name="success">clientShow.jsp</result>
    </action>
    <action name="updateClient" class="org.presentation.action.ClientAction"
        method="update">
        <result name="success">client.jsp</result>
    </action>
    <action name="addCompteToClient"   class="org.presentation.action.ClientAction"
        method="addCompte">
        <result name="success">client.jsp</result>
    </action>
    <action name="deleteClient" class="org.presentation.action.ClientAction"
        method="delete">
        <result name="success">clientShow.jsp</result>
    </action>
</package>  
</struts>

使用Struts2,没有javascript / jquery的jsp可以实现吗?如果不是如何在Struts2中添加jquery代码?

0 个答案:

没有答案