java - struts2 s:property tag: Better way to replace value? -


I have a POJO whose properties I am displaying on JSP using strips2 properties tags:

  public class message {string messageText; Type string message; // Gates and Sets, here} text:  Type: & lt; S: Property value = "messageBean.messageType" />   

The object is created by either user input, or is reading from the database. The "Message Type" attribute contains only the integer value in it, which is used as the key for a lookup table in the database.

When you select the "Type" value, users are given a radio choice at the last page, and each option corresponds to an integer when I am displaying values, I currently only provide an integer Showing I would like to show the text which matches the integer, and I will complete it by creating a key / value lookup method in the action class, and displaying the code as Action class Public Stung Let Translated Type (in): ". If (messageBean.getMessageType (.) Equals ("17")) "Messages for the first time callers" return. // etc} Text: & lt; S: Property Value = "Message Bean. Message Text" / & gt; Type: & lt; S: property value = "translated type" />

Is there a better way to do this?

It does not seem to work:

  Type:   

Is there a syntax to call a stable utility from within the asset tag?

I'm not sure what you are trying to achieve. Why would you prefer to use static calls instead of accessing data from ValueStack (where action properties are used)? If possible, best to avoid a steady call and paste from Standardized / Action Framework and Access Data to the desired design.

If you want to separate logic from your action, then you can change your method:

  public string getTranslatedType () {return utility.Get Translated Text ( GetMessageBean). GetMessageType ()); }   

Or do you want to appear dynamically on the translated text page? If so, then you can use Javascript and Jason to achieve your goal with the following steps on the following steps:

  1. Type your message in integers ( Key) and in a map with the lines of your translated text strings (as values) messageTypeText.put (12, "Messages that are constantly calling.");

  2. Using something like (New JSONObject (messageTypeText)). ToString ();

  3. Then expose the client to such a variety of ways as var messageTypeText = & lt; S: property value = "messageTypeText" />

  4. Type a message to bind a JavaScript method to the radio button which then displays the JavaScript map / value by using the currently selected radio / message type value. Translation of text by accessing it from the array can give me more information on this approach, but I do not want to waste my time if you are not looking for it! :)

Comments