I have created a from in JSP page name add.jsp to save data like this

<s:form action="AddDomain">
            <s:push value="idp">
                <s:textfield name="domainName" label="Domain Name" />
                <s:textfield name="url" label="Domain URL" />
                <s:textfield name="noOfLicense" label="License Purchased" />
                <s:textfield name="licenseExpireDate" label="License Expire Date" title="YYYY-MM-DD like 2013-01-21" /> 
                <s:textfield name="userActiveDuration" label="Active User Duration"
                    title="please mention in days" />
                <s:textarea cols="30" rows="5" name="notes" label="Note"></s:textarea>
                <s:submit value="Add"></s:submit>
            </s:push>
        </s:form>

Action Method that show this view is as

public String addDomainPage() {

    return ActionSupport.SUCCESS;
}

I have created another page that list the all domains and provide a edit link to edit any domain. When Use click on edit URL this action is called

public String loadDomain() {

    HttpServletRequest request = ServletActionContext.getRequest();
    String url = request.getParameter("durl");
    IDPBroker broker = new IDPBroker();
    idp = broker.getDomainByURL(url);
    return ActionSupport.SUCCESS;
}

On successful completion of action I show the add.jsp page. Struts populate the data in JSP page.

Now, issue is that I want to change the value of action attribute of form tag. I also want to change the value of submit button to 'Edit'. I have plan to create some private attribute(action,Label) in Action class and when an addDomainPage action is call I will change the value of these attribute with respect to add page. Similar for loadDomain action. Now I don't know how to do this means how to use these private attributes in view. Tell me is I am doing correctly and what to do next?

有帮助吗?

解决方案

The same action class could be used to map different methods on submit buttons. Like

<s:submit value="Add" method="addDomainPage" />
<s:submit value="Load" method="loadDomain" />

The form action attribute should map to the action class execute method which will never call if you use submit buttons like that. The DMI which is enabled by default allows to call specified methods.

If you want to dynamically change attributes in the Struts tags you could use OGNL expressions in JSP instead of hardcoded values. For this purpose you should define properties in the action that define dynamic values before result is executed. For example

public String getAction(){
  return "AddDomain";
}  

<s:form action="%{action}">
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top