Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

get the ActionForm property value into a java variable from JSP

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will Javascript solve this ?
 
s penumudi
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why not set the maxlength attribute on your textfield? That way you do not need to worry about truncating.
 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic