rawkfist0215
rawkfist0215

Reputation: 1485

Struts2 - Setting a property from a static list String property using OGNL not working

I'm trying to set a hidden input value using the struts2 framework. The input value is an unchanging value, so I'd like to set it via a static reference rather than worrying about setting it possibly in multiple places in the Controller.

Here is the list definition:

     package com.packagename.models;
     public class UsernameModel implements Serializable, Comparable<UsernameModel> {

          ...
          /**
          * <P>A static container of the predefined username types.
          */
          public static final class UsernameTypes {
           public static final String ALIAS = "Alias";
           public static final String ASSIGN_NUM = "Assignment Number";
          }
          ...
      }

I realize that this may be out of the scope of the question, but when I try to reference the property inside the hidden input like so it throws an exception:

<s:hidden name="username_type" value="<s:property value="@com.packagename.models.UsernameModel.UsernameTypes@ALIAS" />"></s:hidden>

org.apache.jasper.JasperException: /WEB-INF/content/user/profile.jsp (line: 185, column: 64) Unterminated <s:hidden tag

If I remove the property tag from the s:hidden input the exception goes away but no text appears where the "Alias" string should be.

-- Thanks in advance

Upvotes: 3

Views: 1159

Answers (1)

Aleksandr M
Aleksandr M

Reputation: 24406

You cannot nest tags like that. And to reference inner class you need to use $ sign.

<s:hidden name="username_type"
          value="%{@com.packagename.models.UsernameModel$UsernameTypes@ALIAS}" />

IMO it is better to use that kind of static variables directly in class rather than send them from JSP.

Upvotes: 3

Related Questions