Monday, August 05, 2013

Get Absolute Url in Tapestry4 and Tapestry5

In Tapestry 4 for getting the absolute Url we use
IRequestCycle obCycle = (IRequestCycle)event.getRequestCycle();
obCycle.getAbsoluteURL("/app?page=Login&service=page");
In Tapestry5 we can use the below code to get the absolute url.
@Inject
PageRenderLinkSource linkSource;

Link link = linkSource.createPageRenderLinkWithContext(
                "DepartmentMasterPG",
                5);
String s = link.toAbsoluteURI();

Thursday, August 01, 2013

ValidationDelegate in Tapestry4 is recordError in Tapestry5

In Tapestry4 we are using

ValidationDelegate delegate = (ValidationDelegate)getBeans().getBean("delegate");

to validate and show the error. In Tapestry5 it is obsolete. In Tapestry5 we need to create as shown below

Page

 

<form t:type="form" t:id="departmentMasterList">
<t:errors />

@Component
private Form departmentMasterList;

Java
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
void onValidateFromDepartmentMasterList() {
 Iterator<DepartmentMasterListVO> iter = deptMasterList.iterator();
 while (iter.hasNext()) {
  DepartmentMasterListVO departmentListVO = iter.next();
  if (!departmentListVO.getCategory().equals("Test")) {
   departmentMasterList.recordError("Category entered is wrong");
   break;
  }
 }
}

In Method onValidateFromDepartmentMasterList DepartmentMasterList is the form Name given in Page.

In the above example I am iterating through a list and checking whether category contains a specific value. This is just for testing only. So now when you press the button, it will go to the above method (OnValidateFrom) if the validation fails, it will display the given message in the location where we have given <t:errors />. If there is any error, the program will not call the OnSuccess

Get Session id and IP Address in Tapestry5

We are going to see on how to get the Session ID and IP Address,

 Please add the below code in the class

@Inject
private HttpServletRequest httpServletRequest;

To get the IP Address

httpServletRequest.getRemoteAddr()

To get the session id

httpServletRequest.getSession().getId()