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>
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.
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.
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.