struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ylva Degerfeldt" <ylva.degerfe...@gmail.com>
Subject [S2] One hidden value doesn't get submitted (another one does). Why?
Date Mon, 01 Sep 2008 17:32:37 GMT
Hi,

My current problem is about a hidden value which isn't saved to the Action.

This is the background information I think is needed:
The value in question (called "state") is an int property of a POJO
called "InfoObject". Other relevant properties of the POJO are "id" (a
String) and "name" (Str.)
In my application a List of these objects is generated and saved in
the current HttpSession.
The action that generates that list calls a JSP which iterates through
the List (using "#session.nameOfList") and for each object shows
certain properties and gives the user a chance to change their values
by using select boxes and buttons (One row equals one object in the
list).

The thing that isn't entirely working right now is this: In each
generated row there's an "Edit" button. When the user clicks it, the
"name" Label (to the left in the row) should change into a TextField
(so the user can edit it) and stay a TextField until the user clicks
the "Save" button of that row. This behaviour is controlled by the
"state" variable of the "InfoObject" (0 means that "name" should be a
Label and 1 means a TextField).

The corresponding Action of the form that shows this List has get- and
set properties for the List along with an "index" property. The
"index" property takes the value of the index of the object in the
List whose "Edit" button was pushed (e.g. the index of the row).

By the way, this Action always returns to the input page. (I'm having
another Action for proceeding)

I get this far: When I click an "Edit" button for the first time the
right index is saved to the "index" property of the Action and I
change the "state" from 0 to 1 for the corresponding object. Then the
JSP is rendered again and the "name" value of the corresponding row is
shown in a TextField instead of a Label which is correct.
Then I try clicking on the "Edit" button of another row, but when the
JSP is rendered again the "state" value belonging to the first row has
changed back to 0 and it's only the "new" row which shows the "name"
as a TextField.

When I debugged the code I noticed that the "state" value is not
submitted to the Action (the "setState" method of the objects is never
called). I have the "state" value as a Hidden field in the form.
Another hidden field is the "id" field. The weird thing is that the
"id" field gets submitted though "state" doesn't, and the s:hidden
tags (and values) have the same structure:

<s:hidden name = "MyList[%{#iterState.index}].name" value = "%{name}"/>
<s:hidden name = "MyList[%{#iterState.index}].state" value = "%{state}"/>

I've also searched for spelling errors but have not found any.
I can add that at first I didn't have a field for "state" in the JSP
but then I realized that I should have one, so I added the Hidden
field and did a "Clean and build" of the app.

Another important thing (which May be the cause of this problem but I
can't tell yet) is that my List is saved in two places (though for a
short while). I want to keep it in the Session and the first time the
JSP is shown I have to pick the List from the session
(#session.MyList), Don't I?
Then each instance of the Action that is called afterwards gets its
own copy of the list and (if I understand correctly), if I didn't do
anything about it, the list would be in two places of the
ActionContext when the JSP is to be rendered again (in the Session and
in the Action instance). Though, in my Action I set the Session
reference to the List (a HttpSession attribute) to point to the List
instance of the Action (because I want to keep it updated). Could that
be causing the problem?

I think it would be good if I could reference the List in the JSP Only
from the Action, but the First time that can't be done (and then I
Always have to get it from the Session, right?) Is there anyone who
has made a similar application and can tell me how he/she did it (I
mean just this "session and Action thing")?

But.. Back at the first problem. I'm not sure if this "list in two
places" thing is causing the problem but it might be.
Anyway, I would really appreciate if someone could help me with this!
(Meanwhile I'll read some more in "Struts 2 in Action" to see if that
clears up anything.)

Big Thanks in advance!

/Ylva

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message