price.xml
<package name="priceList" namespace="/price" extends="struts-default">
<default-interceptor-ref name="paramsPrepareParamsStack" />
<action name="PriceAction_*" method="{1}" class="billing.price.PriceAction">
<result name="input">/price/PriceDetailList.jsp</result>
<result name="success">/price/PriceDetailList.jsp</result>
<result name="list">/price/PriceList.jsp</result>
</action>
</package>
PriceAction.java
public class PriceAction extends BaseAction
implements ModelDriven, Preparable{
private PriceList model;
public PriceList getModel(){
return model;
}
public void prepare() throws Exception{
if(getRequestId() == 0){
model = db.getBlankPriceList();
}else{
model = (PriceList) db.get(getRequestId());
}
}
public class PriceList {
private long id = System.nanoTime();
private Date created = new Date();
private Date effected;
private String area;
private String scheme;
private Map prices = new HashMap();
setters/getters...
}
public class Product {
private long id = System.nanoTime();
private String name;
private String unit; // Kg/Ltr
private double wt; // no.of pieces in decimal ex: 0.500 2.500 0.400
}
<s:iterator value="prices">
<tr>
<td>
<s:textfield name="%{#key.priceListId}" readonly="true" value="%{prices[key].priceListId}" size="15%"/>
</td>
<td>
<s:textfield name="key.product.Id" readonly="true" value="%{prices[key].product.Id}" size="15%"/>
</td>
<td>
<s:textfield name="key.product.name" readonly="true" value="%{prices[key].product.name}" size="25%"/>
</td>
<td>
<s:textfield name="key.tax" readonly="%{readOnly}" value="%{prices[key].tax}" size="5%"/>
</td>
<td>
<s:textfield name="key.superStockistPercent" readonly="%{readOnly}" value="%{prices[key].superStockistPercent}" size="5%"/>
</td>
<td>
<s:textfield name="key.distributorPercent" readonly="%{readOnly}" value="%{prices[key].distributorPercent}" size="5%"/>
</td>
<td>
<s:textfield name="key.agentPercent" readonly="%{readOnly}" value="%{prices[key].agentPercent}" size="5%"/>
</td>
<td>
<s:textfield name="key.mrp" readonly="%{readOnly}" value="%{prices[key].mrp}" size="5%"/>
</td>
</tr>
</s:iterator>
</table>
我正在尝试更新Model的地图类型属性但不能更新,请在此指导
所有值都会更新,但地图值不会更新。
地图键是长地图 我想用product.id在地图中存储价格 以下是PriceListService.jav,因为我创建了PriceList作为模型
public class PriceListService{
private static Map<Long, PriceList> priceLists = new HashMap<Long, PriceList> ();
static {
Collection<Product> cols;
HashMap<Long, Price> prices;
Price price;
double mrp;
PriceList priceList1 = new PriceList( );
try{
priceList1.setEffected(new SimpleDateFormat( "yyyyMMdd" ).parse( "20170201" ));
}catch(ParseException pe){pe.printStackTrace();}
priceList1.setArea("Kolhapur, Ichalkaranji, Sangali, Karad, Satara");
priceList1.setScheme("On Total 25Kg purchase 1Kg Srikhand or Amrakhand Free");
prices = new HashMap<Long, Price>();
cols = new ProductService().getProducts();
mrp = 0.00;
for(Object o: cols){
Product product = (Product) o;
price = new Price();
mrp+=100.00;
price.setPriceListId(priceList1.getId());
price.setProduct(product);
price.setMrp(mrp);
price.setTax(6.50);
price.setAgentPercent(18.00);
price.setDistributorPercent(7.50);
price.setSuperStockistPercent(3.50);
prices.put(price.getProduct().getId(), price);
}
priceList1.setPrices(prices);
priceLists.put(priceList1.getId(), priceList1);
PriceList priceList2 = new PriceList( );
try{
priceList2.setEffected(new SimpleDateFormat( "yyyyMMdd" ).parse( "20170301" ));
}catch(ParseException pe){pe.printStackTrace();}
priceList2.setArea("Solapur, Pandharpur, Ajluj, Ratnagiri, Sindhudurg");
priceList2.setScheme("On Total 30Kg purchase 1Kg Fruitkhand Free");
prices = new HashMap<Long, Price>();
cols = new ProductService().getProducts();
mrp = 0.00;
for(Object o: cols){
Product product = (Product) o;
price = new Price();
mrp+=1000.00;
price.setPriceListId(priceList2.getId());
price.setProduct(product);
price.setMrp(mrp);
price.setTax(6.50);
price.setAgentPercent(20.00);
price.setDistributorPercent(8.00);
price.setSuperStockistPercent(3.00);
prices.put(price.getProduct().getId(), price);
}
priceList2.setPrices(prices);
priceLists.put(priceList2.getId(), priceList2);
}
public Collection getPriceLists(){
ArrayList list = new ArrayList();
list.addAll ( priceLists.values() );
return list;
}
public Object get(long id){
return priceLists.get(id);
}
public void save(Object object) {
/* Persist product. */
PriceList priceList = (PriceList) object;
priceLists.put( priceList.getId(), priceList);
System.out.println(priceList.getArea() + " is saved successfuly.");
}
public void remove(Object object) {
/* Remove Persisted product. */
PriceList priceList = (PriceList) object;
String area= ((PriceList) get(priceList.getId())).getArea();
String effected = (((PriceList) get(priceList.getId())).getEffected()).toString();
priceLists.remove(priceList.getId());
System.out.println(area + " : " + " is removed successfuly.");
}
}