Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Web Application Developer’s Guide phần 7 pptx
Nội dung xem thử
Mô tả chi tiết
Tutorial: Creating a JSP with InternetBeans Express 13-7
Step 8: Adding the InternetBeans control tags
Step 8: Adding the InternetBeans control tags
Now it’s time to add the two control tags for the two text input fields. Add
the tags shown in bold.
<form method="POST">
<p>Enter your name:</p>
<ix:control dataSet="signatures" columnName="Name">
<input type="text" name="Name" size="50">
</ix:control>
<p>Enter your comment:</p>
<ix:control dataSet="signatures" columnName="Comment">
<input type="text" name="Comment" size="100">
</ix:control>
<p>
Note that you are wrapping each of the HTML text input tags in an
InternetBeans control tag. This allows the InternetBeans IxControls to
implicitly understand which text input fields they are replacing.
Step 9: Adding the InternetBeans submit tag
Add the opening and closing submit tags shown in bold.
<input type="text" name="Comment" size="100">
</ix:control>
<p>
<ix:submit methodName="submitPerformed">
<input type="submit" name="submit" value="Submit"></p>
</ix:submit>
</form>
Note that you are wrapping the HTML submit input tag in an
InternetBeans submit tag. This allows the InternetBeans IxSubmitButton to
implicitly understand which submit button it is replacing. We’re not done
with the submit button yet. You still have to add the method which will be
executed when the button is pushed. You’ll do that in the next step.
13-8 Web Application Developer ’ s Guide
Step 10: Adding the submitPerformed() method
Step 10: Adding the submitPerformed() method
Add the code shown in bold.
<ix:submit methodName="submitPerformed">
<%!
public void submitPerformed(PageContext pageContext){
DataSet signatures = (DataSet) pageContext.findAttribute( "signatures" );
signatures.post();
signatures.saveChanges();
}
%>
<input type="submit" name="submit" value="Submit"></p>
</ix:submit>
The submitPerformed() method is contained within a JSP declaration tag.
This method declaration doesn’t have to be nested within the
InternetBeans submit tag, but it is an elegant way of writing the code. The
parameter passed to this method is the PageContext. This is an object
containing information about the page, which exists for every JSP. The
method retrieves a DataExpress DataSet by finding the page attribute
corresponding to the “signatures” dataset. It then posts the user’s input to
the dataset, and saves the changes to the dataset.
Step 11: Adding code to insert a row
There is still one more piece of code you need to add before the JSP will
work properly. When the form is posted, you need to add an empty row
to the dataset to contain the user’s input. Add the code shown in bold.
</ix:table>
<%
signatures.insertRow(false);
%>
<form method="POST">
This last Java code fragment may look a little confusing, because it doesn’t
appear to be enclosed in a method declaration. It actually is. When the JSP
gets compiled this will become part of the service() method in the
generated servlet (which you can’t see, but it’s still there). Any line of code