Struts 2: How to add dynamic inputs to jsp from an activity?
I am trying to create a selection that for each option of that selection I will have specific inputs.
For example, a selection has A,B,C
parameters; if i select A
, one text box and one file upload box appears; if I select B instead, two text boxes appear.
This is a JEE application and I am working with Struts2, struts2-json-plugin and struts2-jquery-plugin.
I tried to follow the documentation but it doesn't work.
Act:
@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;
}
}
The first problem is that I cannot get my list into select, when I use a simple Struts select <s:select>
, it works, I see my list, but when I use <sj:select>
, I cannot, I guess it is because of JSON. but I can't figure out what it is.
No one has answered this question yet
See similar questions:
or similar: