1
votes

I have a struts action class, which does some processing, and then forwards to a JSP page. Is it possible to disable a submit button on the results page from within the action class?

public String execute()
{
  boolean isValid = doProcessing();
  if(!isValid)
  {
    //disable btnSubmit on result page
  }

  return "SUCCESS";
}

Results page contains:

<s:submit name="btnSubmit"/>

Do I need a variable with getter and setter for the submit button to get a handle on it? If so, what would be the data type?

1

1 Answers

2
votes

Trivial, just make the variable class-level and create a getter:

private boolean isValid;

public boolean getIsValid() { 
    return isValid;  
}

public String execute() {
    isValid = doProcessing();
    return "SUCCESS";
}

then check it in JSP with <s:if>:

<s:if test="%{isValid}">
    <s:submit name="btnSubmit"/>
</s:if>