1, each execution of a method in the Action class is executed twice getModel method ;
2, do the update feature , the first time the page jump to update the data is blank , and the second piece of data before the jump is to display the information , search the Internet less, said it would "ModelDrivenInterceptor provides a configuration parameter : refreshModelBeforeResult, as long as it is defined as true, the problem has been solved ! "What is configured in Struts.xml do ?
My struts.xml configuration is as follows , but no matter , the solution ! ! ! !
name = "refreshModelBeforeResult">
true
true
. / back / news / showAllNewsInfo.jsp
------ Solution ------------------------------------ --------
limited, I do not understand your question ! can code did you get to see it
------ For reference only -------- -------------------------------
master all go ah , their top one
--- --- For reference only ---------------------------------------
------ For reference only ---------------------------------- -----
------ For reference only ---------------------------------- -----
possible
Action class code :
public class NewsAction extends BaseAction implements ModelDriven
private NewsServiceImpl newsService; / / Press service layer interface class
private NewsDTO newsInfo = new NewsDTO (); / / instantiate News category
/ **
* Get all the news and information
*
* @ return
* @ throws Exception
* /
public String showAllNewInfo () throws Exception {
if (null! = newsInfo) {
String title = newsInfo.getTitle ();
String newType = newsInfo.getNewtype ();
if (null! = title)
newsInfo.setTitle (title);
if (newType! = null)
newsInfo.setNewtype (newType);
}
pageInfo.setPageNo (pageNo); / / set page
newsService.getAllNewsByPage (newsInfo, pageInfo);
/ / assign all the news and information "newsList" variable
newsList = pageInfo.getList ();
pageMap.put ("pageNo", pageInfo.getPageNo ());
pageMap.put ("pageSize", pageInfo.getPageSize ());
pageMap.put ("pageTotal", pageInfo.getPageTotal ());
pageMap.put ("recTotal", pageInfo.getRecTotal ());
return this.SUCCESS;
}
/ **
* Add News
*
* @ return
* @ throws Exception
* /
public String doInsertNewInfo () throws Exception {
String newCode = randomNum.getTimeStamp ("N_");
long readNum = 1;
newsInfo.setNewcode (newCode);
newsInfo.setPublishtime (new Date ());
newsInfo.setReadnumber (readNum);
boolean flag = newsService.doInsertNews (newsInfo);
if (flag) {
newsInfo.setTitle (null);
newsInfo.setNewtype (null);
messages = " Add succeed ! ' ;
return this.showAllNewInfo ();
} else {
messages = " Sorry , the information added Failed ! Please confirm whether the required fill in ! ' ;
return this.INPUT;
}
}
/ **
* Number delete news and information according to news
*
* @ return
* @ throws Exception
* /
public String doDelNewInfo () throws Exception {
/ / Get news Numbers
String newsCode = request.getParameter ("code");
/ / call the Delete method
boolean flag = newsService.doDelNewsByCode (newsCode);
/ / According to "flag" the return value gives the corresponding message
if (flag) {
messages = " information has been successfully deleted ! ' ;
} else {
messages = " Sorry , the information Delete Failed ! ' ;
}
return this.showAllNewInfo ();
}
/ **
* updated news and information methods
*
* @ return
* @ throws Exception
* /
public String doModifyNewInfo () throws Exception {
return this.SUCCESS;
}
/ **
* news and information according to a news Lookup Method
*
* @ return
* @ throws Exception
* /
public String showNewInfo () throws Exception {
/ / Get news Numbers
String newsCode = request.getParameter ("code");
/ / invoke methods to obtain news entity information
newsInfo = newsService.getNewsInfoByCode (newsCode);
/ / Go to the update page
return "to_updateNewsInfo";
}
public NewsDTO getModel () {
if (newsInfo! = null) {
newsInfo = new NewsDTO ();
}
return newsInfo;
}
public NewsDTO getNewsInfo () {
return newsInfo;
}
public void setNewsInfo (NewsDTO newsInfo) {
this.newsInfo = newsInfo;
}
public void setNewsService (NewsServiceImpl newsService) {
this.newsService = newsService;
}
}
struts.xml code
. / back / news / showAllNewsInfo.jsp
/ back / news / showNewsInfo.jsp
/ back / news / doModifyNews.jsp
.. /.. / back / news / showAllNewsInfo.jsp
. / back / news / showAllNewsInfo.jsp
true
.. /.. / back / news / showAllNewsInfo.jsp
------ For reference only ---------------------------------- -----
------ For reference only ---------------------------------- -----
code above getModel () method code is wrong :
if (newsinfo! = null) {
....
}
should read:
if (newsinfo == null) {
....
}
------ For reference only ---------------------------------- -----
estimated landlord would have solved the problem, but did not answer here . . . .
I also encountered the same problem , check the next , it seems that the landlord needs to be changed in struts.xml in refreshModelBeforeResult modelDriven.refreshModelBeforeResult. Like this:
<interceptor-ref name="defaultStack">
<param name="modelDriven.refreshModelBeforeResult">true</param>
</interceptor-ref>
should be fine
------ For reference only ------------------------------ ---------
If you have not read the children's shoes , you can look here :
http://unmi.cc/struts2-how-to-override-interceptor-parameters
没有评论:
发表评论