jQuery in Action, 2nd edition*
The moose likes Struts and the fly likes get the ActionForm property value into a java variable from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "get the ActionForm property value into a java variable from JSP" Watch "get the ActionForm property value into a java variable from JSP" New topic
Author

get the ActionForm property value into a java variable from JSP

s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
Hello all,

I have a requirement where I have to show a form either in update mode or add mode.
Hence I am making use of ActionForm so that in add mode, form values will be null and empty text boxes will be shown to the user.
in update mode, I am setting the values to the Actionform so that these can be shown in the text fields for update.

In my UI there are couple of fields that are readonly, The text to be shown can be of any length. So, I have to truncate the text to specific number of characters and show complete text in the tooltip.

Now my problem is, how will I be able to get the form field value into a java variable in my JSP so as to truncate the value.

I have tried usign <bean:struts> which is used to get the struts internal values, But it did not work.
I also got exceptions when I used <bean efine>

Can anyone please help me in solving my problem

Thank you
Thilothama Green
Greenhorn

Joined: May 13, 2004
Posts: 14
Will Javascript solve this ?
s penumudi
Ranch Hand

Joined: Nov 17, 2004
Posts: 113
Yes, Javascript can solve this problem.

But I have Java methods that are used to truncate the messages and I cannot pass the javascript variable to the java method.

Ofcourse I can write a java script function to truncate but we wanted to use java method to do this.

Thank you
[ December 28, 2004: Message edited by: s penumudi ]
J P Nelson
Greenhorn

Joined: Dec 16, 2004
Posts: 12
Have you tried to populate the form with a setup Action class? Using this, the action would go from the action setup class to pre-poulate and display the form, then the submit button would go to the handler action class.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Why not set the maxlength attribute on your textfield? That way you do not need to worry about truncating.


A good workman is known by his tools.
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
Why not set the maxlength attribute on your textfield? That way you do not need to worry about truncating.


I'm not sure you could do that while keeping it read-only. Does <html:hidden have a size attribute? if so this could work.

I would think truncating the length before sending it to the jsp would be the easiest way, but then you would need to send another untruncated copy to be used in the tooltip (and to be the value that is actually saved). That means adding another property to the formbean.

-Tad
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Don't do the truncating in your JSP. Have an additional fields in your ActionForm for the truncated values. Have an additional class, FormAssembler, which populates your ActionForm from your model (and vice versa if necessary). Give this class a method such as populate(ActionForm, Model). Inside the populalte() method of FormAssembler, move the appropriate data from your model to the ActionForm. Now, you can either do the truncation in the FormAssembler and just set the truncated value to the form directly (my preference), or have your ActionForm contain the logic to perform the truncation in the appropriate accessor. The correct data will now be available to your JSP through the ActionForm without any messy logic being done in the JSP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get the ActionForm property value into a java variable from JSP
 
Similar Threads
Struts HTML Lib w/Ajax - Can't get textbox value to Action class
Struts: form with multiple text fields with same name.
c:set equivalent in struts tag ?
Action form is not populated while using html:form enctype="multipart/form-data"
html:text as an array