我想在提交操作时向用户显示一条信息消息,但消息未显示。如果我使用addActionError
,它可以工作,但我想显示为信息消息,因此使用addActionMessage
。请让我知道我哪里出错了。
public void validateUser() {
List<Product> existingProductList = new ArrayList<Product>();
try {
IProductRepository productRepository = daoRepository
.getProductRepository();
existingProductList = digestRepository
.searchDigests(null, null);
} catch (Exception e) {
e.printStackTrace();
}
for (Product product: existingProductList ) {
if (prod.getQuartzNumber().equalsIgnoreCase(
product.getQuartzNumber())) {
addActionMessage("The Quartz number entered already exists");
break;
}
}
}
以下是我的jsp代码:
<div id="content-wrapper">
<div id="product_create_header">
<h2>Create a New product</h2>
</div>
<!-- Error messages -->
<dl id="dyna_product_create_errors" class="error"></dl>
<form id="product_create_form" method="post">
<!-- product identifiers -->
<!-- product details -->
<fieldset id="product_create_details">
<legend>product Details</legend>
<div class="form-element">
<label for="product_create_name">Name:</label><br />
<input id="product_create_name" type="text" name="product.name" value="" maxlength="256" /><br />
<span id="product_create_name_error" class="error"></span>
</div>
<div class="form-element">
<label for="product_create_presentation_order">Quartz Order:</label><br />
<input id="product_create_presentation_order" type="text" name="product.quartzOrder" value="" maxlength="256" /><br />
<span id="product_create_presentation_order_error" class="error"></span>
</div>
</fieldset>
<!-- Form buttons -->
<div id="product_create_buttons" class="formButtons">
<button id="product_create_button_cancel" type="button" title="Reset" onclick="resetproductCreateForm();">Reset</button>
<button id="product_create_button_submit" type="button" title="Submit" onclick="createproduct();">Submit</button>
</div>
</form>
</div>
我看到他们已经添加了 用于显示错误,不确定如何显示消息
以下是我的js代码:
function createproduct() {
dojo.xhrPost( {
url :"services/product/create",
handleAs :"json",
preventCache :"true",
load : function(returnObject, ioArgs) {
if (returnObject.status == "success") {
product = returnObject.body;
displayproductDetail();
}
else if (returnObject.status == "input") {
var errorList = dojo.byId("dyna_product_create_errors");
handleActionErrors(returnObject.actionErrors, errorList);
handleActionMessage(returnObject.actionMessages, messageList);
handleCreateproductsFieldErrors(returnObject.fieldErrors);
}
else if (returnObject.status == "error") {
resetproductSearchFormErrors();
var errorList = dojo.byId("dyna_product_create_errors");
handleActionErrors(returnObject.actionErrors, errorList);
}
},
error : function(error) {
handleHTTPError(error);
},
form :'product_create_form'
});
}
答案 0 :(得分:0)
private String myActionMessage;//Getter and setter Method
public void validateUser() {
List<Product> existingProductList = new ArrayList<Product>();
try {
IProductRepository productRepository = daoRepository
.getProductRepository();
existingProductList = digestRepository
.searchDigests(null, null);
} catch (Exception e) {
e.printStackTrace();
}
for (Product product: existingProductList ) {
if (prod.getQuartzNumber().equalsIgnoreCase(
product.getQuartzNumber())) {
addActionMessage("The Quartz number entered already exists");
getMyActionMessage("The Quartz number entered already exists");
break;
}
}
}
你的result.jsp文件
<s:actionmessage/>
<s:property value="myActionMessage"/>