This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Struts and the fly likes poplulate values of FormBean/reset/edit? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "poplulate values of FormBean/reset/edit?" Watch "poplulate values of FormBean/reset/edit?" New topic

poplulate values of FormBean/reset/edit?

Herman Zweibel

Joined: Feb 02, 2004
Posts: 12
What I am trying to do seems extremely common and I don't think I have understood the way you are supposed to do this in struts yet.
I have an app where you can create and edit new users - no problems for new but if you need to edit - you need to query the database and then prepopulate the workflow of the app with values that have already been selected - common right? I thought I had this figured out and have been doing something like this in my formBean:
public void reset(ActionMapping mapping,HttpServletRequest request) {

HttpSession session = request.getSession();

UserExistsPopulateBean uepBean = (UserExistsPopulateBean)session.getAttribute(Constants.USER_EXISTS_POPULATE_BEAN);
Boolean usPageResetFlag = (Boolean)session.getAttribute(Constants.USER_ACCESS_PAGE_RESET_FLAG);

if(uepBean.isUserAlreadyExists() && !usPageResetFlag.booleanValue())

//update form values from another bean that has been updated from
//DB in previous page's action


//reset form vales to null etc.

}//end reset
The problem is: that if on an edit page - and some of the widgets have been prepopluated based on this first if clause - and then the user changes some of the values on the form - then when the action is called it still goes into the first if clause - which has old form values. I tried setting a flag in the action of this formBean but that doesn't work because it seems the reset function gets called before anything in the action.
So how can I accomplish my goal?
Is one way to create an instance of this formBean in the previous page's action and popluate it's values then put it into the session - hoping that with reflection struts will populate the page - then the reset method in the actual formBean could just null out the values etc. but I don't know if that will work?
Please help - links or sample code greatly appreciated.
Many Thanks!!!
poornima balagopal
Ranch Hand

Joined: Dec 02, 2003
Posts: 83
I am also doing some what similar to this only. But what i am doing is
for adding i have one jsp and for editing another page. But in your case i think you have only one jsp fro both. First you will add then on submit you will populate the fields again with the edited value is it ?
I dont have exact idea about reset method . What i am doing is on submission of the page for adding handle the formBean in the session. So one again when you come to your page for editing populate the page with only required field or display all the fields give permission to certain fields as editable.
Hope this will help you
i am also doing the same to populate the values for editing but as i told before i have seperate page for editing
all the best
I agree. Here's the link:
subject: poplulate values of FormBean/reset/edit?
It's not a secret anymore!