Hi Paul !!
                I have placed the code given by you in my application code
and it works fine but only when the javascript is with the html. I tried to
put it in a .scipt file but then it is not working.....

        Could you please help !!!

Thanks & Regards
-----------------------------
Ananya Goswami
Software Developer



-----Original Message-----
From: seloha . [mailto:[EMAIL PROTECTED] 
Sent: 14 October 2005 18:32
To: [email protected]
Subject: RE: passing parameters in DirectLink

Assuming you are using Tapestry 4.0 a component called XTiles is in the 
contrib library if you are working on Tapestry 3 you will need to get the 
library from http://www.t-deli.com/ and install it in your .application 
file.

To use Xtiles you need to write two javascript functions one to send the 
information to your java method that does the checking and another to 
receive the response from the java function.

First you need something like the following line in your .html file to use 
XTiles (assuming using Tapestry 4.0 hence @contrib:XTile):

  <span jwcid="@contrib:XTile" 
listener="ognl:listeners.checkUniqueUserDirectCall"
                             sendName="checkUniqueUserDirect"
                             receiveName="checkUniqueUserRecv"/>

the listener is the name of the java method (listener) to be called the 
sendName is the name of the javascript function to call the java listener 
and the receiveName is the name of the javascript function to receive the 
information from the java listener after it has completed.

Instead of your @DirectLink you could have an anchor calling the javascript 
sendName function like this:

<a href="#" onclick="checkUniqueUser()"><font color="white" size="4" 
 ><u>Check uniqueness</u></font></a>

add to your username input a unique id so that you can refer to it in the 
javascript:

<input type="text" jwcid="username" size="30" id="usernameId"/>

Then place your javascript in a separate file with a name like 
Username.script with the following:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script PUBLIC
        "-//Apache Software Foundation//Tapestry Script Specification
3.0//EN"
        "http://jakarta.apache.org/tapestry/dtd/Script_3_0.dtd";>

<script>

<!-- functions relating to a list of jobs e.g. select row and edit selected 
row -->

<body>

<![CDATA[

// function called by anchor to send to java listener
function checkUniqueUser() {
  username = document.getElementById("usernameId").value;
  if (username == "") {
    alert("You must enter a username");
    return;
  }
  // this is the function specified to send to the server in XTile component
  checkUniqueUserDirect(username);
}

// username unique checked
// received information from java listener from AJAX callback
function checkUniqueUserRecv(arr) {
  if (arr[0] == "SUCCESS") {
    alert("username is unique");
  }
  else {
    alert(arr[0]);
  }
}


]]>


</body>

<initialization>
</initialization>

</script>


The above script file will need to be referenced in your .html file, 
something like, if you had placed in /WEB-INF/scripts directory:

<span jwcid="@Script" script="/WEB-INF/scripts/Username.script"/>


your java file will need a method (listener) something like this:

public void checkUniqueUserDirectCall(IRequestCycle cycle) {
        // XTile property return String
        String[] ret = new String[1];
        ret[0] = "SUCCESS";
        Object[] params = cycle.getListenerParameters();
        String username = (String)params[0];
        // follow this with check to see if username is unique
        // and set the ret[0] with the appropriate message if not
        // this message will be displayed by the javascript alert() function

above
        cycle.setListenerParameters(ret);
        // this final command sends the returned parameters to the 
javascript receiving function
        // you can make the number of parameters passed between the 
functionas as long as you like
}

Hopefully this should give you the jist there may well be a number of 
mistakes in my code since it has been written straight into this email and 
not run or checked.

Paul


Ananya Goswami <[EMAIL PROTECTED]> wrote:

Thanks a lot for replying again!!!
        I went through the tutorial on AJAX and also found some code related
to it. But I don't know how to use it through tapestry .... like where and
how to place the servlet code .
        Please help !!!!




Thanks & Regards
-----------------------------
Ananya Goswami
Software Developer




-----Original Message-----
From: seloha . [mailto:[EMAIL PROTECTED]
Sent: 12 October 2005 19:05
To: [email protected]
Subject: RE: passing parameters in DirectLink

The mechanism you are suggesting is going to involve a page refresh in order

to reach the server so why not submit the form and do your validation in the

form listener.

The only way you could do this validation on the serverside without a page
refresh, which is I guess what you are hoping for, is to use AJAX along with

some javascript to obtain the username the use has entered.

I cannot see any advantage in using the @DirectLink to do this (but then
again that could just be my opinion). As outlined in my first response you
problem with the @DirectLink parameter is the time when it obtains its
parameter and at that point the username has not been entered.

Paul


Ananya Goswami <[EMAIL PROTECTED]> wrote:

Thanks a lot for replying!!
                But I think you understood my problem partially. I already
have a listener to check username on submit of the form( which is
server-side validation).But I want to send the username value in the
directlink (which has a listener method ) before submitting the form.


Thanks & Regards
-----------------------------
Ananya Goswami
Software Developer



-----Original Message-----
From: seloha . [mailto:[EMAIL PROTECTED]
Sent: 12 October 2005 18:30
To: [email protected]
Subject: RE: passing parameters in DirectLink

I think what you want is a @TextField component inside a @Form with a submit

button. So your .html file would look something like this:

<form jwcid="[EMAIL PROTECTED]" listener="listener:checkUniqueUser">
  <input type="text" jwcid="@TextField" value="ognl:username" size="30"/>
  <br/>
  <input type="submit" value="Login"/>
</form>

your .java page would look something like:

public abstract String getUserName();

public void checkUniqueUser(IRequestCycle cycle,String username) {
                String name = getUserName();
                System.out.println("Username="+username);
            return;
         }
         return;
    }

The problem with your code is that the time at which the @DirectLink
parameters are obtained, which is when the server renders the page to
display it. At this point the parmeter username is null.

For further info see the @TextField component documentation.

Hope this helps,

Paul


Ananya Goswami <[EMAIL PROTECTED]> wrote:

Hi All!
        Kindly help me if anybody can..
        I have a .html file where I have a username text field. I have a
link near that to check the uniqueness of the username.
        I have done something like this but am facing a problem in passing
the parameter "username" in the DirectLink.

        .html

<td><input type="text" jwcid="username" size="30"/></td>
<td><a href="#" jwcid="@DirectLink" listener="listener:checkUniqueUser"
parameters="ognl:username"><font color="white" size="4" ><u>Check uniqueness
</u></font></a></td>

         In .java I have a listener method ChequeUniqueUser. I am trying to
print the username to see if I am getting it or not... but am not getting
it!!

public void checkUniqueUser(IRequestCycle cycle,String username) {
                String name = username;
                System.out.println("Username="+username);
            return;
         }
         return;
    }









Thanks & Regards
-----------------------------
Ananya Goswami
Software Developer


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to