Using dynamic form fields in WebWork

Source: Internet
Author: User
Tags implement return
Web| News

In general, WebWork uses field-driven or model-driven methods to get data from a form. (Plain form)
However, in some cases, the field name content that needs to be edited is dynamic, and there is no way to use a defined class for mapping.

At this point I think of the following ways to solve:

  1. Use WebWork internal objects, remove all parameters

Actioncontext context = Actioncontext.getcontext ();
Map params = Context.getparameters ();

Operation params can get all parameters

  2. Use map map

The map has get,put functions, such as Get ("name"), Put ("name", "Scud")
After testing (there is no explanation for this in the document, WebWork's documentation is still very small, and I may not have read it)

Mapping in forms takes the form of:
<input name= "Fields.name" >

The read value takes the form of fields[' name ', which is mentioned in the document

The specific documents are as follows:


A: Input Page

<%@ taglib uri= "webwork" prefix= "ww"%>
<title>webwork Test 2</title>
<body>
<p>what ' s your name?</p>
<form action= "Hello.action" method= "POST" >
<p>
<input type= "text" name= "Field.person"/><br>
<input type= "Submit"/>
</p>
</form>
</body>

B:success turn to Page


<%@ taglib uri= "webwork" prefix= "ww"%>
<title>webwork Test 2</title>
<body>
Hello, <ww:property value= "field[' Person" "/><br>
</body>

C: Action class used


Package HelloWorld;

Import com.opensymphony.xwork.*;
Import java.util.*;

public class Helloaction extends Actionsupport
{
Private Map field = new HashMap ();

Public String Execute () throws Exception
{
return SUCCESS;
}

public void SetField (Map field)
{
This.field = field;
}

Public Map GetField ()
{
return field;
}
}

Part of the configuration inside the D:xwork.xml

<action name= "Hello" class= "helloworld.helloaction" >
<result name= "Error" type= "Dispatcher" >ex02-index.jsp</result>
<result name= "Success" type= "Dispatcher" >ex02-success.jsp</result>
</action>



  3. Use user-defined classes to implement

This approach is not much discussed, and the user's class may need to implement a function similar to getxxx (String SKey).



  Summarize:

Of course there should be other ways to achieve, and may be better, but I just see webwork not a few days, to my concern about the problem of the above method, it is certainly a relatively simple idea.

If there is another way, please feel free.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.