You can let the user select a file by using the file chooser. Once the file has been selected, the user clicks the Result button. The user is then shown the relative path of the selected file.
- Create a model.
If you did not select Main_and_Page, do the following:
- Add a Page builder call to the model, and call it page1.
This page is the first page of the model. Don't worry about adding content right now.
- Add an Action List builder call to the model.
- Type "main" for the Name input.
- Make page 1 the first action in the Actions list.
This action loads the page.
- In page1, create two span tags.
One is for the file chooser and the other is for the Results button, as shown in the following example.
<html><body><form>
<b>An Example of Using the File Chooser Builder</b>
<p>Select a file in the file chooser. Then, click the Results button. The relative path to the file is displayed.</p>
<hr>
<span name="chooser" />
<br><br>
<span name="resultsbutton" />
</form></body></html>
- If chooser is the span name assigned to the File Chooser builder, and results is the span name assigned to the button builder, do the following:
- Add another Page builder call to the model. Call this builder call "results".
This builder is used to display the results page.
- In the "results" page, add two span tags: one for displaying the results in a text area and another for the Back button, as shown in the following example.
<html><body><form>
<b>An Example of Using the File Chooser Builder (Page 2)</b>
<p>The following is the relative path of the file you selected.</p>
<hr>
<span name="chooser_results" />
<br><br>
<span name="backbutton" />
</form></body></html>
- Otherwise, if chooser is the span name assigned to the Text Area builder, which displays the results, and backbutton is the span name assigned to the Button builder, add a Variable builder call to the model, and do the following:
- Name the builder "selectedValue".
- Assign the builder type String.
- In the Initial Value field, enter the following path: factory/samples
Note: This variable is used to hold the value of the selected path for the file chooser.
- Click OK.
- Add a File Choose builder call to the model, and add the following information:
- For the page location, select page1 from the Page drop-down menu and the first span name listed in the Tag menu. For example, chooser.
The file chooser appears in the location of the span tag.
- In the Starting Directory, leave the default as WEB-INF/models.
- From the Filter Class drop-down menu, select com.bowstreet.builders.webapp.methods.FileChooserMethods$FilterDirectories.
- In the Selected Value field, enter an indirect reference to the builder call name of the Variable builder you added to the model in Step 5. For example: ${Variables/selectedValue}
where selectedValue is the builder call name of the Variable builder added in step 3 or 4.
- Select the option Visible Root Node.
- From the Selection Rule drop-down menu, select All nodes can be selected.
- Click OK.
- Add a Button builder call to the model.
This button is the Results button. Do the following:
- From the Page drop-down menu, select page1.
- From the Tag drop-down menu, select the span tag you created for the Results button. For example, resultsbutton.
- In the Label field, enter Results.
- In the Action Type field, select the following option: Submit form and invoke action
- In the Action field, type the name of the second page.
When the Results button is clicked, the user sees the page specified in the Action field.
- Click OK.
- Add another Button builder call to the model.
This button is the Back button on the second page. Do the following:
- From the Page drop-down menu, select the second page. For example, results.
- From the Tag drop-down menu, select the span tag you created for the Back button. For example, backbutton.
- In the Label field, enter Back.
- In the Action Type field, select the following option: Submit form and invoke action
- In the Action field, type the name of the first page. For example, page1.
When the Back button is clicked, the user sees the page specified in the Action field.
- Click OK.
- Add a Text Area Builder call to the model.
The results appear in this text area. Do the following:
- From the Page drop-down menu, select the second page. For example, results.
- From the Tag drop-down menu, select the span tag you created to display the results in a text area. For example, chooser_results.
- In the Default Text field, enter an indirect reference to the variable created at run-time. For example:${Inputs/chooser}, where chooser is the span name assigned to the File Chooser builder.
Note: If you are picking this indirection from the reference chooser, expand the Inputs node and then expand the page1 node to select ${inputs/chooser}.
- Click OK.
- Run the model.
- Make a selection in the file chooser, then click Results.
The Results page displays the path of the item you selected.