質問

I want to send a specific parameter for every result.

struts.xml:

<action name="modifierPara" method="modifierPara"
        class="ma.ensao.evalmetrics.view.ParametrageAction">
  <interceptor-ref name="loginStack" />
  <result name="ssCara">
    <param name="etat">ssCara</param>
    /WEB-INF/admin/projets/parametrer/modifierSubCara.jsp
  </result>

  <result name="metric">
    <param name="etat">metric</param>
    /WEB-INF/admin/projets/parametrer/modifierMetric.jsp
  </result>
</action>

Depends on the value of etat , I will execute linkController.modifier with different arguments.

ma.ensao.evalmetrics.view.ParametrageAction:

public class ParametrageAction extends ActionSupport {

    private static final long serialVersionUID = 9149826260758390091L;
    private Parametrage para;
    private Long id;
        private ParaManager linkController;
        private String etat;
        private String etatSuivant;


    public ParametrageAction() {
        linkController = new ParaManager();
    }

    public String getSpecificPara() {
        try {
            this.setPara(linkController.getSpecificPara(getId()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }
    public String modifierPara() {

        try {
            if (etat.equals("cara")){
                linkController.modifier(para,"cara");
                etatSuivant= "ssCara";
            }else if(etat.equals("ssCara")){
                linkController.modifier(para,"ssCara");
                etatSuivant="metric";
            }else if(etat.equals("metric")){
                linkController.modifier(para,"metric");
                etatSuivant="SUCCESS";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("coucouuuuu from parm action");
        return etatSuivant;
    }
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public ParaManager getLinkController() {
        return linkController;
    }

    public void setLinkController(ParaManager linkController) {
        this.linkController = linkController;
    }

    public static long getSerialversionuid() {
        return serialVersionUID;
    }

    public Parametrage getPara() {
        return para;
    }

    public void setPara(Parametrage para) {
        this.para = para;
    }

    public String getEtat() {
        return etat;
    }

    public void setEtat(String etat) {
        this.etat = etat;
    }
}
役に立ちましたか?

解決

To send a parameter with result you need to add parameter location to the result tag that will hold the value of the resource to be located by the dispatcher. Then add your own params. For example

<result name="ssCara">
  <param name="etat">ssCara</param>
  <param name="location">/WEB-INF/admin/projets/parametrer/modifierSubCara.jsp</param>    
</result>

他のヒント

(It turns out the OP wanted to send data to an Action, not to a JSP. Leaving this answer because it's a better solution for sending data to a JSP than using XML configuration, which is unnecessary and counter to how S2 applications are normally written.)

If the default result type is "dispatcher" (the normal default) then no "sending" is required.

Expose an action property named "etat" and reference it in the JSP.

Action class

public class AnAction extends ActionSupport { // Extending is optional
    private String etat;
    public String getEtat() { return etat; }
    public String modifierPara() {
        etat = whatever();
        return appropriateResult();
    }
    // etc.
}

JSP

${etat} Or...
<s:property value="%{etat}" /> Etc.

Appropriate naming eliminates the bulk of result configuration:

<result>/WEB-INF/admin/projets/parametrer/modifier_${etat}.jsp</result>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top