Defining the Rule's UI

The Java code you’ve added to this point has assumed that a preset weather value is available for comparing during the evaluation process. To let administrators set that value, you must define a UI so your rule can be configured during the view/save lifecycle. Create a view.jsp file in your rule’s module (e.g., /src/main/resources/META-INF/resources/view.jsp) and add the following logic:

<%
Map<String, Object> context = (Map<String, Object>)request.getAttribute("context");

String weather = (String)context.get("weather");
%>

<aui:fieldset>
    <aui:select name="weather" value="<%= weather %>">
        <aui:option label="sunny" value="sunny" />
        <aui:option label="clouds" value="clouds" />
        <aui:option label="snow" value="snow" />
        <aui:option label="rain" value="rain" />
    </aui:select>
</aui:fieldset>

The weather variable in the context map should be set for the weather rule. When the user selects an option, it’s passed from the view template to the populateContext method.

Figure 1: The weather rule uses a select drop-down box to set the weather value.

Figure 1: The weather rule uses a `select` drop-down box to set the weather value.

You’ve created the weather rule and can now target users based on their weather conditions. You can view the finished version of the weather rule by downloading its ZIP file.

Now you’ve created and examined a fully functional rule and have the knowledge to create your own.

« Evaluating a RuleTracking User Actions with Audience Targeting »
¿Fue útil este artículo?
Usuarios a los que les pareció útil: 0 de 0