ahsan mir

Ranch Hand
+ Follow
since Jul 17, 2006
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by ahsan mir

For any one interested the following code performs basic indexed properties validation without the use of validation.xml

[CODE] public ActionErrors validateForm(ActionMapping actionMapping, HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

if(request.getParameter("action").equals("updatePO")) {
if(getPurchaseOrderProductList().size() >0)
Iterator iter=m_aPurchaseOrderProductList.iterator();
PurchaseOrderProduct pop=(PurchaseOrderProduct)iter.next();
try {
if(Integer.parseInt(pop.getInvoiceQty())<0) {
catch (Exception e)



<logic:messagesPresent property="invalidInvoicePrice${purchaseOrderProduct.productId}">
<img src="<c:url value="/images/error.gif"/>" alt="<html:errors property="invalidInvoicePrice${purchaseOrderProduct.productId}"/>"/>
16 years ago
let me rephrase the problem: can i even validate an indexed property?
16 years ago
any advice would be very much appreciated. i have searched the net and hav found nothing useful.
16 years ago
i am using indexed properties in my struts application , and all i well except that it doesnt do validation. My form bean is populated with a list of objects and upon submission i want errors listed for each object's invalid values.

Following is the JSP:
<html:form action="invoice.form?action=updatePO" method="post">
<logic:iterate id="purchaseOrderProduct" name="invoicePOForm" property="purchaseOrderProductList">
<html:hidden name="purchaseOrderProduct" property="productId" indexed="true"/>
<td><bean:write name="purchaseOrderProduct" property="productId"/></td>
<td><bean:write name="purchaseOrderProduct" property="productTitle"/></td>
<td><bean:write name="purchaseOrderProduct" property="orderedQty"/></td>
<td><bean:write name="purchaseOrderProduct" property="receivedQty"/></td>
<td><bean:write name="purchaseOrderProduct" property="invoicedQty"/></td>
<td><bean:write name="purchaseOrderProduct" property="costPrice"/></td>
<c:if test="${purchaseOrderProduct.clearedStatus==0}">
<td>£<html:text name="purchaseOrderProduct" property="invoiceUnitPrice" size="30" indexed="true"/></td>
<td>£<html:text name="purchaseOrderProduct" property="invoiceTotalPrice" size="30" indexed="true"/></td>
<td><html:text name="purchaseOrderProduct" property="invoiceQty" size="30" indexed="true"/></td>
<td>Clear<html:multibox property="selectedProductIds"><bean:write name="purchaseOrderProduct" property="productId"></bean:write></html:multibox> </td>
<c:if test="${purchaseOrderProduct.clearedStatus==1}">
<td>£<bean:write name="purchaseOrderProduct" property="invoiceUnitPrice"/> </td>
<td>£<bean:write name="purchaseOrderProduct" property="invoiceTotalPrice"/> </td>
<td><bean:write name="purchaseOrderProduct" property="invoiceQty"/> </td>
<td><html:errors property="invalidInvoicePrice"></html:errors></td>
<%-- <td<html:errors property="invalidInvoicePrice"></html:errors></td>-- This bit fails as errors maybe of a number of objects' values.%>

any idea how to generate the errors messages.

Following is the error handling method in the form bean:

public ActionErrors validateForm(ActionMapping actionMapping, HttpServletRequest request) {

ActionErrors errors = new ActionErrors();
if(getPurchaseOrderProductList().size() >0)
for(PurchaseOrderProduct pop:m_aPurchaseOrderProductList) {
if (pop.getInvoiceUnitPrice()<0)

return errors;
16 years ago
thanks, it works now.
what do you mean by:

When you redirect, you lose any information stored in the HTTPServletRequest, so to pass information to the JSP, you must either store it in the session or pass it with query string parameters.

In my ActionForward i have added the servlet path for the jsp , and its showing the correct jsp.Is that what you mean?
16 years ago
in my action class whenever i do a forward to a success jsp page the whole struts url gets forwarded as well.as a result the jsp page behaves as part of the struts application, how can i get round this. the jsp i want to get forwarded to is routed through a servlet which populates the jsp with some option values. how can i get the simple jsp page with no struts url attached.
i am using 'return mapping.findforward('success.jsp')'. Whts the difference between this and 'return new ActionForward('success.jsp').

thanks in advance.
16 years ago
Thanks for the advice, and pointing me in the right direction. I am now getting the right values.
I have one last question , more conceptual one than any coding. I have to give the user option of adding a product to the purchaseOrder from the JSP page. Does this mean i would need an another formbean and a action class for this. How can i add a new PO line to the Purchase Order whilst retaining any changes done on the JSP page.Can you point me in the right direction.

16 years ago
another problem. The text boxes i am using displays values taken from the database/object's values when the form is loaded. If a user change those values , the action class still takes the database values. How can it take the changed values? what changes do i have to make to the form bean .

Thanks in advance.
16 years ago
Thanks for the code, it worked!

I was working on a solution of adding the attribute 'isSelectedCheckBox' to the PurchaseOrderProduct object itself(not the form bean). It works but once the checkbox is checked and submit clicked and if the user is directed to the same originating screen(this wont happen in the end product) the checkbox retains it initial value(i.e. once true, itll stay true forever). dont know how to get round this.
16 years ago
realised the formbean has an additional attribute as well:

public List<PurchaseOrderProduct> m_aPurchaseOrderProduct=new ArrayList<PurchaseOrderProduct>();


16 years ago
I am new to struts, and working on a form where a user would use checkboxes to select specific records from a list .The list object is of type 'purchaseOrder' and it can contain 1 or more products. My question is how would the struts action class know which of the product has been clicked.

following is the JSP code:

<nested:root name="invoicePOForm">
Invoice Details for Purchase Order Number: <nested:write property="purchaseOrderNumber"/>
<nested:iterate property="purchaseOrderProduct">
<td Width="15%"><nested:write property="productId"/> </td>
<td Width="25%"><nested:write property="productTitle"/></td>
<td Width="10%"><nested:write property="orderedQty"/> </td>
<td Width="10%"><nested:write property="receivedQty"/> </td>
<td Width="10%"><nested:write property="invoicedQty"/> </td>
<td Width="15%"><nested:write property="costPrice"/> </td>
<td Width="15%"><nested:text property="invoiceUnitPrice"/> </td>
<td Width="15%"><nested:text property="invoiceTotalPrice"/> </td>
<td Width="10%"><nested:text property="invoiceQty"/> </td>
<td Width="15%"><html:checkbox property="selectedCheckbox" value="ok"/> </td>

<html:submit> Submit </html:submit>


Follwowing is the form bean:
public PurchaseOrder m_aPurchaseOrder;
public String m_sPurchaseOrderNumber;
public String selectedCheckbox[]=new String[]{};

public String[] getSelectedCheckbox() {
return selectedCheckbox;

public void setSelectedCheckbox(String[] selectedCheckbox) {
this.selectedCheckbox = selectedCheckbox;

public String getPurchaseOrderNumber() {
return m_sPurchaseOrderNumber;

public void setPurchaseOrderNumber(String m_sPurchaseOrderNumber) {
this.m_sPurchaseOrderNumber = m_sPurchaseOrderNumber;}

public PurchaseOrder getPurchaseOrder() {
return m_aPurchaseOrder;

public void setPurchaseOrder(PurchaseOrder m_aInvoicePurchaseOrder) {
this.m_aPurchaseOrder = m_aInvoicePurchaseOrder;

public List<PurchaseOrderProduct> getPurchaseOrderProduct() {
return m_aPurchaseOrderProduct;

public void setPurchaseOrderProduct(List<PurchaseOrderProduct> m_aPurchaseOrderProduct) {
this.m_aPurchaseOrderProduct = m_aPurchaseOrderProduct;

public void clearAll(){

public void reset(ActionMapping mapping, HttpServletRequest request){
this.selectedCheckbox=new String[]{};



Following is part of Action class:

List<PurchaseOrder> poList=Service.getInvoicePurchaseOrder(request.getParameter("cid"));
PurchaseOrder ipo=poList.get(0);

16 years ago
I have just started threads ,and using them with database calls in my swing application. I am getting the above exception if the same thread is called more than once(this happens if a value is not valid for example, so stays in the same frame/class). Any suggestions how to get round it.

any help would be appreciated
the yield method gives an alternative way, what i really wanted is make use of synchronization in an appropriate way/object.
when i run the following code , even after removing the 'synchronized(this)' keyword i get the same output, I want to print without synchronization output like "ABABABBABCBBCCC..." .any suggestions.

public class Synchroniz extends Thread {

StringBuffer sb;

public Synchroniz(StringBuffer sb) {
public void run() {
for(int i=0;i<=5;i++){

public static void main(String args[]) {
Synchroniz synA=new Synchroniz(new StringBuffer("A"));
Synchroniz synB=new Synchroniz(new StringBuffer("B"));
Synchroniz synC=new Synchroniz(new StringBuffer("C"));

i have just finished my degree project based on XML and related technologies(XMLBeans, DOM and a bit of XPath).interested in doing the 142 xml certification.any suggestions for the reading material i.e books, online tutorials...