Re: Accessing nested properties
No, the foo_array is an array of Foo. Each Foo object holds a Bar object wich holds a test field (see sample code). I'm trying to access the test-field's value from within the iteration over Foo objects. Regards, Fredrik Laurie Harper wrote: Change property=bar.test to property=test; assuming foos_array is an array of Bar then, within the iterate tag body, 'foos' is bound to an instance of Bar on each iteration. L. Fredrik Bostrom wrote: Hi list, How do I access a nested property in an iterated object? I've got two classes like this (heavily simplified and stripped): class Foo { Bar bar = new Bar(); } class Bar { int test = 10; //any value } In my jsp-page, I'm iterating an array of foo-objects and I want to access the test-field in the Bar-class from within the iteration. How do I do that? This is what I'd like to do: logic:iterate id=foos name=foo_array logic:greaterThan name=foos property=bar.test value=1000 //do something /logic:greaterThan /logic:iterate But this doesn't work... Any ideas? Regards, Fredrik Boström - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Fredrik Boström +358 44 306 1324 [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Accessing nested properties
Thanks, but I couldn't wait any longer for a solution, so I rewrote the whole page with jstl instead. Works like a charm :) Regards, Fredrik rajiv verma wrote: Try adding the type attribute to the logic:iterate tag. I always do something like this: logic:iterate name=adminAuthCompany id=adminAuthCompanyId type=com.ao.model.auth.IAuthorizationParameter and it works for me. -Rajiv On 6/21/05, Fredrik Boström [EMAIL PROTECTED] wrote: No, the foo_array is an array of Foo. Each Foo object holds a Bar object wich holds a test field (see sample code). I'm trying to access the test-field's value from within the iteration over Foo objects. Regards, Fredrik Laurie Harper wrote: Change property=bar.test to property=test; assuming foos_array is an array of Bar then, within the iterate tag body, 'foos' is bound to an instance of Bar on each iteration. L. Fredrik Bostrom wrote: Hi list, How do I access a nested property in an iterated object? I've got two classes like this (heavily simplified and stripped): class Foo { Bar bar = new Bar(); } class Bar { int test = 10; //any value } In my jsp-page, I'm iterating an array of foo-objects and I want to access the test-field in the Bar-class from within the iteration. How do I do that? This is what I'd like to do: logic:iterate id=foos name=foo_array logic:greaterThan name=foos property=bar.test value=1000 //do something /logic:greaterThan /logic:iterate But this doesn't work... Any ideas? Regards, Fredrik Boström - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Fredrik Boström +358 44 306 1324 [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Fredrik Boström +358 44 306 1324 [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
logic:lessThan inside logic:iterate
Dear list, I've been fighting this problem for some time now, and can't come up with a solution. Please advice. In my jsp page I'm iterating an array of Category objects which resides in the request scope. This is done with the logic:iterate tag like this: logic:iterate id=categories name=category_array Each Category-object contains a Message-object field called lastmessage which in turn contains a timestamp-field (a long). In session-scope, there is a User object with a lastlogin field (a long). All objects have the appropriate getters (and setters) for all fields. Inside the iteration, I'm trying to do a comparison between the timestamp field of the Message object inside the Category object currently processed and the lastlogin field of the user object. This is how I'd like it to work: logic:iterate id=categories name=category_array logic:present name=user scope=session logic:lessThan name=user property=lastlogin value=category.lastmessage.timestamp //do something /logic:lessThan /logic:present /logic:iterate Now this doesn't work since the timestamp field is referenced wrongly. My next thought was to use logic-el taglib, but there's no lessThan tag in that library, because the jstl-c library is supposed to offer the same functionality. I tried jstl-c's c:if tag, but the problem is that I can't reference the iterating categories object, like this: c:if test=${user.lastlogin categories.lastmessage.timestamp} //do something /c:if This doesn't recognize the categories property. So then I'd have to use the c:iterate tag, but then again I have a bunch of bean:write/ and other el-tags inside the iteration as well, using the categories property created by the logic:iterate tag. These tags wouldn't work properly if using inside a c:iterate tag (i suppose). So, what should I do? How can I reference the timestamp-field in the Message-object inside the Category object in a lessThan tag inside an iteration? (phew) Thankful for any advice. Fredrik Bostrm The relevant code: table class=categorytable logic:iterate id=categories name=category_array tr th html:link action=/ShowThreads.do paramId=categoryId paramName=categories paramProperty=id bean:write name=categories property=name filter=false / /html:link logic:present name=user scope=session logic:lessThan !-- compare user.lastlogin to -- !-- category.lastmessage.timestamp -- New messages! /logic:lessThan /logic:present /th th class=categorycontrols logic:present name=user scope=session logic:equal name=user property=sumode value=true html-el:link action=/EditCategory.do?action=editcategoryId=${categories.id} Edit /html-el:link html-el:link action=/EditCategory.do?action=deletecategoryId=${categories.id} Delete /html-el:link /logic:equal /logic:present /th /tr tr td colspan=2 bean:write name=categories property=description filter=false/ /td /tr /logic:iterate /table - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Losing form values after validating
Hi all. I'm working on a small message-forum project and have stumbled upon many problems along the way, most of which I've been able to more or less solve. To the most recent problem, though, I haven't found any solution despite lots of googling. I'm using a DynaValidatorActionForm to validate input from a form (actually several forms). The form is one of three forms in the same jsp-page. The form to be used is determined by a logic-tag that looks for an action-parameter and ckecks its value. If the value is thread the thread-form is displayed. So the URI to display the thread-form would be /NewForm.do?action=thread. I also have to pass another parameter to the thread-form, namely to which category the thread belongs. This parameter's value is inserted into a hidden field in the form. So, the final URI would be /NewForm.do?action=threadcategory=1. Other fields in the form are - a hidden username field, value from user session bean - thread topic (input type=text) - message (input type=textarea) So, the populated form (but not yet filled in by the user) would look like this: form name=createForm method=post action=/forum_dev/CreateThread.do input type=hidden name=author value=Joe -- from bean input type=hidden name=categoryId value=1 -- from request parameter Topic: input type=text name=topic maxlength=40 size=20 value=br/ Message: textarea name=message cols=60 rows=10/textareabr/ input type=submit value=Create /form When submitting the form, I want it to be validated and if the validation fails, the user is returned to the same page with error-messages displayed. This is currently done by using the following action (which is the action the form submits to): actionpath=/CreateThread type=manegen.forum.CreateThreadAction name=createForm scope=request input=input forward name=input path=/NewForm.do?action=thread / forward name=success path=/ShowMessages.do / forward name=failure path=/ShowThreads.do / /action Validation works fine (when it's failing :), the validator returns to the right page with the right form visible, messages display as they should and everythings seems to be a-ok. But, the problem is that when the validation fails, all form values (except author which comes from the session bean) are lost. This is surely due to the fact that control passes through another action before getting back to the form page. The values somehow get lost on the way. Is there any way to keep the form data through this process? I've tried putting scope=session in the /CreateThread action but with no success. Another alternative would be to maintain a session bean which contains fields for the current category, thread etc, but that bean would demand lots of updating all the time. Any simple solution to this problem? Grateful for any suggestions. Regards, Fredrik - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Losing form values after validating
Just for completeness, I'll post some more relevant information about the application. newForm.jsp (partly) logic:equal parameter=action value=thread !-- Create new thread -- h1New Thread/h1 html:form action=/CreateThread html-el:hidden property=author value=${user.nickname}/ html-el:hidden property=categoryId value=${param.category}/ Topic: html:text property=topic value= size=20 maxlength=40 /br/ Message: html:textarea property=message value= cols=60 rows=10 /br/ html:submit value=Create / /html:form /logic:equal struts-config.xml (partly) - !-- Multi purpose form for creating stuff -- form-bean name=createForm type=org.apache.struts.validator.DynaValidatorActionForm form-property name=author type=java.lang.String / form-property name=categoryId type=java.lang.Integer / form-property name=threadId type=java.lang.Integer / form-property name=topic type=java.lang.String / form-property name=message type=java.lang.String / form-property name=replyto type=java.lang.Integer / form-property name=categoryName type=java.lang.String / form-property name=categoryDescription type=java.lang.String / /form-bean /form-beans !-- Display new user|category|thread|message form -- actionpath=/NewForm forward=.view.newForm / !-- Process new Category -- actionpath=/CreateCategory type=manegen.forum.CreateCategoryAction name=createForm scope=session input=input forward name=input path=/NewForm.do?action=category / forward name=success path=/Home.do/ /action tiles-defs.xml (partly) --- tiles-definitions !-- main layout -- definition name=.layout.main path=/layout/layout.jsp put name=title value=Manegen Forum/ put name=body value=/ /definition !-- views = extensions to the main layout -- definition name=.view.newForm extends=.layout.main put name=body value=/newForm.jsp / /definition /tiles-definitions This is really bothering me, so any ideas would help. Best regards, Fredrik Fredrik Boström wrote: Hi all. I'm working on a small message-forum project and have stumbled upon many problems along the way, most of which I've been able to more or less solve. To the most recent problem, though, I haven't found any solution despite lots of googling. I'm using a DynaValidatorActionForm to validate input from a form (actually several forms). The form is one of three forms in the same jsp-page. The form to be used is determined by a logic-tag that looks for an action-parameter and ckecks its value. If the value is thread the thread-form is displayed. So the URI to display the thread-form would be /NewForm.do?action=thread. I also have to pass another parameter to the thread-form, namely to which category the thread belongs. This parameter's value is inserted into a hidden field in the form. So, the final URI would be /NewForm.do?action=threadcategory=1. Other fields in the form are - a hidden username field, value from user session bean - thread topic (input type=text) - message (input type=textarea) So, the populated form (but not yet filled in by the user) would look like this: form name=createForm method=post action=/forum_dev/CreateThread.do input type=hidden name=author value=Joe -- from bean input type=hidden name=categoryId value=1 -- from request parameter Topic: input type=text name=topic maxlength=40 size=20 value=br/ Message: textarea name=message cols=60 rows=10/textareabr/ input type=submit value=Create /form When submitting the form, I want it to be validated and if the validation fails, the user is returned to the same page with error-messages displayed. This is currently done by using the following action (which is the action the form submits to): actionpath=/CreateThread type=manegen.forum.CreateThreadAction name=createForm scope=request input=input forward name=input path=/NewForm.do?action=thread / forward name=success path=/ShowMessages.do / forward name=failure path=/ShowThreads.do / /action Validation works fine (when it's failing :), the validator returns to the right page with the right form visible, messages display as they should and everythings seems to be a-ok. But, the problem is that when the validation fails, all form values (except author which comes from the session bean) are lost. This is surely due to the fact that control passes through another action before getting back to the form page. The values somehow get lost on the way. Is there any way to keep the form data through this process? I've tried putting scope=session
Re: Losing form values after validating
Thanks for your comment. I tried what you proposed, replacing the action path with the tile definition name. The result was that the tile didn't know which form to display (because the page containes three forms, one of which is selected according to the action request parameter), and thus didn't display anything. So, I thought if I put another hidden field into the form holding the action value... Like this: logic:equal parameter=action value=thread !-- Create new thread -- h1New Thread/h1 html:form action=/CreateThread html-el:hidden property=author value=${user.nickname}/ html-el:hidden property=action value=${param.action}/ html-el:hidden property=categoryId value=${param.category}/ Topic: html:text property=topic value= size=20 maxlength=40 /br/ Message: html:textarea property=message value= cols=60 rows=10 /br/ html:submit value=Create / /html:form /logic:equal I also added the action field to the DynaValidatorActionForm definition in the struts-config.xml. But in the validator configuration files, the field is ignored. The action definition in the struts-config.xml file still has scope=session. The result of this was quite surprising: When submitting invalid information - the validation works fine - the form returns to the correct page with the correct form displayed - the form fields' values are still missing EXCEPT FOR the user and action fields So the missing fields are still: - categoryId - topic - message Like this: !-- Create new thread -- h1New Thread/h1 form name=createForm method=post action=/forum_dev/CreateThread.do input type=hidden name=author value=fredde input type=hidden name=action value=thread input type=hidden name=categoryId value= Topic: input type=text name=topic maxlength=40 size=20 value=br/ Message: textarea name=message cols=60 rows=10/textareabr/ input type=submit value=Create /form As I see it, the action and categoryId fields should be treated the exact same way. But still only action gets re-populated when returning from the validation. Confusing... Ideas? Regards, Fredrik Antony Joseph wrote: Try this. The input point to your tile. !-- Process new Category -- actionpath=/CreateCategory type=manegen.forum.CreateCategoryAction name=createForm scope=session input=input forward name=input path=.view.newForm / forward name=success path=/Home.do/ /action - Original Message - From: Fredrik Boström [EMAIL PROTECTED] To: Struts Users Mailing List user@struts.apache.org Subject: Re: Losing form values after validating Date: Wed, 09 Mar 2005 19:46:23 +0200 Just for completeness, I'll post some more relevant information about the application. newForm.jsp (partly) logic:equal parameter=action value=thread !-- Create new thread -- h1New Thread/h1 html:form action=/CreateThread html-el:hidden property=author value=${user.nickname}/ html-el:hidden property=categoryId value=${param.category}/ Topic: html:text property=topic value= size=20 maxlength=40 /br/ Message: html:textarea property=message value= cols=60 rows=10 /br/ html:submit value=Create / /html:form /logic:equal struts-config.xml (partly) - !-- Multi purpose form for creating stuff -- form-bean name=createForm type=org.apache.struts.validator.DynaValidatorActionForm form-property name=author type=java.lang.String / form-property name=categoryId type=java.lang.Integer / form-property name=threadId type=java.lang.Integer / form-property name=topic type=java.lang.String / form-property name=message type=java.lang.String / form-property name=replyto type=java.lang.Integer / form-property name=categoryName type=java.lang.String / form-property name=categoryDescription type=java.lang.String / /form-bean /form-beans !-- Display new user|category|thread|message form -- actionpath=/NewForm forward=.view.newForm / !-- Process new Category -- actionpath=/CreateCategory type=manegen.forum.CreateCategoryAction name=createForm scope=session input=input forward name=input path=/NewForm.do?action=category / forward name=success path=/Home.do/ /action tiles-defs.xml (partly) --- tiles-definitions !-- main layout -- definition name=.layout.main path=/layout/layout.jsp put name=title value=Manegen Forum/ put name=body value=/ /definition !-- views = extensions to the main layout -- definition name=.view.newForm extends=.layout.main put name=body value=/newForm.jsp / /definition /tiles-definitions This is really bothering me, so any ideas would help. Best
Re: Losing form values after validating
Phew.. after some testing, recompiling and more testing and more recompiling, I have finally found a solution. After posting the last message, I realised that the categoryId form field's value was searched for in a request parameter named category, while the form field's name (property) that got submitted and thus returned after validation was categoryId. Thus, the EL ${param.category} naturally didn't find the categoryId parameter. Changing all occurrences of category to categoryId solved this problem, the categoryId value got re-populated when returning from validation. Yee! But the user-fillable fields topic and message were still empty when returning from validation. I realised that if I put an EL in their value-attributes as well, I'd probably be able to pick those values up from the returning request. So, I changed the tags to Topic: html-el:text property=topic value=${param.topic} size=20 maxlength=40 /br/ Message: html-el:textarea property=message value=${param.message} cols=60 rows=10 /br/ Everything worked out fine! Yee! Then I thought about my login-form in the application, which works about the same way. That form does get re-populated after validation without the value=${param.foo} attributes. In fact, the tags didn't have a value-attribute at all. So the next step was to remove the value-attributes all together from the topic and message tags. I recalled that this of some reason didn't work earlier (I got some sort of exception about not finding a bean or something), so that's why I put those value-attributes there in the first place. Well, everything worked fine without the value-attributes. Yee! But when visiting the form later on, the values I filled in earlier was still there. Why? Ah, the scope=session in the action definition! Replacing session with request did the job. Now everything works as it should! So, the working configuration: - html-el-tags with value-attributes that pick up the request parameters when entering the page - consistent naming of form field names throughout the app (also in form beans, their configurations and business logic beans for safety :) - html-tags without the value-attribute where no data has to be picked up when entering the page - scope=request in the action mapping - input=.tiles.definition.name in the action mapping Thanks Antony for the tiles name tip, which got me going again! :) Regards, Fredrik Fredrik Boström wrote: Thanks for your comment. I tried what you proposed, replacing the action path with the tile definition name. The result was that the tile didn't know which form to display (because the page containes three forms, one of which is selected according to the action request parameter), and thus didn't display anything. So, I thought if I put another hidden field into the form holding the action value... Like this: logic:equal parameter=action value=thread !-- Create new thread -- h1New Thread/h1 html:form action=/CreateThread html-el:hidden property=author value=${user.nickname}/ html-el:hidden property=action value=${param.action}/ html-el:hidden property=categoryId value=${param.category}/ Topic: html:text property=topic value= size=20 maxlength=40 /br/ Message: html:textarea property=message value= cols=60 rows=10 /br/ html:submit value=Create / /html:form /logic:equal I also added the action field to the DynaValidatorActionForm definition in the struts-config.xml. But in the validator configuration files, the field is ignored. The action definition in the struts-config.xml file still has scope=session. The result of this was quite surprising: When submitting invalid information - the validation works fine - the form returns to the correct page with the correct form displayed - the form fields' values are still missing EXCEPT FOR the user and action fields So the missing fields are still: - categoryId - topic - message Like this: !-- Create new thread -- h1New Thread/h1 form name=createForm method=post action=/forum_dev/CreateThread.do input type=hidden name=author value=fredde input type=hidden name=action value=thread input type=hidden name=categoryId value= Topic: input type=text name=topic maxlength=40 size=20 value=br/ Message: textarea name=message cols=60 rows=10/textareabr/ input type=submit value=Create /form As I see it, the action and categoryId fields should be treated the exact same way. But still only action gets re-populated when returning from the validation. Confusing... Ideas? Regards, Fredrik Antony Joseph wrote: Try this. The input point to your tile. !-- Process new Category -- actionpath=/CreateCategory type=manegen.forum.CreateCategoryAction name=createForm scope=session input=input forward name=input path=.view.newForm / forward name=success path=/Home.do/ /action - Original Message - From: Fredrik Boström [EMAIL