-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3946730
By: cpwrsilver
I have a functional application using JSPs with struts that I'm trying to migrate to ZK. As a sample I have a form with 3 fields that are displayed, and the user can update them.
I can get the current values using requestScope, but I'm having problems with the submit to update the data.
I can't find anything in the documentation on suggestions for this - I really don't want to modify the struts actions, but I'm thinking I have to add an "submitForm" method, although I'm not sure what to put in it.
Any suggestions appreciated!
My sample form is:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ZUML -->
<h:form id="updateForm" action="/MyCustomerDetailPage.do" method="post"
xmlns:h="http://www.w3.org/1999/xhtml">
<grid>
<rows>
<row>Id<textbox name="id"
value="${requestScope.myCustomerCustomerForm.id}"/></row>
<row>Company Name<textbox name="companyName"
value="${requestScope.myCustomerCustomerForm.companyName}"/></row>
<row>Registration Date<datebox name="registrationDate"
value="${requestScope.myCustomerCustomerForm.registrationDate}"/></row>
<row>
<button label="Update" onClick="update()"/>
</row>
</rows>
</grid>
<zscript><![CDATA[
void update() {
//validate data
// id.getValue();
// companyName.getValue();
// registrationDate.getValue();
//title.getValue();
//submit the form - HOW???
Customer.submitForm(updateForm);
}
]]></zscript>
</h:form>
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3947708
By: henrichen
Clients.submitForm(updateForm);
This method would pass a command to Browser's zk javascript engine and the engine will do a "submit form" for you.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3949066
By: cpwrsilver
Does this mean I have to write my own submitForm routine in a struts action class? Can't I somehow invoke the HTML submit action to emulate the processing from when this was a JSP?
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3950970
By: cpwrsilver
Ok, let me ask this in a different way.
My current JSP defines the form and html items as follows:
<html:form style="display:inline" action="/MyCustomerDetailPage.do" method="post"
styleId="myCustomerCustomerForm">
<html:text name="myCustomerCustomerForm" property="phoneNumber" size="40"/>
<html:submit property="altura.action.store" onclick="return onSubmit(this);"></html:submit>
</html:form>
with the onSubmit being simple:
function submitForm ( a_elt )
{
var form = getParentElement ( a_elt,"form" );
if (form!=null)
{
form.submit();
}
}
To implement ZK with as little changes to the application as possible, I'm replacing the JSP with an include to a .zul file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ZUML -->
<window xmlns:h="http://www.w3.org/1999/xhtml">
<h:form id="updateForm" action="/MyCustomerDetailPage.do" method="post"
styleId="myCustomerCustomerForm" >
<grid>
<rows>
<row>Id<textbox name="id"
value="${requestScope.myCustomerCustomerForm.id}"/></row>
<row>Company Name<textbox name="companyName"
value="${requestScope.myCustomerCustomerForm.companyName}"/></row>
<row>Registration Date<datebox name="registrationDate"
value="${requestScope.myCustomerCustomerForm.registrationDate}"/></row>
<row>
<h:input type="submit" value="Submit"/> </row>
</rows>
</grid>
</h:form>
</window>
When doing this, the submit (from ZK) shows the error:
The requested resource (/MyCustomerDetailPage.do) is not available.
So the question (finally!) is what am I doing wrong? I have the fields named the same, I'm following the instructions in the developer guide (page 125, version 2.1.2).
Thanks for any help!
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3951337
By: henrichen
I missunderstood your question until I see this example.
You are doing with a two-servlets approach. One is your original servlet that will process the *.do files. Anothor one is the ZK servlet, that will handle the .zul page and zk components. See this smalltalk for detail explaination:
http://www.zkoss.org/smalltalks/legacy-form/legacy-form.html
When you press submit, the form is submitted as any regular html form. So the browser would send a http request to the *.do file with name-value request pairs.
So it is now your original *.do servlet should pick up the duty and do its job.
The error complains that it cannot find the page /MyCustomeerDetailPage.do meaning that probably your original servlet is not there?
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3956724
By: cpwrsilver
To test your question, I put the HTML submit back into the HTML prior to doing the include. The result was that the HTML submit properly worked (saving the changes made to the ZK fields), but the ZK submit took no action and displayed a blank page. This tells me that the servlet is in fact still there, or for some reason it goes away when the include to the .zul file is done.
The two files for this are:
<%@ page contentType="text/html; charset=utf-8"%> <%@ page pageEncoding="utf-8" %> <%@ taglib uri="/struts-html.tld" prefix="html" %> <%@ taglib uri="/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/struts-tiles.tld" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<html:form style="display:inline" action="/MyCustomerDetailPage.do" method="post"
styleId="myCustomerCustomerForm">
<html:hidden name="myCustomerCustomerForm" property="inCreateMode"/>
<div class="webpanel" style="width:100%;">
<html:submit property="altura.action.store" styleId="ButtonStore_store"
styleClass="webbutton" >HTML Submit</html:submit>
</div>
<div class="webpanel" style="width:100%;">
<tiles:insert page="zultest.zul" flush="true">
</tiles:insert>
</div>
</html:form>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!-- ZUML -->
<window xmlns:h="http://www.w3.org/1999/xhtml">
<h:form id="updateForm" action="/MyCustomerDetailPage.do" method="post"
styleId="myCustomerCustomerForm" >
<grid>
<rows>
<row>Id<textbox name="id"
value="${requestScope.myCustomerCustomerForm.id}"/></row>
<row>Company Name<textbox name="companyName"
value="${requestScope.myCustomerCustomerForm.companyName}"/></row>
<row>Registration Date<datebox name="registrationDate"
value="${requestScope.myCustomerCustomerForm.registrationDate}"/></row>
<row>
<h:input type="submit" value="Submit"/>
</row>
</rows>
</grid>
</h:form>
</window>
Any other suggestions or ideas to look at ??
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3956897
By: henrichen
I am a little bit confused. Are you including a form into another form?
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3956924
By: cpwrsilver
I'm not trying to, but as a test to see if the servlet is still around I did exactly that so I could have the submit button in the JSP.
When I don't have a form in the HTML page, the submit action in the zul file gets the 'The requested resource (/MyCustomerDetailPage.do) is not available.'
error (leading to your question about the servlet being around).
What I'd like to do is, in this preference order:
1. Include ZK components in my HTML form (can't since many of my JSPs are not well-formed and they can't all be changed).
2. Have a JSP simply do an include to a .zul file, with the submit button in the .zul file (no form on the JSP)
From the files I posted above, can you suggest how to accomplish this?
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3956957
By: henrichen
Can you help me to clarify something?
1. With the form tag in JSP(the one that will submit OK) and see the browser source code, how is that action="..." is encoded?
2. With the form tag in .zul, and see the browser source code, how is the action="..." is encoded?
/henri
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3956998
By: cpwrsilver
Henri, your idea was right but in the wrong tag. After comparing the generated source code I found that the submit action was slightly different.
I needed to make the submit have a specific id and name in addition to the value and type. Not sure why, but it is working now.
I had:
<input value="Store" type="submit" />
this works:
<input id="ButtonStore_store" value="Store" type="submit"
name="altura.action.store"/>
Thanks for your help.
Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3957029
By: henrichen
Interesting. I guess some javascript handles the onsubmit event in between.
Asked: 2006-10-04 17:52:12 +0800
Seen: 348 times
Last updated: Oct 11 '06