You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Newton <ne...@pingsite.com> on 2006/02/07 17:33:10 UTC

Custom tags in JSP files & Struts forms

This should probably be marked OT, but I'm not sure yet.

I have a custom tag for JSP form fields (consist of a <tr> with two
<td>, one for the prompt and one for the input field). The tag will
inject error messages and do some other stuff depending on whether or
not there's errors etc.

In order to make it easier to change the markup I was going to convert
this to a new-school JSP tagfile. I'm beginning to wonder if that's a
good idea.

I do the following to get the form field prompt:

<c:set var="beanName">
  <%= ((org.apache.struts.taglib.html.FormTag) getParent()).getBeanName() %>
</c:set>

<c:set var="fieldPrompt">
  <bean:message key="${beanName}.${property}.prompt"/>
</c:set>

I don't like this part so much, mostly because of the bean name stuff
that I use to dig into the application resources... Is this the only
place the form bean name is available by default? Would it be "prettier"
to put the bean name (or better yet, an application resource prefix)
into scope via the action class or something? Or wire actions up via
Spring to keep it in a standard config place? Pah!

Now the rest of the tag file looks more or less like this, with some
presentation stuff taken out to protect the... innocent.

  <td valign="top">
    <div class="formprompt">
      ${fieldPrompt}
    </div>
  </td>
 
  <td valign="top">
    <jsp:doBody />
    <logic:messagesPresent property="${property}">
      <br/>
      <span class="formerror">
        <html:messages id="msg" message="false" property="${property}">
          <bean:write name="msg"/>
          <br/>
        </html:messages>
      </span>
    </logic:messagesPresent>
  </td>

Aside from a poorly-thought-out stylesheet, does this seem like a
reasonable conversion to make, or am I fooling myself?

Thanks,
Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org