Buttonã¨Linkã®onclickã«JavaScriptãåãè¾¼ã
ã¯ããã«
ãä»æ¥ãã¾ãã¾ãWicket JavaScriptãã¾ã§googleã«å
¥åããã¨ãããWicket JavaScript å®è¡ãã¨è£å®ããã¾ããã
ãWicket JavaScript å®è¡ãã¨å
¥åããã¦ããæ¹ã
ãæ£ç¢ºä½ãæ±ãã¦ããã®ããæ£ç¢ºãªæã¯åããã¾ããããButtonã¨Linkã®onclickã«JavaScriptãä»è¾¼ãæ¹æ³ãæ¸ãã¾ãã
ããããç§ã以åæ¢ããã®ã§â¦ã
ç°å¢
- Wicket 1.3.6
Buttonåã¯Linkã®onclickã«JavaScriptãä»è¾¼ãæ¹æ³
以ä¸ã®ã¡ã½ããããªã¼ãã¼ã©ã¤ããã¾ãã
ã¯ã©ã¹ | ãªã¼ãã¼ã©ã¤ãããã¡ã½ãã |
---|---|
Button | getOnClickScript() |
Link | getOnClickScript(final CharSequence) |
ãåçã«çæããå
容ããªããã°ãHTMLå´ã«ç´æ¥æ¸ãã¦ããããã¨æãã¾ã(å®é¨ãã¦ãã¾ããã)ã
ããªããªããButtonã¨Linkã¯ãonComponentTag(ComponentTag)ã§onclickå±æ§ãé常ã¯ä¸æ¸ãããªãããã§ãã
ãåè¿°ããã¡ã½ããããªã¼ãã¼ã©ã¤ãããå ´åã¯ãonclickå±æ§ãä¸æ¸ããã¾ãã
Linkã®å®è£ ä¾
ãButtonã®æ¹ã®å®è£
ä¾ã¯æå¤ãªãã¨ã«ãWicket1.3.6ã®ãµã³ãã«ã«ã¤ãã¦ã¾ããã
ãLinkã®æ¹ã¯å®è£
ä¾ãã¤ãã¦ãã¾ãããµã³ãã«ã®ãã¹ã¯ä»¥ä¸ã®éãã
- apache-wicket-1.3.6\src\jdk-1.5\wicket-examples\src\main\java\org\apache\wicket\examples\ajax\prototype\Index.java
ã該å½é¨åãå¼ç¨ãã¾ãã
add(new Link("link") { /** * Handles a click on the link. This method is accessed normally using a standard http * request, but in this example, we use Ajax to perform the call. */ public void onClick() { // Increment count count++; // The response should refresh the label displaying the counter. getRequestCycle().setRequestTarget(new ComponentRequestTarget(counter)); } /** * Alter the javascript 'onclick' event to emit the Ajax call and update the counter * label. */ protected String getOnClickScript(String url) { return new AppendingStringBuffer("new Ajax.Updater('counter', '").append( urlFor(ILinkListener.INTERFACE)) .append("', {method:'get'}); return false;").toString(); } });
Buttonåã¯Linkã«ã¤ãã¦ãonclick以å¤ã®å ´å
ãonclick以å¤ã®å ´åã¯ãSimpleAttributeModifierã使ã£ã¦å·®ãè¾¼ãããHTMLå´ã«ç´æ¥æ¸ãã¦ãã¾ãã¾ãããã
Buttonã¨Link以å¤ã®onclickã«ã¤ãã¦
ãonComponentTag(final ComponentTag)ã®å®è£
ãè¦ã¦ã¿ã¾ãããã
ããtag.put("onclick", ã);ãã®ç®æãonclickå±æ§ã«å¤ãè¨å®ãã¦ããç®æã§ãã
ãã¨è¨ããã¨ãè¸ã¾ãã¤ã¤ã½ã¼ã¹ãèªãã¨ãå·®ãè¾¼ãæ¹æ³ã®å¯ããã¤ãã¯ãã
ãå ´åã«ãã£ã¦ã¯ãonComponentTag(final ComponentTag)ããªã¼ãã¼ã©ã¤ãããã¨ãããæ³¥èãçãã«ãã©ãçããã¨ããããã¨æãã¾ããâ¦ã
ãã¡ãªã¿ã«ãåç´ã«ãtag.put("onclick", ã);ããå¼ã°ãã¦ããå ´åãHTMLå´ã«æ¸ããJavaScriptã¯ç¡ãã£ããã¨ã«ããã¾ãã
ãè¦æ³¨æã
onloadã使ãããå ´å
ãIHeaderContributorã®JavaDocãèªãã¨æ¹æ³ãæ¸ãã¦ããã¾ãã
ãJavaDocã«æ¸ããã¦ãããµã³ãã«ã以ä¸ã«æç²ãã¾ãã
class MyPanel extends Panel implements IHeaderContributor { public MyPanel(String id) { super(id); } public void renderHead(IHeaderResponse response) { response.renderOnLoadJavascript("alert('page loaded!');"); } }
ãä½è«ã§ãããWicket 1.5ã§ã¯å¾®å¦ã«æ¸ãæ¹ãå¤ãã£ã¦ããã®ã§æ³¨æãã¦ãã ãã
ãWicket 1.5ã®IHeaderContributorã®JavaDocãã¿ãã¨ãWicket 1.5ã®å ´åã®æ¸ãæ¹ãè¼ã£ã¦ãã¾ãã
ãããã«
ãæ¥åã¢ããªã§ãã¨ãJavaScriptå·®ãè¾¼ããã¨ããããã¾ããã®ãã
ãå°ã£ã¦ãã人ã®å©ãã«ãªãã°å¹¸ãã§ãã