DynaActionForm question

2003-01-19 Thread Mark Minnie
"Struts in Action" on page 162 reads:

"You can use a DynaActionForm anywhere an ActionForm can be used.  You can also 
substitute a DynaActionForm for a conventional ActionForm without changing any of the 
existing Java or JSP code."

I changed a ActionForm to a DynaActionForm by using the struts-config.xml:


   
   


I thought I would not have to change my existing code in the Action java code, but my 
existing code did not work.  I originally had:

String username = ((LoginForm)form).getUsername();
String password = ((LoginForm)form).getPassword();

The LoginForm was the form bean that I had created manually in java.  I deleted the 
LoginForm and replaced the form bean with a DynaActionForm as listed above.  Of 
course, once I no longer have a LoginForm.java file because it is a DynaActionForm, 
this Action java code does not compile. 

Therefore I see that I have to change my code in going from a manually coded form bean 
to a DynaActionForm.  

Am I missing something?

TIA

Mark


Multiple parameters

2003-01-07 Thread Mark Minnie
How do you create a link such as

Edit Bob

I am talking about having multiple HTTP get parameters  

user=BOB
AND
account=ABC123


TIA

Mark


Help

2003-01-06 Thread Mark Minnie
How do you create a link such as

Edit Bob

I am talking about having multiple HTTP get parameters  

user=BOB
AND
account=ABC123


TIA

Mark


Iterate help

2003-01-02 Thread Mark Minnie
Let me try to explain this a quickly and clearly as possible.  I want to
make my struts application have a calendar.  The user can add notes to each
day on the calendar.  I made a class that will contain all the information
for the note (see the ANote class below).  The note class contains a string
and a date.  I also have a class that store many notes.  The class (see the
MyNotes class below) will hold the notes in ArrayLists that are stored in a
Hashtable.  So if I add 2 notes for Jan 1, 2003 and 3 notes for Jan 2, 2003,
the Hashtable will contain 2 ArrayListsone array list for each day.  I
thought this would be easy to iterate through each ArrayList...that is
what I thought.  My struts Action will create a MyNotes object, fill the
MyNotes object with the notes that need to be displayed on the calendar (may
be a weekly calendar, monthly, etc).  This filled MyNotes object will be set
as a request attribute (e.g. request.setAttribute("myNotes", myNotes); ).

What I don't know how to do is to easily get the ArrayList for each day
using the MyNotes.getNotes(date) method.  I am _trying_ to use the struts
logic tag libraries to do this.  I CAN do this using Java code in my JSP,
but that is the purpose of the struts design...to minimize the use of Java
in the JSP.  So...is there a way to use the struts logic:iterate tag to get
the ArrayList of a particular day?  Something like:

("theDays" can be a collection of the days to display on the calendar)


   >
  The note says:
   





---
import java.util.Date;

public class ANote {

protected String note;
protected Date event_date;

public void setNote(String note) { this.note = note; }
public String getNote() { return note; }

public void setEventDate(Date event_date) { this.event_date =
event_date; }
public Date getEventDate() { return event_date; }
}


---

import java.util.Hashtable;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
import java.text.SimpleDateFormat;

public class MyNotes {

private Hashtable allNotes;

// Adds a note to the ArrayList in the Hashtable
public void addNote(ANote myNote) {
ArrayList notes;

// Get date as hash key
SimpleDateFormat sdf = new SimpleDateFormat("MMdd");
String dateString = sdf.format(note.getEventDate());

// get existing array list for date
try {
notes = (ArrayList)allNotes.get(dateString);

if (notes == null) {
notes = new ArrayList();
allNotes.put(dateString, notes);
}
} catch (Throwable t) {
}

// Add appointment
notes.add(myNote);
}

// Returns all MyNotes from a date
public ArrayList getNotes(Date date) {
ArrayList notes;

// Get hash key
SimpleDateFormat sdf = new SimpleDateFormat("MMdd");
String dateString = sdf.format(date);

// get existing array list for date
try {
notes = (ArrayList)allNotes.get(dateString);
return notes;
} catch (Throwable t) {
}
}

public MyNotes() {
allNotes = new Hashtable();
}

}


--
To unsubscribe, e-mail:   
For additional commands, e-mail: 




Action mappings

2002-11-26 Thread Mark Minnie
Maybe I am missing something, but.

I have a customer form (CustomerView.do) that takes a HTTP GET parameter to
show a customer.  (ie. CustomerView.do?customerid=4).  On this customer
form, there are links to JSP pages to modify the data of the customer.  If I
wanted to add a phone number, then I would call addcustomerphonenumber.jsp.
The AddCustomerPhoneNumber.do action mapping is as follows:

 
  
  
  
 

This action populates the customer form (puts a hidden input field
containing the customer number "4") and the addcustomerphonenumber.jsp is
displayed. When the user SUBMITS the addcustomerphonenumber.jsp the
SaveAddedCustomerPhoneNumber action is called.


  
  
  


MY PROBLEM IS:
This saves the customer phone number, but I get an error that the customer
bean is not found in the scope null.  This is because the "success" forward
is forwarding to /CustomerView.do with NO GET PARAMETER.  Since this get
parameter is dynamic depending upon the customer, how do I return to the
CustomerView.do?customerid=4 

Struts is designed to have the action mappings make the MVC design be
easier.  Do I manually have to put code into
SaveAddedCustomerPhoneNumber.java to have the servlet forward the request
back to the HTTP referrer?  I would be surprised is STRUTS does not have a c
lean method to handle something like this.

Thanks for any help in advance.

Mark