3

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

例如 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" 
/>

签名密钥类型:

@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;
}


}

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

4

0 回答 0