Example 5: Diagnostics
If you can't play the video, make sure that you are logged in at Wex Solutions.
-
What will we do? - Learn how to add a Diagnostics UI to any WEX and how to use it
-
What do you need? - Site access to a non-production Windchill
-
How long will it take - 10 minutes
You can find the code for this example in our Git-Hub repository.
This example sheds some light on how to add a Diagnostics UI to a Windchill Extension. While explaining that, the example also demonstrates some useful concepts when it comes to WEX development:
- A simple UI crafting using CSS and jQuery.
- A JSP backend interaction.
- Use of the
wex-wt-framework
library.
Implementation
The Diagnostics UI is implemented by a JSP file located in wex-example-diags/src/main/wex/jsp/utils/diags.jsp
. This generates a user interface like the one below:
It uses JavaScript to call another JSP in the following way:
<script language="JavaScript">
var doAction = function() {
var result = $("#wex-diags-result");
result.html("Running....");
var oid = $("#wex-diags-oid").val();
$.ajax({
url: "rundiags.jsp",
data: {'oid': oid},
success: function (data) { result.html(data); }
}).fail(function () {
result.html('Failed');
});
}
</script>
The JavaScript above calls a JSP, which in turn calls a WEX's method defined as a feature, passing the request and response:
<%@ page import="com.wincomplm.wex.kernel.api.invoke.WexInvoker"%><%
String result = WexInvoker.invoke(
"com.wincomplm.wex-example-diags","methods.test",request,response);
out.println(result);
%>
The file com\wincomplm\wex\example\diags\methods\ExampleMethods.java
contains the previously invoked method. It uses the inputted OID to find the object and then returns the object's number.
@WexComponent(uid = "methods", description = "Wex Diagnostic Methods")
public class ExampleMethods {
@WexMethod(name = "test", description = "Display configuration")
public String test(HttpServletRequest request, HttpServletResponse response) throws Exception {
String oid = request.getParameter("oid");
WTPart part = (WTPart) WexQueryHelper.getObject(oid);
return "Number: " + part.getNumber();
}//test
}
Execution
The adding of the Diagnostics JSP to a WEX will trigger the apparition of the icon in the Extension Manager.
A click on said icon will make the UI pop up; then, tests can be conducted.