Author: bleny Date: 2011-11-16 16:07:34 +0100 (Wed, 16 Nov 2011) New Revision: 144 Url: http://nuiton.org/repositories/revision/nuiton-web/144 Log: #1808 Add a nuiton struts taglib. help tag has better support for some type of fields Modified: trunk/nuiton-struts2/src/main/java/org/nuiton/web/struts2/taglib/HelpBean.java trunk/nuiton-struts2/src/main/java/org/nuiton/web/struts2/taglib/HelpTag.java trunk/nuiton-struts2/src/main/resources/META-INF/tld/nuiton-tags.tld trunk/nuiton-struts2/src/main/resources/template/css_xhtml/help.ftl Modified: trunk/nuiton-struts2/src/main/java/org/nuiton/web/struts2/taglib/HelpBean.java =================================================================== --- trunk/nuiton-struts2/src/main/java/org/nuiton/web/struts2/taglib/HelpBean.java 2011-11-14 15:29:07 UTC (rev 143) +++ trunk/nuiton-struts2/src/main/java/org/nuiton/web/struts2/taglib/HelpBean.java 2011-11-16 15:07:34 UTC (rev 144) @@ -11,7 +11,7 @@ @StrutsTag( name="help", tldTagClass="org.nuiton.web.struts2.taglib.HelpTag", - description="TODO", + description="display an help message for the fields inside this tag", allowDynamicAttributes=false) public class HelpBean extends ClosingUIBean { @@ -19,12 +19,16 @@ protected static final String TEMPLATE_CLOSE = "help-close"; + protected static final String DEFAULT_HELP_ZONE = "helpZone"; + + protected String helpKey; + + protected String helpZone; + public HelpBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { super(stack, req, res); } - protected String helpKey; - @Override public String getDefaultOpenTemplate() { return TEMPLATE; @@ -37,14 +41,17 @@ @Override protected void evaluateExtraParams() { - if (helpKey != null) { - addParameter("helpKey", helpKey); - } - + addParameter("helpKey", helpKey); + addParameter("helpZone", helpZone == null ? DEFAULT_HELP_ZONE : helpZone); } - @StrutsTagAttribute(description="TODO" ,required = true) + @StrutsTagAttribute(description="the key used to get the help message body", required = true) public void setHelpKey(String helpKey) { this.helpKey = helpKey; } + + @StrutsTagAttribute(description="the id of the element where the help message will be pushed") + public void setHelpZone(String helpZone) { + this.helpZone = helpZone; + } } Modified: trunk/nuiton-struts2/src/main/java/org/nuiton/web/struts2/taglib/HelpTag.java =================================================================== --- trunk/nuiton-struts2/src/main/java/org/nuiton/web/struts2/taglib/HelpTag.java 2011-11-14 15:29:07 UTC (rev 143) +++ trunk/nuiton-struts2/src/main/java/org/nuiton/web/struts2/taglib/HelpTag.java 2011-11-16 15:07:34 UTC (rev 144) @@ -15,6 +15,8 @@ protected String helpKey; + protected String helpZone; + public HelpBean getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) { return new HelpBean(stack, req, res); } @@ -23,9 +25,14 @@ this.helpKey = helpKey; } + public void setHelpZone(String helpZone) { + this.helpZone = helpZone; + } + @Override protected void populateParams() { HelpBean helpBean = (HelpBean) component; helpBean.setHelpKey(helpKey); + helpBean.setHelpZone(helpZone); } } Modified: trunk/nuiton-struts2/src/main/resources/META-INF/tld/nuiton-tags.tld =================================================================== --- trunk/nuiton-struts2/src/main/resources/META-INF/tld/nuiton-tags.tld 2011-11-14 15:29:07 UTC (rev 143) +++ trunk/nuiton-struts2/src/main/resources/META-INF/tld/nuiton-tags.tld 2011-11-16 15:07:34 UTC (rev 144) @@ -15,11 +15,17 @@ <tag-class>org.nuiton.web.struts2.taglib.HelpTag</tag-class> <body-content>JSP</body-content> <attribute> - <description><![CDATA[Date or DateTime format pattern]]></description> + <description><![CDATA[the key used to get the help message body]]></description> <name>helpKey</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> + <attribute> + <description><![CDATA[the id of the element where the help message will be pushed]]></description> + <name>helpZone</name> + <required>false</required> + <rtexprvalue>true</rtexprvalue> + </attribute> <dynamic-attributes>false</dynamic-attributes> </tag> </taglib> Modified: trunk/nuiton-struts2/src/main/resources/template/css_xhtml/help.ftl =================================================================== --- trunk/nuiton-struts2/src/main/resources/template/css_xhtml/help.ftl 2011-11-14 15:29:07 UTC (rev 143) +++ trunk/nuiton-struts2/src/main/resources/template/css_xhtml/help.ftl 2011-11-16 15:07:34 UTC (rev 144) @@ -1,13 +1,40 @@ <div id="idHelpKey${parameters.helpKey}"> <script type="text/javascript"> $(document).ready( function() { - function printHelp() { - alert('aide pour le champs'); + var helpZone = $('#${parameters.helpZone}'); + var initialHtml; + function showHelp() { + initialHtml = helpZone.html(); + helpZone.html(getHelpAsHtml("${parameters.helpKey}")); } + function hideHelp() { + helpZone.html(initialHtml); + } + + /* select, text, text areas and password fields */ $('#idHelpKey${parameters.helpKey} input').focus( function() { - printHelp(); + showHelp(); } ); + $('#idHelpKey${parameters.helpKey} input').blur( + function() { + hideHelp(); + } + ); + + /* radio buttons, check-boxes */ + var fieldsNeedingHelpWhenMouseOver = + $('#idHelpKey${parameters.helpKey} input[type=radio], #idHelpKey${parameters.helpKey} input[type=checkbox], #idHelpKey${parameters.helpKey} input[type=submit], #idHelpKey${parameters.helpKey} label'); + fieldsNeedingHelpWhenMouseOver.mouseover( + function() { + showHelp(); + } + ); + fieldsNeedingHelpWhenMouseOver.mouseout( + function() { + hideHelp(); + } + ); }); </script> \ No newline at end of file