Struts 2:如何在动作中添加jsp中的动态输入?

时间:2015-06-09 12:16:55

标签: jquery struts2 struts2-jquery struts2-json-plugin struts2-jquery-plugin

我正在尝试创建一个选择,对于该选择的每个选项,我将指定输入。

例如,select有A,B,C个选项;如果我选择A,则会出现一个文本字段和一个文件上传字段;如果我选择B代替,则会出现两个文本字段。

这是一个JEE应用程序,我正在使用Struts2,struts2-json-plugin和struts2-jquery-plugin。

我试图按照文档进行操作,但它不起作用。

动作:

    @Actions({
        @Action(
           value="jsonsample",
           results={ @Result(name="success",type="json")}
        )
    })
    public String execute() throws Exception{
        List<SignatureKeyType> signatureKeyTypes = signatureKeyTypeService.findAll();
        signatureKeyTypesSubscriber = new ArrayList<SignatureKeyType>();
        signatureKeyTypesServer = new ArrayList<SignatureKeyType>();
        for (int i=0; i<signatureKeyTypes.size(); i++) {
            if(signatureKeyTypes.get(i).getFlag()==1){
                signatureKeyTypesSubscriber.add(signatureKeyTypes.get(i));
            }else{
                signatureKeyTypesServer.add(signatureKeyTypes.get(i));
            }
        }

        listParamSubscriber = new ArrayList<SignatureKeyTypeParameter>();
        for (SignatureKeyType signatureKeyTypeSub : signatureKeyTypesSubscriber) {
            listParamSubscriber = signatureKeyTypeSub.getSignatureKeyTypeParameter();
        }

        listParamServer = new ArrayList<SignatureKeyTypeParameter>();
        for (SignatureKeyType signatureKeyTypeServer : signatureKeyTypesServer) {
            listParamServer = signatureKeyTypeServer.getSignatureKeyTypeParameter();
        }

        return SUCCESS;
    }

    public String getJSON() throws Exception{
        return execute();
    }

JSP:

<s:url var="remoteurl" action="jsonsample"/>
<sj:select href="%{remoteurl}" 
             id="echo" 
           name="echo"
           list="signatureKeyTypesSubscriber"
        listKey="idSignatureKeyType"
      listValue="label" 
    emptyOption="true" 
      headerKey="-1"
    headerValue="Please Select" 
/>

SignatureKeyType:

@Entity
@Table(name="signaturekeytype")
public class SignatureKeyType extends Tokenizable{

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long idSignatureKeyType;

    @Column(name = "label", nullable = false)
    private String label;

    @Column(name = "flag")
    private int flag;

     @OneToMany(mappedBy = "signatureKeyType")
   private List<ServerSignature> serverSignatures;

   @OneToMany(mappedBy = "signatureKeyType")
   private List<SubscriberSignature> subscriberSignatures;

    @OneToMany(fetch = FetchType.EAGER, mappedBy = "signatureKeyType", cascade = CascadeType.ALL)
   private List<SignatureKeyTypeParameter> signatureKeyTypeParameter;

   public Long getIdSignatureKeyType() {
      return idSignatureKeyType;
   }

   /** @param newIdSignatureKeyType */
   public void setIdSignatureKeyType(Long newIdSignatureKeyType) {
      idSignatureKeyType = newIdSignatureKeyType;
   }

   public String getLabel() {
      return label;
   }

   /** @param newLabel */
   public void setLabel(String newLabel) {
      label = newLabel;
   }



public List<ServerSignature> getServerSignatures() {
    return serverSignatures;
}

public void setServerSignatures(List<ServerSignature> serverSignatures) {
    this.serverSignatures = serverSignatures;
}

public List<SubscriberSignature> getSubscriberSignatures() {
    return subscriberSignatures;
}

public void setSubscriberSignatures(List<SubscriberSignature> subscriberSignatures) {
    this.subscriberSignatures = subscriberSignatures;
}

public int getFlag() {
    return flag;
}

public void setFlag(int flag) {
    this.flag = flag;
}

public List<SignatureKeyTypeParameter> getSignatureKeyTypeParameter() {
    return signatureKeyTypeParameter;
}

public void setSignatureKeyTypeParameter(List<SignatureKeyTypeParameter> signatureKeyTypeParameter) {
    this.signatureKeyTypeParameter = signatureKeyTypeParameter;
}


}

第一个问题是我无法在select中获取我的列表,当我使用简单的Struts select <s:select>时它可以工作,我可以看到我的列表但是当我使用<sj:select>时我不能,我认为这是因为JSON,但我无法弄清楚究竟是什么。

0 个答案:

没有答案