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.